Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-cookie

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-cookie - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

14

package.json
{
"name": "js-cookie",
"version": "2.2.0",
"version": "2.2.1",
"description": "A simple, lightweight JavaScript API for handling cookies",

@@ -10,3 +10,2 @@ "main": "src/js.cookie.js",

"keywords": [
"jquery-plugin",
"cookie",

@@ -36,11 +35,10 @@ "cookies",

"devDependencies": {
"grunt": "1.0.1",
"grunt": "1.0.3",
"grunt-compare-size": "0.4.2",
"grunt-contrib-connect": "1.0.2",
"grunt-contrib-jshint": "1.1.0",
"grunt-contrib-nodeunit": "1.0.0",
"grunt-contrib-connect": "2.0.0",
"grunt-contrib-nodeunit": "2.0.0",
"grunt-contrib-qunit": "2.0.0",
"grunt-contrib-uglify": "2.3.0",
"grunt-contrib-watch": "1.0.0",
"grunt-jscs": "3.0.1",
"grunt-contrib-watch": "1.1.0",
"grunt-eslint": "21.0.0",
"grunt-saucelabs": "9.0.0",

@@ -47,0 +45,0 @@ "gzip-js": "0.3.2",

@@ -23,3 +23,3 @@ <p align="center">

## Build Status Matrix
## Build Status Matrix ([including active Pull Requests](https://github.com/js-cookie/js-cookie/issues/286))

@@ -51,5 +51,10 @@ [![Selenium Test Status](https://saucelabs.com/browser-matrix/js-cookie.svg)](https://saucelabs.com/u/js-cookie)

#### NPM
```
$ npm install js-cookie --save
```
### Module Loaders
JavaScript Cookie can also be loaded as an AMD, CommonJS or [ES6](https://github.com/js-cookie/js-cookie/issues/233#issuecomment-233187386) module.
JavaScript Cookie can also be loaded as an AMD or CommonJS module.

@@ -89,2 +94,12 @@ ## Basic Usage

*Note: It is not possible to read a particular cookie by passing one of the cookie attributes (which may or may not
have been used when writing the cookie in question):*
```javascript
Cookies.get('foo', { domain: 'sub.example.com' }); // `domain` won't have any effect...!
```
The cookie with the name `foo` will only be available on `.get()` if it's visible from where the
code is called; the domain and/or path attribute will not have an effect when reading.
Delete cookie:

@@ -104,6 +119,10 @@

*IMPORTANT! when deleting a cookie, you must pass the exact same path and domain attributes that was used to set the cookie, unless you're relying on the [default attributes](#cookie-attributes).*
*IMPORTANT! When deleting a cookie and you're not relying on the [default attributes](#cookie-attributes), you must pass the exact same path and domain attributes that were used to set the cookie:*
*Note: Removing unexisting cookie does not raise any exception nor return any value*
```javascript
Cookies.remove('name', { path: '', domain: '.yourdomain.com' });
```
*Note: Removing a nonexistent cookie does not raise any exception nor return any value.*
## Namespace conflicts

@@ -159,2 +178,4 @@

*Note: According to [RFC 6265](https://tools.ietf.org/html/rfc6265#section-6.1), your cookies may get deleted if they are too big or there are too many cookies in the same domain, [more details here](https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#why-are-my-cookies-being-deleted).*
## Cookie Attributes

@@ -200,4 +221,6 @@

This means one cannot set a path using `path: window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).
This means one cannot set a path using `window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).
In fact, you should never allow untrusted input to set the cookie attributes or you might be exposed to a [XSS attack](https://github.com/js-cookie/js-cookie/issues/396).
### domain

@@ -204,0 +227,0 @@

@@ -35,3 +35,3 @@ # Server-side integration

return encodeURIComponent(value)
// Revert the characters that are unnecessarly encoded but are
// Revert the characters that are unnecessarily encoded but are
// allowed in a cookie value, except for the plus sign (%2B)

@@ -66,3 +66,3 @@ .replace(/%(23|24|26|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);

return encodeURIComponent(value)
// Revert the characters that are unnecessarly encoded but are
// Revert the characters that are unnecessarily encoded but are
// allowed in a cookie value

@@ -100,3 +100,3 @@ .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)

return encodeURIComponent(value)
// Revert the characters that are unnecessarly encoded but are
// Revert the characters that are unnecessarily encoded but are
// allowed in a cookie value

@@ -103,0 +103,0 @@ .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)

/*!
* JavaScript Cookie v2.2.0
* JavaScript Cookie v2.2.1
* https://github.com/js-cookie/js-cookie

@@ -9,3 +9,3 @@ *

;(function (factory) {
var registeredInModuleLoader = false;
var registeredInModuleLoader;
if (typeof define === 'function' && define.amd) {

@@ -40,5 +40,10 @@ define(factory);

function decode (s) {
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
}
function init (converter) {
function api (key, value, attributes) {
var result;
function api() {}
function set (key, value, attributes) {
if (typeof document === 'undefined') {

@@ -48,62 +53,61 @@ return;

// Write
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (arguments.length > 1) {
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
}
if (typeof attributes.expires === 'number') {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
attributes.expires = expires;
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
try {
var result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
value = converter.write ?
converter.write(value, key) :
encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
key = encodeURIComponent(String(key))
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
.replace(/[\(\)]/g, escape);
if (!converter.write) {
value = encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
stringifiedAttributes += '=' + attributes[attributeName];
}
return (document.cookie = key + '=' + value + stringifiedAttributes);
// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}
// Read
return (document.cookie = key + '=' + value + stringifiedAttributes);
}
if (!key) {
result = {};
function get (key, json) {
if (typeof document === 'undefined') {
return;
}
var jar = {};
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;

@@ -115,3 +119,3 @@

if (!this.json && cookie.charAt(0) === '"') {
if (!json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);

@@ -121,8 +125,7 @@ }

try {
var name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read ?
converter.read(cookie, name) : converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);
var name = decode(parts[0]);
cookie = (converter.read || converter)(cookie, name) ||
decode(cookie);
if (this.json) {
if (json) {
try {

@@ -133,29 +136,22 @@ cookie = JSON.parse(cookie);

jar[name] = cookie;
if (key === name) {
result = cookie;
break;
}
if (!key) {
result[name] = cookie;
}
} catch (e) {}
}
return result;
return key ? jar[key] : jar;
}
api.set = api;
api.set = set;
api.get = function (key) {
return api.call(api, key);
return get(key, false /* read as raw */);
};
api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
api.getJSON = function (key) {
return get(key, true /* read as json */);
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', extend(attributes, {
set(key, '', extend(attributes, {
expires: -1

@@ -165,2 +161,4 @@ }));

api.defaults = {};
api.withConverter = init;

@@ -167,0 +165,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc