bjork_cookie
v1.2.5
Published
A collection for managing cookies
Downloads
11
Maintainers
Readme
What is this?
An object containing four methods for managing cookies. The main methods set and get. And the secondary methods check and destroy.
Install
Use npm to install bjork_cookies or copy the code manually from github.
> npm i bjork_cookie
Usage
> const cookie = require('bjork_cookie')
>
> cookie.set(key, value, opions?)
> cookie.get(key, initalValue)
> cookie.destroy(key)
> cookie.check(key)
Set
Packages and sets a cookie according to params. Takes three parameters, key (string), value (*) and the optional options (object).
Options
- days (number): Expiration date of the cookie in days (@default 7)
- path (string): Indicates a URL path. (@default '/')
Get
Fetches cookie by key and extracts value. Takes two parameters, key (string) and the optional initalValue. Returns value | initalValue.
Check
Checks if a cookie by the given key exists. Takes one param, key. Returns Boolean. Utilizes get.
Destroy
Destroys a cookie by overwriting it. Takes one param, key. Utilizes set and an expiration date of yesterday.
Contribution
Pull requests are welcome. For any considerable changes, please open an issue first to discuss what you would like to change.