react-cookie
Advanced tools
Comparing version 0.3.4 to 0.4.0
33
index.js
@@ -44,13 +44,16 @@ var cookie = require('cookie'); | ||
function remove(name, path) { | ||
function remove(name, opt) { | ||
delete _rawCookie[name]; | ||
if (typeof document !== 'undefined') { | ||
var removeCookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
if (path) { | ||
removeCookie += ' path=' + path; | ||
if (typeof opt === 'undefined') { | ||
opt = {}; | ||
} else if (typeof opt === 'string') { | ||
// Will be deprecated in future versions | ||
opt = { path: opt }; | ||
} | ||
document.cookie = removeCookie; | ||
opt.expires = new Date(1970, 1, 1, 0, 0, 1); | ||
document.cookie = cookie.serialize(name, '', opt); | ||
} | ||
@@ -65,12 +68,16 @@ | ||
function setRawCookie(rawCookie) { | ||
_rawCookie = cookie.parse(rawCookie); | ||
if (rawCookie) { | ||
_rawCookie = cookie.parse(rawCookie); | ||
} else { | ||
_rawCookie = {}; | ||
} | ||
} | ||
function plugToRequest(req, res) { | ||
if (req) { | ||
if (req.cookie) { | ||
_rawCookie = req.cookie; | ||
} else if (req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
} | ||
if (req.cookie) { | ||
_rawCookie = req.cookie; | ||
} else if (req.headers && req.headers.cookie) { | ||
setRawCookie(req.headers.cookie); | ||
} else { | ||
_rawCookie = {}; | ||
} | ||
@@ -77,0 +84,0 @@ |
{ | ||
"name": "react-cookie", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Load and save cookies within your React application", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,3 +13,3 @@ # react-cookie | ||
Bower: `bower install react-cookie`<br /> | ||
CDN: `https://cdnjs.cloudflare.com/ajax/libs/react-cookie/0.2.6/react-cookie.min.js` | ||
CDN: `https://cdnjs.cloudflare.com/ajax/libs/react-cookie/0.3.4/react-cookie.min.js` | ||
@@ -88,3 +88,3 @@ # Examples | ||
### `reactCookie.save(name, val, [opt])` | ||
### `reactCookie.remove(name, [path])` | ||
### `reactCookie.remove(name, [opt])` | ||
### `reactCookie.plugToRequest(req, res)` | ||
@@ -91,0 +91,0 @@ ### `reactCookie.setRawCookie(cookies)` |
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
14053
248