Socket
Socket
Sign inDemoInstall

js-cookie

Package Overview
Dependencies
0
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-rc.3 to 3.0.0-rc.4

dist/js.cookie.min.js

219

dist/js.cookie.js

@@ -1,131 +0,142 @@

/*! js-cookie v3.0.0-rc.3 | MIT */
'use strict';
/*! js-cookie v3.0.0-rc.4 | MIT */
;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, (function () {
var current = global.Cookies;
var exports = global.Cookies = factory();
exports.noConflict = function () { global.Cookies = current; return exports; };
}()));
}(this, (function () { 'use strict';
function assign (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
function assign (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
}
}
return target
}
return target
}
var defaultConverter = {
read: function (value) {
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
function init (converter, defaultAttributes) {
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return
var defaultConverter = {
read: function (value) {
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
attributes = assign({}, defaultAttributes, attributes);
function init (converter, defaultAttributes) {
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return
}
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}
if (attributes.expires) {
attributes.expires = attributes.expires.toUTCString();
}
attributes = assign({}, defaultAttributes, attributes);
key = encodeURIComponent(key)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}
if (attributes.expires) {
attributes.expires = attributes.expires.toUTCString();
}
value = converter.write(value, key);
key = encodeURIComponent(key)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue
}
value = converter.write(value, key);
stringifiedAttributes += '; ' + attributeName;
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue
}
if (attributes[attributeName] === true) {
continue
}
stringifiedAttributes += '; ' + attributeName;
// 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];
}
if (attributes[attributeName] === true) {
continue
}
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];
}
function get (key) {
if (typeof document === 'undefined' || (arguments.length && !key)) {
return
return (document.cookie = key + '=' + value + stringifiedAttributes)
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var jar = {};
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var value = parts.slice(1).join('=');
if (value[0] === '"') {
value = value.slice(1, -1);
function get (key) {
if (typeof document === 'undefined' || (arguments.length && !key)) {
return
}
try {
var foundKey = defaultConverter.read(parts[0]);
jar[foundKey] = converter.read(value, foundKey);
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var jar = {};
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var value = parts.slice(1).join('=');
if (key === foundKey) {
break
if (value[0] === '"') {
value = value.slice(1, -1);
}
} catch (e) {}
}
return key ? jar[key] : jar
}
try {
var foundKey = defaultConverter.read(parts[0]);
jar[foundKey] = converter.read(value, foundKey);
return Object.create(
{
set: set,
get: get,
remove: function (key, attributes) {
set(
key,
'',
assign({}, attributes, {
expires: -1
})
);
},
withAttributes: function (attributes) {
return init(this.converter, assign({}, this.attributes, attributes))
},
withConverter: function (converter) {
return init(assign({}, this.converter, converter), this.attributes)
if (key === foundKey) {
break
}
} catch (e) {}
}
},
{
attributes: { value: Object.freeze(defaultAttributes) },
converter: { value: Object.freeze(converter) }
return key ? jar[key] : jar
}
)
}
var api = init(defaultConverter, { path: '/' });
return Object.create(
{
set: set,
get: get,
remove: function (key, attributes) {
set(
key,
'',
assign({}, attributes, {
expires: -1
})
);
},
withAttributes: function (attributes) {
return init(this.converter, assign({}, this.attributes, attributes))
},
withConverter: function (converter) {
return init(assign({}, this.converter, converter), this.attributes)
}
},
{
attributes: { value: Object.freeze(defaultAttributes) },
converter: { value: Object.freeze(converter) }
}
)
}
module.exports = api;
var api = init(defaultConverter, { path: '/' });
return api;
})));
{
"name": "js-cookie",
"version": "3.0.0-rc.3",
"version": "3.0.0-rc.4",
"description": "A simple, lightweight JavaScript API for handling cookies",
"main": "dist/js.cookie.js",
"browser": "dist/js.cookie.js",
"module": "dist/js.cookie.mjs",
"unpkg": "dist/js.cookie.umd.min.js",
"jsdelivr": "dist/js.cookie.umd.min.js",
"unpkg": "dist/js.cookie.min.js",
"jsdelivr": "dist/js.cookie.min.js",
"exports": {

@@ -10,0 +10,0 @@ "import": "./dist/js.cookie.mjs",

@@ -20,4 +20,4 @@ <p align="center">

**If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.
[View documentation for the latest release.](https://github.com/js-cookie/js-cookie/tree/latest#readme)**
**πŸ‘‰πŸ‘‰ If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.
[View documentation for the latest release.](https://github.com/js-cookie/js-cookie/tree/latest#readme) πŸ‘ˆπŸ‘ˆ**

@@ -34,4 +34,2 @@ ## Installation

The npm package has a `module` field pointing to an ES module variant of the library, mainly to provide support for ES module aware bundlers, whereas its `browser` field points to an UMD module for full backward compatibility.
### Direct download

@@ -58,3 +56,3 @@

<script type="module" src="/path/to/js.cookie.mjs"></script>
<script nomodule defer src="/path/to/js.cookie.js"></script>
<script nomodule defer src="/path/to/js.cookie.umd.js"></script>
```

@@ -66,19 +64,4 @@

Alternatively, include it via [jsDelivr CDN](https://www.jsdelivr.com/package/npm/js-cookie):
Alternatively, include it via [jsDelivr CDN](https://www.jsdelivr.com/package/npm/js-cookie).
UMD:
```html
<script src="//cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.umd.min.js"></script>
```
ES module:
```html
<script
type="module"
src="//cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.mjs"
></script>
```
## ES Module

@@ -85,0 +68,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc