A lightweight, intuitive, vanilla ES6 fueled JS cookie and local storage library.
// Cookie
crumbs.set("Operating System","Win10"); // => true
// Local storage key
crumbs.ls.set("Operating System","Win10") // => true
// The "expires" parameter is capable of taking a number, and will default as days.
crumbs.set("Name","Roy Azaeev",{type:"day",value:7},"/crumbsjs"); // => true
const my_cookies = [];
my_cookies.push({name:"Operating System",value:"Win10"});
my_cookies.push({name:"Age",value:"29"});
crumbs.set(my_cookies); // => [{name:"Operating System",value:"Win10"},{name:"Age",value:"29"}]
const my_localstorage_array = [];
my_localstorage_array.push({"key":"Operating System","value":"Win10"});
my_localstorage_array.push({"key":"Age","value":"29"});
crumbs.ls.set(my_localstorage_array); // => [{key:"Operating System",value:"Win10"},{key:"Age",value:"29"}]
// Cookie
let age = crumbs.get("Age"); // => "29"
// Local storage
let age = crumbs.ls.get("Age"); // => "29"
// Cookies
let all_cookies = crumbs.getAll(); // => [{name:"Operating System",value:"Win10"},{name:"Age",value:"29"}]
// Local storage
let all_localstorage = crumbs.ls.getAll(); // => [{key:"Operating System",value:"Win10"},{key:"Age",value:"29"}]
// Cookie
crumbs.delete("Operating system"); // => true
// Local storage
crumbs.ls.delete("Operating system"); // => true
const my_cookies = [];
my_cookies.push("Operating system");
my_cookies.push("Age");
crumbs.delete(my_cookies); // => true
- NO DEPENDENCIES - Yup, no jQuery.
- ES5 compatible.
- Tested, using Jest.
- Add one or multiple cookies or local storage keys at once
- Update cookies or local storage keys using the
set
method - Delete one or multiple cookies at once
- Delete local storage keys easily
- Display a cookie or a local storage key value
- Display all cookies or local storage keys in a key-value easy to read object
- Fallback to cookies when localstorage is not available (Safari private browsing)
Sets one or more cookies or local storage keys.
name can be set as an array of key-pair objects in the format of {name:"Age",value:29} for mass cookie set
Gets a cookie or a local storage value by its name.
Gets all the cookies or local storage keys in a key-pair object array.
Deletes a cookie or local storage key by its name.
name can be set as an array of strings for mass delete of cookies
Deletes all cookies or local storage keys.
You can import CrumbsJS like that
import crumbs from 'crumbsjs';
use npm
npm install crumbsjs
use git
git clone https://github.com/nirtz89/crumbsjs.git
- IndexDB support
- Session storage support
Thank you for making the library better!