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

universal-cookie

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-cookie - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0

53

lib/Cookies.js

@@ -29,12 +29,8 @@ 'use strict';

if ((0, _utils.isNode)()) {
if (typeof cookies === 'string') {
this.cookies = _cookie2.default.parse(cookies);
} else if ((typeof cookies === 'undefined' ? 'undefined' : _typeof(cookies)) === 'object') {
this.cookies = cookies;
} else {
throw new Error('Missing the cookie header or object');
}
} else if (cookies) {
throw new Error('The browser should not provide the cookies');
if (typeof cookies === 'string') {
this.cookies = _cookie2.default.parse(cookies);
} else if ((typeof cookies === 'undefined' ? 'undefined' : _typeof(cookies)) === 'object') {
this.cookies = cookies;
} else {
this.cookies = {};
}

@@ -46,2 +42,17 @@

_createClass(Cookies, [{
key: '_updateBrowserValues',
value: function _updateBrowserValues() {
if (!_utils.HAS_DOCUMENT_COOKIE) {
return;
}
var newCookies = _cookie2.default.parse(document.cookie);
// Make sure we keep the other cookies
// In test, sometimes we have an empty document.cookie
for (var name in newCookies) {
this.cookies[name] = newCookies[name];
}
}
}, {
key: 'get',

@@ -51,4 +62,4 @@ value: function get(name) {

var values = this.cookies || _cookie2.default.parse(document.cookie);
return readCookie(values[name], options);
this._updateBrowserValues();
return readCookie(this.cookies[name], options);
}

@@ -60,7 +71,7 @@ }, {

var values = this.cookies || _cookie2.default.parse(document.cookie);
this._updateBrowserValues();
var result = {};
for (var name in values) {
result[name] = readCookie(values[name], options);
for (var name in this.cookies) {
result[name] = readCookie(this.cookies[name], options);
}

@@ -81,5 +92,5 @@

if ((0, _utils.isNode)()) {
this.cookies[name] = value;
} else {
this.cookies[name] = value;
if (_utils.HAS_DOCUMENT_COOKIE) {
document.cookie = _cookie2.default.serialize(name, value, options);

@@ -100,5 +111,5 @@ }

if ((0, _utils.isNode)()) {
delete this.cookies[name];
} else {
delete this.cookies[name];
if (_utils.HAS_DOCUMENT_COOKIE) {
document.cookie = _cookie2.default.serialize(name, '', finalOptions);

@@ -105,0 +116,0 @@ }

@@ -6,12 +6,9 @@ 'use strict';

});
exports.isNode = isNode;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.cleanCookies = cleanCookies;
// Are we in the browser or node.js?
// Only reliable way to know is checking if we can access the browser cookies
var IS_NODE = typeof document === 'undefined' || typeof document.cookie === 'undefined';
// Can we get/set cookies on document.cookie?
var HAS_DOCUMENT_COOKIE = exports.HAS_DOCUMENT_COOKIE = (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object' && typeof document.cookie === 'string';
function isNode() {
return process.env.NODE_ENV === 'test' && typeof global.MOCK_IS_NODE !== 'undefined' ? global.MOCK_IS_NODE : IS_NODE;
}
function cleanCookies() {

@@ -18,0 +15,0 @@ document.cookie.split(';').forEach(function (c) {

{
"name": "universal-cookie",
"version": "2.0.9",
"version": "2.1.0",
"description": "Universal cookies for JavaScript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -26,3 +26,3 @@ <h3 align="center">

Create a cookies context
- cookieHeader (string|object): specify the cookie header on the server only
- cookieHeader (string|object): specify the cookie header or object

@@ -29,0 +29,0 @@ ### `get(name, [options])`

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