js-cookie 2.1.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -12
- package/SERVER_SIDE.md +3 -3
- package/package.json +15 -12
- package/src/js.cookie.js +75 -63
- package/.jshintignore +0 -2
- package/.jshintrc +0 -14
- package/.npmignore +0 -4
- package/.tm_properties +0 -11
- package/.travis.yml +0 -12
- package/Gruntfile.js +0 -243
- package/MIT-LICENSE.txt +0 -20
- package/bower.json +0 -18
- package/src/.jshintrc +0 -13
- package/test/.jshintrc +0 -16
- package/test/amd-config.js +0 -9
- package/test/amd.html +0 -15
- package/test/amd.js +0 -14
- package/test/encoding.html +0 -18
- package/test/encoding.js +0 -628
- package/test/index.html +0 -18
- package/test/malformed_cookie.html +0 -17
- package/test/missing_semicolon.html +0 -24
- package/test/node.js +0 -29
- package/test/polyfill.js +0 -11
- package/test/tests.js +0 -413
- package/test/utils.js +0 -122
- package/travis.sh +0 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Copyright 2018 Klaus Hartl, Fagner Brack, GitHub Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<img src="https://cloud.githubusercontent.com/assets/835857/14581711/ba623018-0436-11e6-8fce-d2ccd4d379c9.gif">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
# JavaScript Cookie [](https://travis-ci.org/js-cookie/js-cookie) [](https://codeclimate.com/github/js-cookie/js-cookie)
|
|
5
|
+
# JavaScript Cookie [](https://travis-ci.org/js-cookie/js-cookie) [](https://codeclimate.com/github/js-cookie/js-cookie) [](https://www.jsdelivr.com/package/npm/js-cookie)
|
|
6
6
|
|
|
7
7
|
A simple, lightweight JavaScript API for handling cookies
|
|
8
8
|
|
|
@@ -15,12 +15,12 @@ A simple, lightweight JavaScript API for handling cookies
|
|
|
15
15
|
* [RFC 6265](https://tools.ietf.org/html/rfc6265) compliant
|
|
16
16
|
* Useful [Wiki](https://github.com/js-cookie/js-cookie/wiki)
|
|
17
17
|
* Enable [custom encoding/decoding](#converters)
|
|
18
|
-
* **~
|
|
18
|
+
* **~900 bytes** gzipped!
|
|
19
19
|
|
|
20
20
|
**If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.
|
|
21
|
-
[View documentation for the latest release
|
|
21
|
+
[View documentation for the latest release.](https://github.com/js-cookie/js-cookie/tree/latest#readme)**
|
|
22
22
|
|
|
23
|
-
## Build Status Matrix
|
|
23
|
+
## Build Status Matrix ([including active Pull Requests](https://github.com/js-cookie/js-cookie/issues/286))
|
|
24
24
|
|
|
25
25
|
[](https://saucelabs.com/u/js-cookie)
|
|
26
26
|
|
|
@@ -28,12 +28,18 @@ A simple, lightweight JavaScript API for handling cookies
|
|
|
28
28
|
|
|
29
29
|
### Direct download
|
|
30
30
|
|
|
31
|
-
Download the script [here](https://github.com/js-cookie/js-cookie/blob/
|
|
31
|
+
Download the script [here](https://github.com/js-cookie/js-cookie/blob/latest/src/js.cookie.js) and include it (unless you are packaging scripts somehow else):
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
34
|
<script src="/path/to/js.cookie.js"></script>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
Or include it via [jsDelivr CDN](https://www.jsdelivr.com/package/npm/js-cookie):
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
|
|
41
|
+
```
|
|
42
|
+
|
|
37
43
|
**Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked
|
|
38
44
|
in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN.
|
|
39
45
|
|
|
@@ -41,6 +47,11 @@ in Internet Explorer on Windows 7 for instance (because of the wrong MIME type).
|
|
|
41
47
|
|
|
42
48
|
JavaScript Cookie supports [npm](https://www.npmjs.com/package/js-cookie) and [Bower](http://bower.io/search/?q=js-cookie) under the name `js-cookie`.
|
|
43
49
|
|
|
50
|
+
#### NPM
|
|
51
|
+
```
|
|
52
|
+
$ npm install js-cookie --save
|
|
53
|
+
```
|
|
54
|
+
|
|
44
55
|
### Module Loaders
|
|
45
56
|
|
|
46
57
|
JavaScript Cookie can also be loaded as an AMD or CommonJS module.
|
|
@@ -78,6 +89,16 @@ Read all visible cookies:
|
|
|
78
89
|
Cookies.get(); // => { name: 'value' }
|
|
79
90
|
```
|
|
80
91
|
|
|
92
|
+
*Note: It is not possible to read a particular cookie by passing one of the cookie attributes (which may or may not
|
|
93
|
+
have been used when writing the cookie in question):*
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
Cookies.get('foo', { domain: 'sub.example.com' }); // `domain` won't have any effect...!
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The cookie with the name `foo` will only be available on `.get()` if it's visible from where the
|
|
100
|
+
code is called; the domain and/or path attribute will not have an effect when reading.
|
|
101
|
+
|
|
81
102
|
Delete cookie:
|
|
82
103
|
|
|
83
104
|
```javascript
|
|
@@ -92,7 +113,13 @@ Cookies.remove('name'); // fail!
|
|
|
92
113
|
Cookies.remove('name', { path: '' }); // removed!
|
|
93
114
|
```
|
|
94
115
|
|
|
95
|
-
*IMPORTANT!
|
|
116
|
+
*IMPORTANT! When deleting a cookie and you're not relying on the [default attributes](#cookie-attributes), you must pass the exact same path and domain attributes that were used to set the cookie:*
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
Cookies.remove('name', { path: '', domain: '.yourdomain.com' });
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
*Note: Removing a nonexistent cookie does not raise any exception nor return any value.*
|
|
96
123
|
|
|
97
124
|
## Namespace conflicts
|
|
98
125
|
|
|
@@ -142,7 +169,9 @@ Cookies.getJSON(); // => { name: { foo: 'bar' } }
|
|
|
142
169
|
|
|
143
170
|
This project is [RFC 6265](http://tools.ietf.org/html/rfc6265#section-4.1.1) compliant. All special characters that are not allowed in the cookie-name or cookie-value are encoded with each one's UTF-8 Hex equivalent using [percent-encoding](http://en.wikipedia.org/wiki/Percent-encoding).
|
|
144
171
|
The only character in cookie-name or cookie-value that is allowed and still encoded is the percent `%` character, it is escaped in order to interpret percent input as literal.
|
|
145
|
-
To override the default
|
|
172
|
+
Please note that the default encoding/decoding strategy is meant to be interoperable [only between cookies that are read/written by js-cookie](https://github.com/js-cookie/js-cookie/pull/200#discussion_r63270778). To override the default encoding/decoding strategy you need to use a [converter](#converters).
|
|
173
|
+
|
|
174
|
+
*Note: According to [RFC 6265](https://tools.ietf.org/html/rfc6265#section-6.1), your cookies may get deleted if they are too big or there are too many cookies in the same domain, [more details here](https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#why-are-my-cookies-being-deleted).*
|
|
146
175
|
|
|
147
176
|
## Cookie Attributes
|
|
148
177
|
|
|
@@ -152,6 +181,8 @@ Cookie attributes defaults can be set globally by setting properties of the `Coo
|
|
|
152
181
|
|
|
153
182
|
Define when the cookie will be removed. Value can be a [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) which will be interpreted as days from time of creation or a [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance. If omitted, the cookie becomes a session cookie.
|
|
154
183
|
|
|
184
|
+
To create a cookie that expires in less than a day, you can check the [FAQ on the Wiki](https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#expire-cookies-in-less-than-a-day).
|
|
185
|
+
|
|
155
186
|
**Default:** Cookie is removed when the user closes the browser.
|
|
156
187
|
|
|
157
188
|
**Examples:**
|
|
@@ -182,7 +213,9 @@ Cookies.remove('name', { path: '' });
|
|
|
182
213
|
|
|
183
214
|
(From [Internet Explorer Cookie Internals (FAQ)](http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx))
|
|
184
215
|
|
|
185
|
-
This means one cannot set a path using `
|
|
216
|
+
This means one cannot set a path using `window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).
|
|
217
|
+
|
|
218
|
+
In fact, you should never allow untrusted input to set the cookie attributes or you might be exposed to a [XSS attack](https://github.com/js-cookie/js-cookie/issues/396).
|
|
186
219
|
|
|
187
220
|
### domain
|
|
188
221
|
|
|
@@ -220,7 +253,7 @@ Either `true` or `false`, indicating if the cookie transmission requires a secur
|
|
|
220
253
|
```javascript
|
|
221
254
|
Cookies.set('name', 'value', { secure: true });
|
|
222
255
|
Cookies.get('name'); // => 'value'
|
|
223
|
-
Cookies.remove('name'
|
|
256
|
+
Cookies.remove('name');
|
|
224
257
|
```
|
|
225
258
|
|
|
226
259
|
## Converters
|
|
@@ -269,16 +302,22 @@ Check out the [Servers Docs](SERVER_SIDE.md)
|
|
|
269
302
|
|
|
270
303
|
Check out the [Contributing Guidelines](CONTRIBUTING.md)
|
|
271
304
|
|
|
305
|
+
## Security
|
|
306
|
+
|
|
307
|
+
For vulnerability reports, send an e-mail to `jscookieproject at gmail dot com`
|
|
308
|
+
|
|
272
309
|
## Manual release steps
|
|
273
310
|
|
|
274
311
|
* Increment the "version" attribute of `package.json`
|
|
275
312
|
* Increment the version number in the `src/js.cookie.js` file
|
|
313
|
+
* If `major` bump, update jsDelivr CDN major version link on README
|
|
276
314
|
* Commit with the message "Release version x.x.x"
|
|
277
315
|
* Create version tag in git
|
|
278
316
|
* Create a github release and upload the minified file
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
317
|
+
* Change the `latest` tag pointer to the latest commit
|
|
318
|
+
* `git tag -f latest`
|
|
319
|
+
* `git push <remote> :refs/tags/latest`
|
|
320
|
+
* `git push origin master --tags`
|
|
282
321
|
* Release on npm
|
|
283
322
|
|
|
284
323
|
## Authors
|
package/SERVER_SIDE.md
CHANGED
|
@@ -32,7 +32,7 @@ var PHPCookies = Cookies.withConverter({
|
|
|
32
32
|
write: function (value) {
|
|
33
33
|
// Encode all characters according to the "encodeURIComponent" spec
|
|
34
34
|
return encodeURIComponent(value)
|
|
35
|
-
// Revert the characters that are
|
|
35
|
+
// Revert the characters that are unnecessarily encoded but are
|
|
36
36
|
// allowed in a cookie value, except for the plus sign (%2B)
|
|
37
37
|
.replace(/%(23|24|26|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
|
38
38
|
},
|
|
@@ -62,7 +62,7 @@ var TomcatCookies = Cookies.withConverter({
|
|
|
62
62
|
write: function (value) {
|
|
63
63
|
// Encode all characters according to the "encodeURIComponent" spec
|
|
64
64
|
return encodeURIComponent(value)
|
|
65
|
-
// Revert the characters that are
|
|
65
|
+
// Revert the characters that are unnecessarily encoded but are
|
|
66
66
|
// allowed in a cookie value
|
|
67
67
|
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)
|
|
68
68
|
// Encode the parens that are interpreted incorrectly by Tomcat
|
|
@@ -95,7 +95,7 @@ var JBossCookies = Cookies.withConverter({
|
|
|
95
95
|
write: function (value) {
|
|
96
96
|
// Encode all characters according to the "encodeURIComponent" spec
|
|
97
97
|
return encodeURIComponent(value)
|
|
98
|
-
// Revert the characters that are
|
|
98
|
+
// Revert the characters that are unnecessarily encoded but are
|
|
99
99
|
// allowed in a cookie value
|
|
100
100
|
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)
|
|
101
101
|
// Encode again the characters that are not allowed in JBoss 7.1.1, like "[" and "]":
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-cookie",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "A simple, lightweight JavaScript API for handling cookies",
|
|
5
5
|
"main": "src/js.cookie.js",
|
|
6
6
|
"directories": {
|
|
7
7
|
"test": "test"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
|
-
"jquery-plugin",
|
|
11
10
|
"cookie",
|
|
12
11
|
"cookies",
|
|
13
12
|
"browser",
|
|
@@ -24,21 +23,25 @@
|
|
|
24
23
|
"type": "git",
|
|
25
24
|
"url": "git://github.com/js-cookie/js-cookie.git"
|
|
26
25
|
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src/**/*.js",
|
|
28
|
+
"SERVER_SIDE.md",
|
|
29
|
+
"CONTRIBUTING.md"
|
|
30
|
+
],
|
|
27
31
|
"author": "Klaus Hartl",
|
|
28
32
|
"license": "MIT",
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"grunt": "1.0.
|
|
34
|
+
"grunt": "1.0.3",
|
|
31
35
|
"grunt-compare-size": "0.4.2",
|
|
32
|
-
"grunt-contrib-connect": "
|
|
33
|
-
"grunt-contrib-
|
|
34
|
-
"grunt-contrib-
|
|
35
|
-
"grunt-contrib-
|
|
36
|
-
"grunt-contrib-
|
|
37
|
-
"grunt-
|
|
38
|
-
"grunt-
|
|
39
|
-
"grunt-saucelabs": "8.6.2",
|
|
36
|
+
"grunt-contrib-connect": "2.0.0",
|
|
37
|
+
"grunt-contrib-nodeunit": "2.0.0",
|
|
38
|
+
"grunt-contrib-qunit": "2.0.0",
|
|
39
|
+
"grunt-contrib-uglify": "2.3.0",
|
|
40
|
+
"grunt-contrib-watch": "1.1.0",
|
|
41
|
+
"grunt-eslint": "21.0.0",
|
|
42
|
+
"grunt-saucelabs": "9.0.0",
|
|
40
43
|
"gzip-js": "0.3.2",
|
|
41
44
|
"qunitjs": "1.23.1",
|
|
42
|
-
"requirejs": "2.
|
|
45
|
+
"requirejs": "2.3.5"
|
|
43
46
|
}
|
|
44
47
|
}
|
package/src/js.cookie.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* JavaScript Cookie v2.1
|
|
2
|
+
* JavaScript Cookie v2.2.1
|
|
3
3
|
* https://github.com/js-cookie/js-cookie
|
|
4
4
|
*
|
|
5
5
|
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
*/
|
|
8
8
|
;(function (factory) {
|
|
9
|
+
var registeredInModuleLoader;
|
|
9
10
|
if (typeof define === 'function' && define.amd) {
|
|
10
11
|
define(factory);
|
|
11
|
-
|
|
12
|
+
registeredInModuleLoader = true;
|
|
13
|
+
}
|
|
14
|
+
if (typeof exports === 'object') {
|
|
12
15
|
module.exports = factory();
|
|
13
|
-
|
|
16
|
+
registeredInModuleLoader = true;
|
|
17
|
+
}
|
|
18
|
+
if (!registeredInModuleLoader) {
|
|
14
19
|
var OldCookies = window.Cookies;
|
|
15
20
|
var api = window.Cookies = factory();
|
|
16
21
|
api.noConflict = function () {
|
|
@@ -31,117 +36,124 @@
|
|
|
31
36
|
return result;
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
function decode (s) {
|
|
40
|
+
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
function init (converter) {
|
|
35
|
-
function api
|
|
36
|
-
|
|
44
|
+
function api() {}
|
|
45
|
+
|
|
46
|
+
function set (key, value, attributes) {
|
|
37
47
|
if (typeof document === 'undefined') {
|
|
38
48
|
return;
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
|
|
51
|
+
attributes = extend({
|
|
52
|
+
path: '/'
|
|
53
|
+
}, api.defaults, attributes);
|
|
42
54
|
|
|
43
|
-
if (
|
|
44
|
-
attributes =
|
|
45
|
-
|
|
46
|
-
}, api.defaults, attributes);
|
|
55
|
+
if (typeof attributes.expires === 'number') {
|
|
56
|
+
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
|
|
57
|
+
}
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
// We're using "expires" because "max-age" is not supported by IE
|
|
60
|
+
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
var result = JSON.stringify(value);
|
|
64
|
+
if (/^[\{\[]/.test(result)) {
|
|
65
|
+
value = result;
|
|
52
66
|
}
|
|
67
|
+
} catch (e) {}
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
value = converter.write ?
|
|
70
|
+
converter.write(value, key) :
|
|
71
|
+
encodeURIComponent(String(value))
|
|
72
|
+
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
|
73
|
+
|
|
74
|
+
key = encodeURIComponent(String(key))
|
|
75
|
+
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
|
|
76
|
+
.replace(/[\(\)]/g, escape);
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
var stringifiedAttributes = '';
|
|
79
|
+
for (var attributeName in attributes) {
|
|
80
|
+
if (!attributes[attributeName]) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
84
|
+
if (attributes[attributeName] === true) {
|
|
85
|
+
continue;
|
|
66
86
|
}
|
|
67
87
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
attributes.domain && '; domain=' + attributes.domain,
|
|
77
|
-
attributes.secure ? '; secure' : ''
|
|
78
|
-
].join(''));
|
|
88
|
+
// Considers RFC 6265 section 5.2:
|
|
89
|
+
// ...
|
|
90
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
91
|
+
// character:
|
|
92
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
93
|
+
// not including, the first %x3B (";") character.
|
|
94
|
+
// ...
|
|
95
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
79
96
|
}
|
|
80
97
|
|
|
81
|
-
|
|
98
|
+
return (document.cookie = key + '=' + value + stringifiedAttributes);
|
|
99
|
+
}
|
|
82
100
|
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
function get (key, json) {
|
|
102
|
+
if (typeof document === 'undefined') {
|
|
103
|
+
return;
|
|
85
104
|
}
|
|
86
105
|
|
|
106
|
+
var jar = {};
|
|
87
107
|
// To prevent the for loop in the first place assign an empty array
|
|
88
|
-
// in case there are no cookies at all.
|
|
89
|
-
// calling "get()"
|
|
108
|
+
// in case there are no cookies at all.
|
|
90
109
|
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
91
|
-
var rdecode = /(%[0-9A-Z]{2})+/g;
|
|
92
110
|
var i = 0;
|
|
93
111
|
|
|
94
112
|
for (; i < cookies.length; i++) {
|
|
95
113
|
var parts = cookies[i].split('=');
|
|
96
114
|
var cookie = parts.slice(1).join('=');
|
|
97
115
|
|
|
98
|
-
if (cookie.charAt(0) === '"') {
|
|
116
|
+
if (!json && cookie.charAt(0) === '"') {
|
|
99
117
|
cookie = cookie.slice(1, -1);
|
|
100
118
|
}
|
|
101
119
|
|
|
102
120
|
try {
|
|
103
|
-
var name = parts[0]
|
|
104
|
-
cookie = converter.read
|
|
105
|
-
|
|
106
|
-
cookie.replace(rdecode, decodeURIComponent);
|
|
121
|
+
var name = decode(parts[0]);
|
|
122
|
+
cookie = (converter.read || converter)(cookie, name) ||
|
|
123
|
+
decode(cookie);
|
|
107
124
|
|
|
108
|
-
if (
|
|
125
|
+
if (json) {
|
|
109
126
|
try {
|
|
110
127
|
cookie = JSON.parse(cookie);
|
|
111
128
|
} catch (e) {}
|
|
112
129
|
}
|
|
113
130
|
|
|
131
|
+
jar[name] = cookie;
|
|
132
|
+
|
|
114
133
|
if (key === name) {
|
|
115
|
-
result = cookie;
|
|
116
134
|
break;
|
|
117
135
|
}
|
|
118
|
-
|
|
119
|
-
if (!key) {
|
|
120
|
-
result[name] = cookie;
|
|
121
|
-
}
|
|
122
136
|
} catch (e) {}
|
|
123
137
|
}
|
|
124
138
|
|
|
125
|
-
return
|
|
139
|
+
return key ? jar[key] : jar;
|
|
126
140
|
}
|
|
127
141
|
|
|
128
|
-
api.set =
|
|
142
|
+
api.set = set;
|
|
129
143
|
api.get = function (key) {
|
|
130
|
-
return
|
|
144
|
+
return get(key, false /* read as raw */);
|
|
131
145
|
};
|
|
132
|
-
api.getJSON = function () {
|
|
133
|
-
return
|
|
134
|
-
json: true
|
|
135
|
-
}, [].slice.call(arguments));
|
|
146
|
+
api.getJSON = function (key) {
|
|
147
|
+
return get(key, true /* read as json */);
|
|
136
148
|
};
|
|
137
|
-
api.defaults = {};
|
|
138
|
-
|
|
139
149
|
api.remove = function (key, attributes) {
|
|
140
|
-
|
|
150
|
+
set(key, '', extend(attributes, {
|
|
141
151
|
expires: -1
|
|
142
152
|
}));
|
|
143
153
|
};
|
|
144
154
|
|
|
155
|
+
api.defaults = {};
|
|
156
|
+
|
|
145
157
|
api.withConverter = init;
|
|
146
158
|
|
|
147
159
|
return api;
|
package/.jshintignore
DELETED
package/.jshintrc
DELETED
package/.npmignore
DELETED
package/.tm_properties
DELETED
package/.travis.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- '5.1.1'
|
|
4
|
-
# Only use grunt-ci for commits pushed to this repo. Fall back to regular test
|
|
5
|
-
# for pull requests (as secure variables won't be exposed there).
|
|
6
|
-
script:
|
|
7
|
-
- ./travis.sh
|
|
8
|
-
env:
|
|
9
|
-
# Encrypted SAUCE_USERNAME and SAUCE_ACCESS_KEY used by travis
|
|
10
|
-
global:
|
|
11
|
-
- secure: IkMOa/8r4sWyzUMxecsfqoPzZyIqVAMwPkQ6/HxXPbT8X7UnvqAdaicAMeHEKtOnOac+rx6pGB9HQvC8P/ZzkEBtsKLP4nEh9vsAInZvb3pXg+qbIgIK6/19X0kU4UkpDqVdWmBuFTamJvMDMstUTgEaM3869bB5vGp9taBgfVo=
|
|
12
|
-
- secure: DKrQplF0CBiBh+cbQ8D7EKebCeklUWEELblIJdU4475Occ4G9b8ZFYO9HFwl1B8F/XapB7CsMyxbJCWor030FySeqn8bhJs9NoAVoYGg+MtWniv1EOHuZLWuOGfgQDv7qj5U0Af9Y655MmUpXSN2aDlCmQweWnYdpFTM9Dfsdd8=
|