js-cookie 3.0.0 → 3.0.2

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/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 [![Build Status](https://travis-ci.com/js-cookie/js-cookie.svg?branch=master)](https://travis-ci.com/js-cookie/js-cookie) [![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?badge_key=b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2)](https://www.browserstack.com/automate/public-build/b3VDaHAxVDg0NDdCRmtUOWg0SlQzK2NsRVhWTjlDQS9qdGJoak1GMzJiVT0tLVhwZHNvdGRoY284YVRrRnI3eU1JTnc9PQ==--5e88ffb3ca116001d7ef2cfb97a4128ac31174c2) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Code Climate](https://codeclimate.com/github/js-cookie/js-cookie.svg)](https://codeclimate.com/github/js-cookie/js-cookie) [![npm](https://img.shields.io/github/package-json/v/js-cookie/js-cookie)](https://www.npmjs.com/package/js-cookie) [![size](https://img.shields.io/bundlephobia/minzip/js-cookie/rc)](https://www.npmjs.com/package/js-cookie) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/js-cookie/badge?style=rounded)](https://www.jsdelivr.com/package/npm/js-cookie)
5
+ # JavaScript Cookie [![CI](https://github.com/js-cookie/js-cookie/actions/workflows/ci.yml/badge.svg)](https://github.com/js-cookie/js-cookie/actions/workflows/ci.yml) [![BrowserStack](https://github.com/js-cookie/js-cookie/actions/workflows/browserstack.yml/badge.svg)](https://github.com/js-cookie/js-cookie/actions/workflows/browserstack.yml) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Code Climate](https://codeclimate.com/github/js-cookie/js-cookie.svg)](https://codeclimate.com/github/js-cookie/js-cookie) [![npm](https://img.shields.io/github/package-json/v/js-cookie/js-cookie)](https://www.npmjs.com/package/js-cookie) [![size](https://img.shields.io/bundlephobia/minzip/js-cookie/3)](https://www.npmjs.com/package/js-cookie) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/js-cookie/badge?style=rounded)](https://www.jsdelivr.com/package/npm/js-cookie)
6
6
 
7
7
  A simple, lightweight JavaScript API for handling cookies
8
8
 
@@ -17,7 +17,7 @@ A simple, lightweight JavaScript API for handling cookies
17
17
  - Enable [custom encoding/decoding](#converters)
18
18
  - **< 800 bytes** gzipped!
19
19
 
20
- **👉👉 If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.
20
+ **👉👉 If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the main branch.
21
21
  [View documentation for the latest release.](https://github.com/js-cookie/js-cookie/tree/latest#readme) 👈👈**
22
22
 
23
23
  ## Installation
@@ -26,8 +26,8 @@ A simple, lightweight JavaScript API for handling cookies
26
26
 
27
27
  JavaScript Cookie supports [npm](https://www.npmjs.com/package/js-cookie) under the name `js-cookie`.
28
28
 
29
- ```
30
- $ npm i js-cookie
29
+ ```bash
30
+ npm i js-cookie
31
31
  ```
32
32
 
33
33
  The npm package has a `module` field pointing to an ES module variant of the library, mainly to provide support for ES module aware bundlers, whereas its `browser` field points to an UMD module for full backward compatibility.
@@ -301,8 +301,8 @@ Cookies.withConverter({
301
301
 
302
302
  ## TypeScript declarations
303
303
 
304
- ```
305
- $ npm i @types/js-cookie
304
+ ```bash
305
+ npm i @types/js-cookie
306
306
  ```
307
307
 
308
308
  ## Server-side integration
@@ -319,19 +319,7 @@ For vulnerability reports, send an e-mail to `js-cookie at googlegroups dot com`
319
319
 
320
320
  ## Releasing
321
321
 
322
- We are using [release-it](https://www.npmjs.com/package/release-it) for automated releasing.
323
-
324
- Start a dry run to see what would happen:
325
-
326
- ```
327
- $ npm run release minor -- --dry-run
328
- ```
329
-
330
- Do a real release (publishes both to npm as well as create a new release on GitHub):
331
-
332
- ```
333
- $ npm run release minor
334
- ```
322
+ For releasing there's the `Release` GitHub Actions workflow, which will create a new release along with package provenance on npmjs.com.
335
323
 
336
324
  _GitHub releases are created as a draft and need to be published manually!
337
325
  (This is so we are able to craft suitable release notes before publishing.)_
package/dist/js.cookie.js CHANGED
@@ -1,14 +1,14 @@
1
- /*! js-cookie v3.0.0 | MIT */
1
+ /*! js-cookie v3.0.2 | MIT */
2
2
  ;
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
5
5
  typeof define === 'function' && define.amd ? define(factory) :
6
- (global = global || self, (function () {
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () {
7
7
  var current = global.Cookies;
8
8
  var exports = global.Cookies = factory();
9
9
  exports.noConflict = function () { global.Cookies = current; return exports; };
10
- }()));
11
- }(this, (function () { 'use strict';
10
+ })());
11
+ })(this, (function () { 'use strict';
12
12
 
13
13
  /* eslint-disable no-var */
14
14
  function assign (target) {
@@ -25,6 +25,9 @@
25
25
  /* eslint-disable no-var */
26
26
  var defaultConverter = {
27
27
  read: function (value) {
28
+ if (value[0] === '"') {
29
+ value = value.slice(1, -1);
30
+ }
28
31
  return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
29
32
  },
30
33
  write: function (value) {
@@ -39,7 +42,7 @@
39
42
  /* eslint-disable no-var */
40
43
 
41
44
  function init (converter, defaultAttributes) {
42
- function set (key, value, attributes) {
45
+ function set (name, value, attributes) {
43
46
  if (typeof document === 'undefined') {
44
47
  return
45
48
  }
@@ -53,12 +56,10 @@
53
56
  attributes.expires = attributes.expires.toUTCString();
54
57
  }
55
58
 
56
- key = encodeURIComponent(key)
59
+ name = encodeURIComponent(name)
57
60
  .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
58
61
  .replace(/[()]/g, escape);
59
62
 
60
- value = converter.write(value, key);
61
-
62
63
  var stringifiedAttributes = '';
63
64
  for (var attributeName in attributes) {
64
65
  if (!attributes[attributeName]) {
@@ -81,11 +82,12 @@
81
82
  stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
82
83
  }
83
84
 
84
- return (document.cookie = key + '=' + value + stringifiedAttributes)
85
+ return (document.cookie =
86
+ name + '=' + converter.write(value, name) + stringifiedAttributes)
85
87
  }
86
88
 
87
- function get (key) {
88
- if (typeof document === 'undefined' || (arguments.length && !key)) {
89
+ function get (name) {
90
+ if (typeof document === 'undefined' || (arguments.length && !name)) {
89
91
  return
90
92
  }
91
93
 
@@ -97,30 +99,26 @@
97
99
  var parts = cookies[i].split('=');
98
100
  var value = parts.slice(1).join('=');
99
101
 
100
- if (value[0] === '"') {
101
- value = value.slice(1, -1);
102
- }
103
-
104
102
  try {
105
- var foundKey = defaultConverter.read(parts[0]);
106
- jar[foundKey] = converter.read(value, foundKey);
103
+ var found = decodeURIComponent(parts[0]);
104
+ jar[found] = converter.read(value, found);
107
105
 
108
- if (key === foundKey) {
106
+ if (name === found) {
109
107
  break
110
108
  }
111
109
  } catch (e) {}
112
110
  }
113
111
 
114
- return key ? jar[key] : jar
112
+ return name ? jar[name] : jar
115
113
  }
116
114
 
117
115
  return Object.create(
118
116
  {
119
- set: set,
120
- get: get,
121
- remove: function (key, attributes) {
117
+ set,
118
+ get,
119
+ remove: function (name, attributes) {
122
120
  set(
123
- key,
121
+ name,
124
122
  '',
125
123
  assign({}, attributes, {
126
124
  expires: -1
@@ -146,4 +144,4 @@
146
144
 
147
145
  return api;
148
146
 
149
- })));
147
+ }));
@@ -1,2 +1,2 @@
1
- /*! js-cookie v3.0.0 | MIT */
2
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,r=e.Cookies=t();r.noConflict=function(){return e.Cookies=n,r}}())}(this,(function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var t={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};return function n(r,o){function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),n=r.write(n,t);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var c=n[i].split("="),u=c.slice(1).join("=");'"'===u[0]&&(u=u.slice(1,-1));try{var f=t.read(c[0]);if(o[f]=r.read(u,f),e===f)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){i(t,"",e({},n,{expires:-1}))},withAttributes:function(t){return n(this.converter,e({},this.attributes,t))},withConverter:function(t){return n(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(r)}})}(t,{path:"/"})}));
1
+ /*! js-cookie v3.0.2 | MIT */
2
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,(function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var t=function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(r,t)+c}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(o[u]=n.read(c,u),e===u)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){r(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});return t}));
@@ -1,2 +1,2 @@
1
- /*! js-cookie v3.0.0 | MIT */
2
- function e(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var t={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};var r=function r(n,o){function i(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),r=n.write(r,t);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+r+c}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],o={},i=0;i<r.length;i++){var c=r[i].split("="),u=c.slice(1).join("=");'"'===u[0]&&(u=u.slice(1,-1));try{var a=t.read(c[0]);if(o[a]=n.read(u,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(t,r){i(t,"",e({},r,{expires:-1}))},withAttributes:function(t){return r(this.converter,e({},this.attributes,t))},withConverter:function(t){return r(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}(t,{path:"/"});export default r;
1
+ /*! js-cookie v3.0.2 | MIT */
2
+ function e(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var t=function t(r,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=e({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+r.write(o,t)+c}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],n={},o=0;o<t.length;o++){var i=t[o].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(n[u]=r.read(c,u),e===u)break}catch(e){}}return e?n[e]:n}},remove:function(t,r){o(t,"",e({},r,{expires:-1}))},withAttributes:function(r){return t(this.converter,e({},this.attributes,r))},withConverter:function(r){return t(e({},this.converter,r),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(r)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});export{t as default};
@@ -1,4 +1,4 @@
1
- /*! js-cookie v3.0.0 | MIT */
1
+ /*! js-cookie v3.0.2 | MIT */
2
2
  /* eslint-disable no-var */
3
3
  function assign (target) {
4
4
  for (var i = 1; i < arguments.length; i++) {
@@ -14,6 +14,9 @@ function assign (target) {
14
14
  /* eslint-disable no-var */
15
15
  var defaultConverter = {
16
16
  read: function (value) {
17
+ if (value[0] === '"') {
18
+ value = value.slice(1, -1);
19
+ }
17
20
  return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
18
21
  },
19
22
  write: function (value) {
@@ -28,7 +31,7 @@ var defaultConverter = {
28
31
  /* eslint-disable no-var */
29
32
 
30
33
  function init (converter, defaultAttributes) {
31
- function set (key, value, attributes) {
34
+ function set (name, value, attributes) {
32
35
  if (typeof document === 'undefined') {
33
36
  return
34
37
  }
@@ -42,12 +45,10 @@ function init (converter, defaultAttributes) {
42
45
  attributes.expires = attributes.expires.toUTCString();
43
46
  }
44
47
 
45
- key = encodeURIComponent(key)
48
+ name = encodeURIComponent(name)
46
49
  .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
47
50
  .replace(/[()]/g, escape);
48
51
 
49
- value = converter.write(value, key);
50
-
51
52
  var stringifiedAttributes = '';
52
53
  for (var attributeName in attributes) {
53
54
  if (!attributes[attributeName]) {
@@ -70,11 +71,12 @@ function init (converter, defaultAttributes) {
70
71
  stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
71
72
  }
72
73
 
73
- return (document.cookie = key + '=' + value + stringifiedAttributes)
74
+ return (document.cookie =
75
+ name + '=' + converter.write(value, name) + stringifiedAttributes)
74
76
  }
75
77
 
76
- function get (key) {
77
- if (typeof document === 'undefined' || (arguments.length && !key)) {
78
+ function get (name) {
79
+ if (typeof document === 'undefined' || (arguments.length && !name)) {
78
80
  return
79
81
  }
80
82
 
@@ -86,30 +88,26 @@ function init (converter, defaultAttributes) {
86
88
  var parts = cookies[i].split('=');
87
89
  var value = parts.slice(1).join('=');
88
90
 
89
- if (value[0] === '"') {
90
- value = value.slice(1, -1);
91
- }
92
-
93
91
  try {
94
- var foundKey = defaultConverter.read(parts[0]);
95
- jar[foundKey] = converter.read(value, foundKey);
92
+ var found = decodeURIComponent(parts[0]);
93
+ jar[found] = converter.read(value, found);
96
94
 
97
- if (key === foundKey) {
95
+ if (name === found) {
98
96
  break
99
97
  }
100
98
  } catch (e) {}
101
99
  }
102
100
 
103
- return key ? jar[key] : jar
101
+ return name ? jar[name] : jar
104
102
  }
105
103
 
106
104
  return Object.create(
107
105
  {
108
- set: set,
109
- get: get,
110
- remove: function (key, attributes) {
106
+ set,
107
+ get,
108
+ remove: function (name, attributes) {
111
109
  set(
112
- key,
110
+ name,
113
111
  '',
114
112
  assign({}, attributes, {
115
113
  expires: -1
@@ -133,4 +131,4 @@ function init (converter, defaultAttributes) {
133
131
  var api = init(defaultConverter, { path: '/' });
134
132
  /* eslint-enable no-var */
135
133
 
136
- export default api;
134
+ export { api as default };
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "js-cookie",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A simple, lightweight JavaScript API for handling cookies",
5
5
  "browser": "dist/js.cookie.js",
6
6
  "module": "dist/js.cookie.mjs",
7
7
  "unpkg": "dist/js.cookie.min.js",
8
8
  "jsdelivr": "dist/js.cookie.min.js",
9
9
  "exports": {
10
- "import": "./dist/js.cookie.mjs",
11
- "require": "./dist/js.cookie.js"
10
+ ".": {
11
+ "import": "./dist/js.cookie.mjs",
12
+ "require": "./dist/js.cookie.js"
13
+ },
14
+ "./package.json": "./package.json"
12
15
  },
13
16
  "directories": {
14
17
  "test": "test"
@@ -40,30 +43,30 @@
40
43
  "author": "Klaus Hartl",
41
44
  "license": "MIT",
42
45
  "devDependencies": {
43
- "browserstack-runner": "^0.9.0",
46
+ "@rollup/plugin-terser": "^0.4.0",
47
+ "browserstack-runner": "github:browserstack/browserstack-runner#1e85e559951bdf97ffe2a7c744ee67ca83589fde",
44
48
  "eslint": "^7.31.0",
45
49
  "eslint-config-standard": "^16.0.3",
46
- "eslint-plugin-promise": "^5.1.0",
47
- "eslint-plugin-html": "^6.0.0",
48
- "eslint-plugin-markdown": "^2.2.0",
50
+ "eslint-plugin-html": "^7.0.0",
51
+ "eslint-plugin-markdown": "^3.0.0",
49
52
  "grunt": "^1.0.4",
50
53
  "grunt-compare-size": "^0.4.2",
51
54
  "grunt-contrib-connect": "^3.0.0",
52
- "grunt-contrib-nodeunit": "^3.0.0",
53
- "grunt-contrib-qunit": "^3.1.0",
55
+ "grunt-contrib-nodeunit": "^5.0.0",
56
+ "grunt-contrib-qunit": "^7.0.0",
54
57
  "grunt-contrib-watch": "^1.1.0",
55
58
  "grunt-exec": "^3.0.0",
56
59
  "gzip-js": "^0.3.2",
57
60
  "prettier": "^2.3.2",
58
61
  "qunit": "^2.9.3",
59
- "release-it": "^14.10.0",
60
- "rollup": "^2.0.0",
61
- "rollup-plugin-filesize": "^9.1.1",
62
- "rollup-plugin-license": "^2.5.0",
63
- "rollup-plugin-terser": "^7.0.2",
64
- "standard": "^16.0.3"
62
+ "release-it": "^15.0.0",
63
+ "rollup": "^3.17.2",
64
+ "rollup-plugin-filesize": "^10.0.0",
65
+ "rollup-plugin-license": "^3.0.0",
66
+ "standard": "^17.0.0"
65
67
  },
66
68
  "engines": {
67
- "node": ">=12"
69
+ "node": ">=14",
70
+ "npm": ">=9.5.0"
68
71
  }
69
72
  }