Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56
🍪 A simple, lightweight JavaScript API for handling browser cookies , it is easy to pick up and use, has a reasonable footprint(~2kb, gzipped: 0.95kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.https://jaywcjlove.github.io/cookie.js/
jaywcjlove/cookie.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
🍪 A simple, lightweight JavaScript API for handling browser cookies, it is easy to pick up and use, has a reasonable footprint (~2kb) (gzipped: 0.84kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.
Oldv1 versiondocument preview.
Features:
🚀 Has no dependencies
🌱 Works in all browsers
🍁 Support TypeScript, includingd.ts definition
🔥 Heavily tested
📦 Supports AMD/CommonJS
💥cookie.min.js 2.01kb(gzipped: 0.84kb)
Installed via npm. You will need Node.js installed on your system.
$ npm install cookiejs --save
importcookiefrom'cookiejs';cookie("test","tank",1)
Or manually download and linkcookiejs in your HTML, It can also be downloaded viaUNPKG orjsDelivr CDN:
<scriptsrc="https://unpkg.com/cookiejs/dist/cookie.min.js"></script><scripttype="text/javascript">cookie("test","tank",1);</script>
cookie(key, value, num)
keycookie namevaluecookie valuenumexpires time
cookie('test','tank',1)// Create a cookie that expires 1 days from nowcookie('test')// Create a cookie, valid across the entire sitecookie('test',null)// Delete cookie `test`cookie()// Get all cookiecookie.set('test','tank',1)// ====cookie('test', 'tank', 1)cookie.get('test')// ====cookie('test')cookie.remove('test')// ====cookie('test',null)cookie.remove('test3','test4')// Delete cookie `test3` and `test4`cookie.clear()// Clean all cookiecookie.all()// Get all cookie
cookie.set(name, value, options)
The same effectcookie(name, value, options)
Set the value of the cookie in batches
cookie.set({name1:'value1',name2:'value2'});
Create cookie that expires 30 days from now
cookie('test','tank',30);// Create a cookie that expires 30 days from nowcookie({'test':'123','test2':'456'},{// 批量设置'expires':30,'path':'/','domain':''});
Create cookie that expires 30 days from now,and set cookie attributes
cookie('test','123',{'expires':30,'path':'/','domain':''});
individually for each call tocookie.set(...) by passing a plain object in the last argument. Per-call attributes override the default attributes.
Examples:
cookie('name','value',{'expires':30,'path':'/','domain':''});cookie.get('name')cookie.remove('name')
Define when the cookie will be removed. Value can be a Number which will be interpreted as days from time of creation or a Date instance. If omitted, the cookie becomes a session cookie.
cookie('name','value',{'expires':30});
Default:
/
A String indicating the path where the cookie is visible.
cookie.set('name','value',{path:''});cookie.get('name');// => 'value'
Default: Cookie is visible only to the domain or subdomain of the page where the cookie was created, except for Internet Explorer (see: Note regarding Internet Explorer default behavior).
⚠️ If you omit the domain attribute, it will be visible for a subdomain in IE.
A String indicating a valid domain where the cookie should be visible. The cookie will also be visible to all subdomains.
Examples:
cookie.set('name','value',{domain:'subdomain.website.com'});cookie.get('name');// => undefined (need to read at 'subdomain.website.com')
Default: No secure protocol requirement.
Either true or false, indicating if the cookie transmission requires a secure protocol (https).
Here's an examples:
cookie.set('name','value',{secure:true});cookie.get('name');// => 'value'cookie.remove('name');
TheSameSite attribute lets servers specify whether/when cookies are sent with cross-site requests (whereSite is defined by the registrable domain and the scheme: http or https). This provides some protection against cross-site request forgery attacks (CSRF). It takes three possible values: Strict, Lax, and None.
With Strict, the cookie is only sent to the site where it originated. Lax is similar, except that cookies are sent when the user navigates to the cookie's origin site. For example, by following a link from an external site. None specifies that cookies are sent on both originating and cross-site requests, but only in secure contexts (i.e., ifSameSite=None then the Secure attribute must also be set). If noSameSite attribute is set, the cookie is treated as Lax.
Here's an example:
cookie.set('name','value',{sameSite:'Strict'});
Note: The standard related to
SameSiterecently changed (MDN documents the new behavior above). See the cookiesBrowser compatibility table for information about how the attribute is handled in specific browser versions:
SameSite=Laxis the new default ifSameSiteisn't specified. Previously, cookies were sent for all requests by default.
- Cookies with
SameSite=Nonemust now also specify theSecureattribute (they require a secure context).- Cookies from the same domain are no longer considered to be from the same site if sent using a different scheme (
http:orhttps:).
- storejs A simple, lightweight JavaScript API for handling browser localStorage , it is easy to pick up and use, has a reasonable footprint 2.36kb(gzipped: 1.04kb), and has no dependencies.
As always, thanks to our amazing contributors!
Made withaction-contributors.
Licensed under the MIT License.
About
🍪 A simple, lightweight JavaScript API for handling browser cookies , it is easy to pick up and use, has a reasonable footprint(~2kb, gzipped: 0.95kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.https://jaywcjlove.github.io/cookie.js/
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.