1.2.3 • Published 2 years ago

@dbpkgs/cookie v1.2.3

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

A Browser Cookie

Cookie Action Status Downloads Action Status

A lightweight browser cookie library for frontend applications Library also supports special characters encoding

Installation

npm install @dbpkgs/cookie

or

yarn add @dbpkgs/cookie

Usage

Set Cookie

import cookie from '@dbpkgs/cookie';

cookie.set('COOKIE_NAME', 'COOKIE_VALUE', options);
//options are optional, check below for acceptable options

Cookie options

{
  expires?: Date
  path?: string
  domain?: string
  secure?: boolean
}

Get Cookie

import cookie from '@dbpkgs/cookie';

cookie.get('COOKIE_NAME');

Remove Cookie

import cookie from '@dbpkgs/cookie';

cookie.remove('COOKIE_NAME');

Example Usage

Testing in applications

import cookie from '@dbpkgs/cookie';

cookie.set('session', 'Uxc70_67gGuHHvAmTy10a', {
  expires: new Date(2022, 03, 13),
  path: '',
  secure: true,
});

Testing in unit test libraries

At the moment the library is being tested with jest unit testing library

import cookie from '@dbpkgs/cookie';

test('Check if cookie is set to browser properly', () => {
  expect(cookie.set('test_session', 'Ab7MNgGyql89hpPalIdgql01gTjkaGb5')).toBe(
    'test_session=Ab7MNgGyql89hpPalIdgql01gTjkaGb5',
  );
});

License

MIT

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago