Skip to content

EmilEinarsen/cookie-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Format and sets the cookie according to params. Takes three parameters, key (string), value (any) 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

Gets the cookies value by keye. Takes two parameters, key (string) and the optional initalValue. Returns value if defined otherwise initalValue.

Check

Info: Wrapper around get. Checks if a cookie has been set by given key. Takes one param, key. Returns Boolean.

Destroy

Info: Wrapper around set, setting the expiration date to yesterday. Destroys a cookie. Takes one param, key.

Contribution

Pull requests are welcome. For any considerable changes, please open an issue first to discuss what you would like to change.

Licence

MIT

Releases

No releases published

Packages

No packages published