@katherineheadshall/cookies

1.0.3 • Public • Published

Cookies




Skip the hard steps to manage the cookie in the front-end, use the standard from W3C.

This is an image

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')

License

MIT

Package Sidebar

Install

npm i @katherineheadshall/cookies

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

14 kB

Total Files

10

Last publish

Collaborators

  • logiky
  • gabriellacerda