@katherineheadshall/cookies
v1.0.6
Published
Skip the hard managment of cookies in the front-end, the best and most customizable cookies management lib for front-end in the world!
Readme
Cookies
Skip the hard steps to manage the cookie in the front-end, use the standard from W3C.
Legacy release, reach github for release notes.
Install
$ npm install --save @katherineheadshall/cookiesUsage
setObject
import { setObject } from '@katherineheadshall/cookies';
let user = setObject('user', {id: 1, username: 'example user'});
console.log(user); // returns the parsed stored cookie in cookie formatExample
getObject
import { getObject } from '@katherineheadshall/cookies';
// can also be imported as comonjs module:
// const cookies = require('@katherineheadshall/simple-storage');
// Getting an already stored user object
getObject('user').then(user => {
console.log(user);
// => {object}
});API
// you can provide an default value if the cookie cannot be found, this also works for getObject
storage.get('cookieName', null)cookieName : string
| cookies-available-methods | Output |
|---------------------------------------------|---------------|
| get | string or defaultValue |
| set | string |
| setObject | any |
| getObject | string or defaultValue |
| remove | string |
Remove an already created Cookie
// commonjs
cookies.remove('cookieName')// es6
remove('cookieName')