🍪 CrumbsJS 🍪
A lightweight, intuitive, vanilla ES6 fueled JS cookie and local storage library.
Quick Start
Adding a single cookie or a local storage key
// Cookiecrumbs; // => true // Local storage keycrumbsls // => true
Adding a single cookie that will expire in 7 days for a specific path
// The "expires" parameter is capable of taking a number, and will default as days.crumbs; // => true
Adding a few cookies at once
const my_cookies = ;my_cookies;my_cookies; crumbs; // => [{name:"Operating System",value:"Win10"},{name:"Age",value:"29"}]
Adding a few local storage keys at once
const my_localstorage_array = ;my_localstorage_array;my_localstorage_array; crumbs; // => [{key:"Operating System",value:"Win10"},{key:"Age",value:"29"}]
Get a cookie or a local storage key value
// Cookielet age = crumbs; // => "29" // Local storagelet age = crumbsls; // => "29"
Get all cookies or all local storage keys in a key-value pair object
// Cookieslet all_cookies = crumbs; // => [{name:"Operating System",value:"Win10"},{name:"Age",value:"29"}] // Local storagelet all_localstorage = crumbsls; // => [{key:"Operating System",value:"Win10"},{key:"Age",value:"29"}]
Delete a single cookie or local storage key
// Cookiecrumbs; // => true // Local storagecrumbsls; // => true
Delete a few cookies at once
const my_cookies = ;my_cookies;my_cookies; crumbs; // => true
Features
- 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)
Methods
set(name, value, [expires], [domain])
Sets one or more cookies.
name can be set as an array of key-pair objects in the format of {name:"Age",value:29} for mass cookie set
get(name)
Gets a cookie value by its name.
getAll()
Gets all the cookies in a key-pair object array.
delete(name)
Deletes a cookie by its name.
name can be set as an array of strings for mass delete of cookies
deleteAll()
Deletes all cookies.
Getting Started
Install On your local PC
Using a bundler ?
You can import CrumbsJS like that
;
Download Sources
use npm
npm install crumbsjs
use git
git clone https://github.com/nirtz89/crumbsjs.git
What's next
- IndexDB support
- Session storage support
Contributers
Thank you for making the library better!