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

browser-cookie

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-cookie - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/spec/clear.js

45

lib/cookie.js

@@ -17,3 +17,3 @@ /**

* @param options.path Define the path where the cookie is valid, default is /.
* @param options.domain Define the domain whether the cookie is valid.
* @param options.domain Define the domain where the cookie is valid.
* @param options.secure If true, the cookie transmission requires a

@@ -24,6 +24,8 @@ * secure protocol (https).

this.options = options || {};
this.options.expires = this.options.expires || 30;
this.options.path = this.options.path || '/';
this.options.secure = typeof this.options.secure === 'boolean' ?
this.options.secure : false;
this.options.expires =
typeof this.options.expires === 'number' ? this.options.expires : 30;
this.options.path =
this.options.path !== undefined ? this.options.path : '/';
this.options.secure = typeof this.options.secure === 'boolean'
? this.options.secure : false;
}

@@ -42,5 +44,4 @@

options = options || this.options;
var days = options.expires = typeof options.expires === 'number'
? options.expires : 1;
if (value !== undefined && !(typeof value === 'function')) {
var days = parseInt(options.expires || -1);
if(value !== undefined && typeof value !== 'function') {
var t = new Date();

@@ -67,8 +68,6 @@ t.setDate((t.getDate() + days));

function get(key, value) {
var result = key ? null : {};
// 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 $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];
var i, parts, name, cookie;
var result = key ? undefined : {};
/* istanbul ignore next */
var cookies = (document.cookie || '').split('; ');
for (i = 0; i < cookies.length; i++) {

@@ -79,7 +78,7 @@ parts = cookies[i].split('=');

if (key && key === name) {
// If second argument (value) is a function it's a converter...
// if second argument (value) is a function it's a converter
result = this.read(cookie, value);
break;
}
// Prevent storing a cookie that we couldn't decode.
// prevent storing a cookie that we couldn't decode
if (!key && (cookie = this.read(cookie)) !== undefined) {

@@ -160,19 +159,13 @@ result[name] = cookie;

function parse(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
// this is a quoted cookie as according to RFC2068, unescape
if(s.indexOf('"') === 0) {
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}
// decode and parse
try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
} catch(e) {
return null;
}
try {
// If we can't parse the cookie, ignore it, it's unusable.
return this.options.json ? JSON.parse(s) : s;
} catch(e) {}
// if we can't decode or parse the cookie it is unusable
}catch(e) {}
}

@@ -179,0 +172,0 @@

{
"name": "browser-cookie",
"version": "1.0.1",
"version": "1.0.2",
"description": "Standalone cookie class for the browser.",

@@ -5,0 +5,0 @@ "author": "muji <noop@xpm.io>",

@@ -1,1 +0,13 @@

module.exports = require('./cookie');
module.exports = [
require('./options'),
require('./set'),
require('./get'),
require('./string'),
require('./json'),
require('./raw'),
require('./converter'),
require('./quoted'),
require('./decode'),
require('./del'),
require('./clear'),
]
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