react-cookie
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -34,3 +34,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 remove(name) { | ||
function remove(name, path) { | ||
delete _rawCookies[name]; | ||
@@ -40,3 +40,9 @@ delete _cookies[name]; | ||
if (typeof document !== 'undefined') { | ||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
var removeCookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
if (path) { | ||
removeCookie += ' path=' + path; | ||
} | ||
document.cookie = removeCookie; | ||
} | ||
@@ -46,2 +52,5 @@ } | ||
function setRawCookie(rawCookie) { | ||
_rawCookies = {}; | ||
_cookies = {}; | ||
if (!rawCookie) { | ||
@@ -48,0 +57,0 @@ return; |
@@ -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 _rawCookies={};var _cookies={};if(typeof document!=="undefined"){setRawCookie(document.cookie)}function load(name,doNotParse){if(doNotParse){return _rawCookies[name]}return _cookies[name]}function save(name,val,opt){_cookies[name]=val;_rawCookies[name]=val;if(typeof val==="object"){_rawCookies[name]=JSON.stringify(val)}if(typeof document!=="undefined"){document.cookie=cookie.serialize(name,_rawCookies[name],opt)}}function remove(name){delete _rawCookies[name];delete _cookies[name];if(typeof document!=="undefined"){document.cookie=name+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"}}function setRawCookie(rawCookie){if(!rawCookie){return}var rawCookies=cookie.parse(rawCookie);for(var key in rawCookies){_rawCookies[key]=rawCookies[key];try{_cookies[key]=JSON.parse(rawCookies[key])}catch(e){_cookies[key]=rawCookies[key]}}}var reactCookie={load:load,save:save,remove:remove,setRawCookie:setRawCookie};if(typeof window!=="undefined"){window["reactCookie"]=reactCookie}module.exports=reactCookie},{cookie:2}],2:[function(require,module,exports){var serialize=function(name,val,opt){opt=opt||{};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("; ")};var parse=function(str,opt){opt=opt||{};var obj={};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]){try{obj[key]=dec(val)}catch(e){obj[key]=val}}});return obj};var encode=encodeURIComponent;var decode=decodeURIComponent;module.exports.serialize=serialize;module.exports.parse=parse},{}]},{},[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 _rawCookies={};var _cookies={};if(typeof document!=="undefined"){setRawCookie(document.cookie)}function load(name,doNotParse){if(doNotParse){return _rawCookies[name]}return _cookies[name]}function save(name,val,opt){_cookies[name]=val;_rawCookies[name]=val;if(typeof val==="object"){_rawCookies[name]=JSON.stringify(val)}if(typeof document!=="undefined"){document.cookie=cookie.serialize(name,_rawCookies[name],opt)}}function remove(name,path){delete _rawCookies[name];delete _cookies[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}}function setRawCookie(rawCookie){_rawCookies={};_cookies={};if(!rawCookie){return}var rawCookies=cookie.parse(rawCookie);for(var key in rawCookies){_rawCookies[key]=rawCookies[key];try{_cookies[key]=JSON.parse(rawCookies[key])}catch(e){_cookies[key]=rawCookies[key]}}}var reactCookie={load:load,save:save,remove:remove,setRawCookie:setRawCookie};if(typeof window!=="undefined"){window["reactCookie"]=reactCookie}module.exports=reactCookie},{cookie:2}],2:[function(require,module,exports){var serialize=function(name,val,opt){opt=opt||{};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("; ")};var parse=function(str,opt){opt=opt||{};var obj={};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]){try{obj[key]=dec(val)}catch(e){obj[key]=val}}});return obj};var encode=encodeURIComponent;var decode=decodeURIComponent;module.exports.serialize=serialize;module.exports.parse=parse},{}]},{},[1]); |
13
index.js
@@ -33,3 +33,3 @@ var cookie = require('cookie'); | ||
function remove(name) { | ||
function remove(name, path) { | ||
delete _rawCookies[name]; | ||
@@ -39,3 +39,9 @@ delete _cookies[name]; | ||
if (typeof document !== 'undefined') { | ||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
var removeCookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
if (path) { | ||
removeCookie += ' path=' + path; | ||
} | ||
document.cookie = removeCookie; | ||
} | ||
@@ -45,2 +51,5 @@ } | ||
function setRawCookie(rawCookie) { | ||
_rawCookies = {}; | ||
_cookies = {}; | ||
if (!rawCookie) { | ||
@@ -47,0 +56,0 @@ return; |
{ | ||
"name": "react-cookie", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Load and save cookies within your React application", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,3 +83,3 @@ # react-cookie | ||
### `reactCookie.save(name, val, [opt])` | ||
### `reactCookie.remove(name)` | ||
### `reactCookie.remove(name, [path])` | ||
### `reactCookie.setRawCookie(cookies)` | ||
@@ -86,0 +86,0 @@ |
Sorry, the diff of this file is not supported yet
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
12772
190