@vessp/cookie
v1.0.0
Published
Browser cookie CRUD helper
Downloads
3
Readme
@vessp/cookie
Browser cookie CRUD helper
Installation
npm install --save @vessp/cookie
Usage
import Cookie from '@vessp/cookie'
Cookie.set('pool', '6', {
// Scope
domain: 'aiur.com', // default: undefined
path: '/hatch', // default: '/'
sameSite: 'lax', // [ strict | lax | none ], default: undefined
secure: true, // default: true
// Expiry
expires: new Date().toUTCString() // date when the cookie should expire, default: undefined
maxAge: 24 * 60 * 60, // expires in <maxAge> seconds, default: undefined
})
// Cookie.get(name) returns cookie value string
Cookie.get('pool')
Cookie.get('pool', {
path: '/hatch',
domain: 'aiur.com',
})
// Cookie.has(name) returns boolean
Cookie.has('pool')
// Cookie.remove(name, { domain, path })
Cookie.remove('pool', {
domain: 'aiur.com',
path: '/hatch',
})
Notes
- Cookie.remove() functions by setting cookie max-age to 0
- For more detailed explanation of cookie options see here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie