@katherineheadshall/cookies
v1.0.3
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!
Downloads
19
Readme
Cookies
Install
$ npm install --save @katherineheadshall/cookies
Usage
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 format
Example
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')