react-cookie
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -8,3 +8,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
function load(name, doNotParse) { | ||
var cookies; | ||
var cookies = {}; | ||
@@ -15,3 +15,3 @@ if (typeof document !== 'undefined') { | ||
var cookieVal = cookies[name] || _rawCookie[name]; | ||
var cookieVal = (cookies && cookies[name]) || _rawCookie[name]; | ||
@@ -71,4 +71,8 @@ if (!doNotParse) { | ||
function plugToRequest(req, res) { | ||
if (req && req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
if (req) { | ||
if (req.cookie) { | ||
_rawCookie = req.cookie; | ||
} else if (req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
} | ||
} | ||
@@ -75,0 +79,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var cookie=require("cookie");var _rawCookie={};var _res=undefined;function load(name,doNotParse){var cookies;if(typeof document!=="undefined"){cookies=cookie.parse(document.cookie)}var cookieVal=cookies[name]||_rawCookie[name];if(!doNotParse){try{cookieVal=JSON.parse(cookieVal)}catch(e){}}return cookieVal}function save(name,val,opt){_rawCookie[name]=val;if(typeof val==="object"){_rawCookie[name]=JSON.stringify(val)}if(typeof document!=="undefined"){document.cookie=cookie.serialize(name,_rawCookies[name],opt)}if(_res&&_res.cookie){_res.cookie(name,val,opt)}}function remove(name,path){delete _rawCookie[name];if(typeof document!=="undefined"){var removeCookie=name+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";if(path){removeCookie+=" path="+path}document.cookie=removeCookie}if(_res&&_res.clearCookie){var opt=path?{path:path}:undefined;_res.clearCookie(name,opt)}}function setRawCookie(rawCookie){_rawCookie=cookie.parse(rawCookie)}function plugToRequest(req,res){if(req&&req.headers&&req.headers.cookie){setRawCookie(req.headers.cookie)}_res=res}var reactCookie={load:load,save:save,remove:remove,setRawCookie:setRawCookie,plugToRequest:plugToRequest};if(typeof window!=="undefined"){window["reactCookie"]=reactCookie}module.exports=reactCookie},{cookie:2}],2:[function(require,module,exports){exports.parse=parse;exports.serialize=serialize;var decode=decodeURIComponent;var encode=encodeURIComponent;function parse(str,options){var obj={};var opt=options||{};var pairs=str.split(/; */);var dec=opt.decode||decode;pairs.forEach(function(pair){var eq_idx=pair.indexOf("=");if(eq_idx<0){return}var key=pair.substr(0,eq_idx).trim();var val=pair.substr(++eq_idx,pair.length).trim();if('"'==val[0]){val=val.slice(1,-1)}if(undefined==obj[key]){obj[key]=tryDecode(val,dec)}});return obj}function serialize(name,val,options){var opt=options||{};var enc=opt.encode||encode;var pairs=[name+"="+enc(val)];if(null!=opt.maxAge){var maxAge=opt.maxAge-0;if(isNaN(maxAge))throw new Error("maxAge should be a Number");pairs.push("Max-Age="+maxAge)}if(opt.domain)pairs.push("Domain="+opt.domain);if(opt.path)pairs.push("Path="+opt.path);if(opt.expires)pairs.push("Expires="+opt.expires.toUTCString());if(opt.httpOnly)pairs.push("HttpOnly");if(opt.secure)pairs.push("Secure");return pairs.join("; ")}function tryDecode(str,decode){try{return decode(str)}catch(e){return str}}},{}]},{},[1]); | ||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var cookie=require("cookie");var _rawCookie={};var _res=undefined;function load(name,doNotParse){var cookies={};if(typeof document!=="undefined"){cookies=cookie.parse(document.cookie)}var cookieVal=cookies&&cookies[name]||_rawCookie[name];if(!doNotParse){try{cookieVal=JSON.parse(cookieVal)}catch(e){}}return cookieVal}function save(name,val,opt){_rawCookie[name]=val;if(typeof val==="object"){_rawCookie[name]=JSON.stringify(val)}if(typeof document!=="undefined"){document.cookie=cookie.serialize(name,_rawCookies[name],opt)}if(_res&&_res.cookie){_res.cookie(name,val,opt)}}function remove(name,path){delete _rawCookie[name];if(typeof document!=="undefined"){var removeCookie=name+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";if(path){removeCookie+=" path="+path}document.cookie=removeCookie}if(_res&&_res.clearCookie){var opt=path?{path:path}:undefined;_res.clearCookie(name,opt)}}function setRawCookie(rawCookie){_rawCookie=cookie.parse(rawCookie)}function plugToRequest(req,res){if(req){if(req.cookie){_rawCookie=req.cookie}else if(req.headers&&req.headers.cookie){setRawCookie(req.headers.cookie)}}_res=res}var reactCookie={load:load,save:save,remove:remove,setRawCookie:setRawCookie,plugToRequest:plugToRequest};if(typeof window!=="undefined"){window["reactCookie"]=reactCookie}module.exports=reactCookie},{cookie:2}],2:[function(require,module,exports){exports.parse=parse;exports.serialize=serialize;var decode=decodeURIComponent;var encode=encodeURIComponent;function parse(str,options){var obj={};var opt=options||{};var pairs=str.split(/; */);var dec=opt.decode||decode;pairs.forEach(function(pair){var eq_idx=pair.indexOf("=");if(eq_idx<0){return}var key=pair.substr(0,eq_idx).trim();var val=pair.substr(++eq_idx,pair.length).trim();if('"'==val[0]){val=val.slice(1,-1)}if(undefined==obj[key]){obj[key]=tryDecode(val,dec)}});return obj}function serialize(name,val,options){var opt=options||{};var enc=opt.encode||encode;var pairs=[name+"="+enc(val)];if(null!=opt.maxAge){var maxAge=opt.maxAge-0;if(isNaN(maxAge))throw new Error("maxAge should be a Number");pairs.push("Max-Age="+maxAge)}if(opt.domain)pairs.push("Domain="+opt.domain);if(opt.path)pairs.push("Path="+opt.path);if(opt.expires)pairs.push("Expires="+opt.expires.toUTCString());if(opt.httpOnly)pairs.push("HttpOnly");if(opt.secure)pairs.push("Secure");return pairs.join("; ")}function tryDecode(str,decode){try{return decode(str)}catch(e){return str}}},{}]},{},[1]); |
12
index.js
@@ -7,3 +7,3 @@ var cookie = require('cookie'); | ||
function load(name, doNotParse) { | ||
var cookies; | ||
var cookies = {}; | ||
@@ -14,3 +14,3 @@ if (typeof document !== 'undefined') { | ||
var cookieVal = cookies[name] || _rawCookie[name]; | ||
var cookieVal = (cookies && cookies[name]) || _rawCookie[name]; | ||
@@ -70,4 +70,8 @@ if (!doNotParse) { | ||
function plugToRequest(req, res) { | ||
if (req && req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
if (req) { | ||
if (req.cookie) { | ||
_rawCookie = req.cookie; | ||
} else if (req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
} | ||
} | ||
@@ -74,0 +78,0 @@ |
{ | ||
"name": "react-cookie", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Load and save cookies within your React application", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13865
241
0