browser-cookies
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "browser-cookies", | ||
"description": "Tiny cookies library for the browser", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "src/browser-cookies.js", | ||
"files": [ | ||
"src/browser-cookies.js", | ||
"src/browser-cookies.d.ts", | ||
"README.md", | ||
@@ -13,17 +14,17 @@ "LICENCE" | ||
"devDependencies": { | ||
"browserify": "13.1.1", | ||
"concurrently": "3.1.0", | ||
"coveralls": "2.11.15", | ||
"browserify": "14.5.0", | ||
"concurrently": "3.5.1", | ||
"coveralls": "3.0.0", | ||
"gulp": "git://github.com/gulpjs/gulp.git#4.0", | ||
"gulp-rename": "1.2.2", | ||
"gulp-size": "2.1.0", | ||
"gulp-uglify": "2.0.0", | ||
"gulp-uglify": "3.0.0", | ||
"gulp-wrap": "0.13.0", | ||
"karma": "1.3.0", | ||
"karma": "2.0.0", | ||
"karma-coverage": "1.1.1", | ||
"karma-jasmine": "0.1.6", | ||
"karma-phantomjs-launcher": "1.0.2", | ||
"karma-spec-reporter": "0.0.26", | ||
"phantomjs-prebuilt": "2.1.14", | ||
"watchify": "3.8.0", | ||
"karma-phantomjs-launcher": "1.0.4", | ||
"karma-spec-reporter": "0.0.32", | ||
"phantomjs-prebuilt": "2.1.16", | ||
"watchify": "3.9.0", | ||
"zuul": "3.11.1", | ||
@@ -36,4 +37,6 @@ "zuul-ngrok": "4.0.0" | ||
"test:full": "concurrently \"node ./node_modules/gulp/bin/gulp.js build\" \"node ./node_modules/zuul/bin/zuul -- test/*.js\"", | ||
"test": "concurrently \"node ./node_modules/gulp/bin/gulp.js coverage\" \"node ./node_modules/zuul/bin/zuul -- test/*.js\"" | ||
}, | ||
"test:travis_saucelabs": "node ./node_modules/gulp/bin/gulp.js coverage && node ./node_modules/zuul/bin/zuul -- test/*.js", | ||
"test": "if [ -z \"$SAUCE_ACCESS_KEY\" ]; then npm run test:local; else npm run test:travis_saucelabs; fi" | ||
}, | ||
"types": "./src/browser-cookies.d.ts", | ||
"author": { | ||
@@ -40,0 +43,0 @@ "name": "Voltace", |
@@ -58,4 +58,4 @@ <img width="425" height="200" src="https://raw.githubusercontent.com/voltace/browser-cookies/master/browser-cookies.png"/> | ||
- method [cookies.get(`name`)](#cookies-get) | ||
- method [cookies.erase(`name`, [, `options`])](#cookies-erase) | ||
- method [cookies.all()](#cookies-all) | ||
- method [cookies.erase(`name`, [, `options`])](#cookies-erase) | ||
- property [cookies.defaults](#cookies-defaults) | ||
@@ -86,9 +86,2 @@ | ||
<hr/><a name="cookies-all"></a> | ||
[cookies.all()](#cookies-all) | ||
<br/> | ||
Method to get all cookies. | ||
Returns an object containing all cookie values with the cookie names used as keys. Percent encoded names and values will automatically be decoded. | ||
<hr/><a name="cookies-erase"></a> | ||
@@ -105,3 +98,9 @@ | ||
<hr/><a name="cookies-all"></a> | ||
[cookies.all()](#cookies-all) | ||
<br/> | ||
Method to get all cookies. | ||
Returns an object containing all cookie values with the cookie names used as keys. Percent encoded names and values will automatically be decoded. | ||
<hr/><a name="cookies-defaults"></a> | ||
@@ -115,3 +114,3 @@ | ||
### Options | ||
The options shown in the table below may be set globally using [cookies.defaults](#cookies-defaults) or passed as function argument to [cookies.set()](#cookies-set) and [cookies.get()](#cookies-get). Also check out the [Examples](#examples) further below. | ||
The options shown in the table below may be set globally using [cookies.defaults](#cookies-defaults) or passed as function argument to [cookies.set()](#cookies-set) and [cookies.erase()](#cookies-erase). Also check out the [Examples](#examples) further below. | ||
@@ -125,2 +124,3 @@ | Name | Type | Default | Description | ||
| `httponly` | `Boolean` | `false` | If true the cookie may only be read by the web server.<ul><li> This option may be set to [prevent malicious scripts from accessing cookies][ref-httponly], not all browsers support this feature yet.</li></ul> | ||
| `samesite` | `String` | `""` | The `samesite` argument may be used to [prevent cookies from being sent along with cross-site requests][ref-samesite].<ul><li>If set to `""` the SameSite feature will not be used.</li><li>If set to `"Strict"` the cookie will only be sent along with "same-site" requests.</li><li>If set to `"Lax"` the cookie will be sent with "same-site" requests and with "cross-site" top-level navigations.</li></ul>This is an experimental feature as only [a few browsers support SameSite][ref-samesite-caniuse] and [the standard][ref-samesite-spec] has not been finalized yet. Don't use this feature in production environments. | ||
@@ -207,3 +207,3 @@ ### Examples | ||
Feel free to add an issue on GitHub for any questions, bug or feature request you may have. | ||
Feel free to submit an issue on GitHub for any question, bug or feature requesst you may have. | ||
@@ -224,2 +224,5 @@ ### License | ||
[ref-unittests]: https://rawgit.com/voltace/browser-cookies/master/test/index.html | ||
[ref-samesite]: http://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/ | ||
[ref-samesite-caniuse]: http://caniuse.com/#feat=same-site-cookie-attribute | ||
[ref-samesite-spec]: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 | ||
@@ -226,0 +229,0 @@ [npm-url]: https://npmjs.org/package/browser-cookies |
@@ -14,2 +14,3 @@ exports.defaults = {}; | ||
var httponly = opts.httponly !== undefined ? opts.httponly : defaults.httponly; | ||
var samesite = opts.samesite !== undefined ? opts.samesite : defaults.samesite; | ||
@@ -23,3 +24,3 @@ // Determine cookie expiration date | ||
expires | ||
) : ''; | ||
) : 0; | ||
@@ -32,6 +33,7 @@ // Set cookie | ||
(expDate && expDate.getTime() >= 0 ? ';expires=' + expDate.toUTCString() : '') + // Add expiration date | ||
(domain ? ';domain=' + domain : '') + // Add domain | ||
(path ? ';path=' + path : '') + // Add path | ||
(secure ? ';secure' : '') + // Add secure option | ||
(httponly ? ';httponly' : ''); // Add httponly option | ||
(domain ? ';domain=' + domain : '') + // Add domain | ||
(path ? ';path=' + path : '') + // Add path | ||
(secure ? ';secure' : '') + // Add secure option | ||
(httponly ? ';httponly' : '') + // Add httponly option | ||
(samesite ? ';samesite=' + samesite : ''); // Add samesite option | ||
}; | ||
@@ -41,7 +43,6 @@ | ||
var cookies = document.cookie.split(';'); | ||
// Iterate all cookies | ||
for(var i = 0; i < cookies.length; i++) { | ||
var cookie = cookies[i]; | ||
var cookieLength = cookie.length; | ||
while(cookies.length) { | ||
var cookie = cookies.pop(); | ||
@@ -52,9 +53,9 @@ // Determine separator index ("name=value") | ||
// IE<11 emits the equal sign when the cookie value is empty | ||
separatorIndex = separatorIndex < 0 ? cookieLength : separatorIndex; | ||
separatorIndex = separatorIndex < 0 ? cookie.length : separatorIndex; | ||
var cookie_name = decodeURIComponent(cookie.substring(0, separatorIndex).replace(/^\s+/, '')); | ||
var cookie_name = decodeURIComponent(cookie.slice(0, separatorIndex).replace(/^\s+/, '')); | ||
// Return cookie value if the name matches | ||
if (cookie_name === name) { | ||
return decodeURIComponent(cookie.substring(separatorIndex + 1, cookieLength)); | ||
return decodeURIComponent(cookie.slice(separatorIndex + 1)); | ||
} | ||
@@ -82,18 +83,17 @@ } | ||
// Iterate all cookies | ||
for(var i = 0; i < cookies.length; i++) { | ||
var cookie = cookies[i]; | ||
var cookieLength = cookie.length; | ||
while(cookies.length) { | ||
var cookie = cookies.pop(); | ||
// Determine separator index ("name=value") | ||
var separatorIndex = cookie.indexOf('='); | ||
// Determine separator index ("name=value") | ||
var separatorIndex = cookie.indexOf('='); | ||
// IE<11 emits the equal sign when the cookie value is empty | ||
separatorIndex = separatorIndex < 0 ? cookieLength : separatorIndex; | ||
// IE<11 emits the equal sign when the cookie value is empty | ||
separatorIndex = separatorIndex < 0 ? cookie.length : separatorIndex; | ||
// add the cookie name and value to the `all` object | ||
var cookie_name = decodeURIComponent(cookie.substring(0, separatorIndex).replace(/^\s+/, '')); | ||
all[cookie_name] = decodeURIComponent(cookie.substring(separatorIndex + 1, cookieLength)); | ||
} | ||
var cookie_name = decodeURIComponent(cookie.slice(0, separatorIndex).replace(/^\s+/, '')); | ||
all[cookie_name] = decodeURIComponent(cookie.slice(separatorIndex + 1)); | ||
} | ||
return all; | ||
}; |
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
18121
5
88
234