Gathering detailed insights and metrics for cookies-js
Gathering detailed insights and metrics for cookies-js
Gathering detailed insights and metrics for cookies-js
Gathering detailed insights and metrics for cookies-js
JavaScript Client-Side Cookie Manipulation Library
npm install cookies-js
Typescript
Module System
Node Version
NPM Version
JavaScript (93.96%)
CSS (4.98%)
HTML (1.05%)
Total Downloads
19,996,810
Last Day
11,226
Last Week
50,994
Last Month
212,088
Last Year
3,508,947
1,772 Stars
140 Commits
169 Forks
48 Watching
1 Branches
10 Contributors
Minified
Minified + Gzipped
Latest Version
1.2.3
Package Id
cookies-js@1.2.3
Size
7.23 kB
NPM Version
2.15.9
Node Version
4.6.0
Publised On
06 Nov 2016
Cumulative downloads
Total Downloads
Last day
-1.1%
11,226
Compared to previous day
Last week
-7.2%
50,994
Compared to previous week
Last month
2.8%
212,088
Compared to previous month
Last year
28.8%
3,508,947
Compared to previous year
No dependencies detected.
Cookies.js is a small client-side javascript library that makes managing cookies easy.
Features
Browser Compatibility
Getting the Library
Use in CommonJS/Node Environments Without window
A Note About Encoding
API Reference
The following browsers have passed all of the automated Cookies.js tests:
npm install cookies-js
bower install cookies-js
window
In environments where there is no native window
object, Cookies.js will export a factory method
that accepts a window
instance. For example, using jsdom, you
might do something like:
1var jsdom = require('jsdom'); 2var window = jsdom.jsdom().parentWindow; 3var Cookies = require('cookies-js')(window); 4 5// Use Cookies as you normally would
RFC6265 defines a strict set of allowed characters for cookie keys and values. In order to effectively allow any character to be used in a key or value, Cookies.js will URI encode disallowed characters in their UTF-8 representation. As such, Cookies.js also expects cookie keys and values to already be URI encoded in a UTF-8 representation when it accesses cookies. Keep this in mind when working with cookies on the server side.
Do not use HttpUtility.UrlEncode and
HttpUtility.UrlDecode on cookie keys or
values. HttpUtility.UrlEncode
will improperly escape space characters to '+'
and lower case every
escape sequence. HttpUtility.UrlDecode
will improperly unescape every '+'
to a space character.
Instead, use
System.Uri.EscapeDataString
and System.Uri.UnescapeDataString.
Methods
Cookies.set(key, value [, options])
Cookies.get(key)
Cookies.expire(key [, options])
Properties
Cookies.enabled
Cookies.defaults
Alias: Cookies(key, value [, options])
Sets a cookie in the document. If the cookie does not already exist, it will be created. Returns the Cookies
object.
Option | Description | Default |
---|---|---|
path | A string value of the path of the cookie | "/" |
domain | A string value of the domain of the cookie | undefined |
expires | A number (of seconds), a date parsable string, or a Date object of when the cookie will expire | undefined |
secure | A boolean value of whether or not the cookie should only be available over SSL | false |
A default value for any option may be set in the Cookies.defaults
object.
Example Usage
1// Setting a cookie value 2Cookies.set('key', 'value'); 3 4// Chaining sets together 5Cookies.set('key', 'value').set('hello', 'world'); 6 7// Setting cookies with additional options 8Cookies.set('key', 'value', { domain: 'www.example.com', secure: true }); 9 10// Setting cookies with expiration values 11Cookies.set('key', 'value', { expires: 600 }); // Expires in 10 minutes 12Cookies.set('key', 'value', { expires: '01/01/2012' }); 13Cookies.set('key', 'value', { expires: new Date(2012, 0, 1) }); 14Cookies.set('key', 'value', { expires: Infinity }); 15 16// Using the alias 17Cookies('key', 'value', { secure: true });
Alias: Cookies(key)
Returns the value of the most locally scoped cookie with the specified key.
Example Usage
1// First set a cookie 2Cookies.set('key', 'value'); 3 4// Get the cookie value 5Cookies.get('key'); // "value" 6 7// Using the alias 8Cookies('key'); // "value"
Alias: Cookies(key, undefined
[, options])
Expires a cookie, removing it from the document. Returns the Cookies
object.
Option | Description | Default |
---|---|---|
path | A string value of the path of the cookie | "/" |
domain | A string value of the domain of the cookie | undefined |
A default value for any option may be set in the Cookies.defaults
object.
Example Usage
1// First set a cookie and get its value 2Cookies.set('key', 'value').get('key'); // "value" 3 4// Expire the cookie and try to get its value 5Cookies.expire('key').get('key'); // undefined 6 7// Using the alias 8Cookies('key', undefined);
A boolean value of whether or not the browser has cookies enabled.
Example Usage
1if (Cookies.enabled) { 2 Cookies.set('key', 'value'); 3}
An object representing default options to be used when setting and expiring cookie values.
Option | Description | Default |
---|---|---|
path | A string value of the path of the cookie | "/" |
domain | A string value of the domain of the cookie | undefined |
expires | A number (of seconds), a date parsable string, or a Date object of when the cookie will expire | undefined |
secure | A boolean value of whether or not the cookie should only be available over SSL | false |
Example Usage
1Cookies.defaults = { 2 path: '/', 3 secure: true 4}; 5 6Cookies.set('key', 'value'); // Will be secure and have a path of '/' 7Cookies.expire('key'); // Will expire the cookie with a path of '/'
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More