1.2.4 • Published 1 year ago

cookie-handler v1.2.4

Weekly downloads
12
License
MIT
Repository
github
Last release
1 year ago

cookie-handler

Handle cookies in a easy way

Methods availables

get

cookies.get(key , isString=false, markAsErasable=false );

If you need to retrieve a cookie value from cookies, just give it the key:

//document.cookie -> "foo=idunno; bar=firstValue"

var myValue = cookies.get('foo');
console.log('my value', myValue);//idunno

var otherValue = cookies.get('inexistent');
console.log(otherValue);//null

Also, you can just mark as erasable value(after it is recovered):

//document.cookie -> "foo=idunno; bar=firstValue"

var myValue = cookies.get('foo', false, true);
console.log(myValue);//idunno

var otherValue = cookies.get('foo', false, true);
console.log(otherValue);//null

//document.cookie -> "bar=firstValue"

set

cookies.set(key, value , time=365 );

to set a new cookie value, just give it the key and its value. Optionally, you can send how many days your cookie will survive.

cookies.set('coffeeType', 'mocha');

//cookie="foo=idunno; bar=firstValue; coffeeType=mocha"

format

format supported by this lib

  • s : seconds
  • m : minutes
  • h : hours
  • d : days (by default)
cookies.set('coffeeType', 'mocha', 1, 's');

//cookie="foo=idunno; bar=firstValue; coffeeType=mocha"

remove

cookies.remove(key);

To remove a cookie, just pass the key.

//cookie="foo=idunno; bar=firstValue"

cookies.remove('foo');

//cookie="bar=firstValue"
1.2.4

1 year ago

1.2.3

3 years ago

1.2.2

4 years ago

1.3.0

4 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

8 years ago

1.0.0

8 years ago