I'm currently working on a library that needs to have basic management for cookies (get and set). I could use js-cookie, but I try to avoid dependencies.
I was wondering what was the best approach to deal with this. Here are the different implementations I have thought of, but I'm not sure which one is more relevant, or maybe there is a better way to do it.
1. With two separate functions
export function getCookie() {
// code
};
export function setCookie() {
// code
};
2. With a function and 2 methods
export function Cookie {
this.get = function () {
// code
};
this.set = function () {
// code
};
}
3. With a class and 2 methods
A. Classic way
export class Cookie {
get() {
// code
};
set() {
// code
};
}
B. Export the instance
class Cookie {
get() {
// code
};
set() {
// code
};
}
export new Cookie();
C. With static methods
export class Cookie {
static get() {
// code
};
static set() {
// code
};
}
Having your opinion will be really appreciated.