2.0.8 • Published 2 years ago

@juji/simple-cookie v2.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simple-cookie

simple cookie serializer & parser for node.js

NPM Version

usage

import { stringify, parse, tokenize } from '@juji/simple-cookie';
// const { stringify, parse, tokenize } = require('@juji/simple-cookie');

const cookieObject = {
  name: 'cookieName',
  value: 'cookie value',
  expires: (new Date()).valueOf() + 500000,
  path: '/',
  domain: 'domain.com',
  httponly: false,
  secure: true,
  samesite: 'None'
}

What is cookieObject:

name String : cookie name

value String : cookie value

expires DateString | Number | Date (optional) : expire date (default type is Date), value will be used as a parameter in new Date. e.g. new Date(yourDateString).

path String (optional) : cookie path, defaults to /

domain String (optional) : cookie domain

httponly Boolean (optional) : defaults to false

secure Boolean (optional) : defaults to false

samesite String (optional) : SameSite attribute

methods

import { 
  type CookieObject, 
  stringify, parse, tokenize 
} from '@juji/simple-cookie';

const cookie: string = stringify( cookieObject );
// cookieName=cookie%20value; Expires: Sat, 15-Aug-2015 17:41:05 GMT; Max-Age: 31449600; Path=/; domain=domain.com; secure; samesite=None


const cookieObject: CookieObject = parse( 
  cookieString  [, defaultPath]  [, defaultDomain]  
);
// will create object like the 'cookieObject'


const tokens: string = tokenize([
  {name:'cookie1', value: 'cvalue1'},
  {name:'cookie2', value: 'cvalue2'},
  {name:'cookie3', value: 'cvalue3'}
]);
// cookie1=cvalue1; cookie2=cvalue2; cookie3=cvalue3

cheers,

jujiyangasli.com

1.0.19

2 years ago

1.0.28

2 years ago

1.0.17

2 years ago

1.0.27

2 years ago

1.0.16

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

2.0.1

2 years ago

1.0.35

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.15

2 years ago