js-cookie 3.0.0 → 3.0.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/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 [![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/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
 
package/dist/js.cookie.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! js-cookie v3.0.0 | MIT */
1
+ /*! js-cookie v3.0.1 | MIT */
2
2
  ;
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -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) {
@@ -57,8 +60,6 @@
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,7 +82,8 @@
81
82
  stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
82
83
  }
83
84
 
84
- return (document.cookie = key + '=' + value + stringifiedAttributes)
85
+ return (document.cookie =
86
+ key + '=' + converter.write(value, key) + stringifiedAttributes)
85
87
  }
86
88
 
87
89
  function get (key) {
@@ -97,12 +99,8 @@
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]);
103
+ var foundKey = decodeURIComponent(parts[0]);
106
104
  jar[foundKey] = converter.read(value, foundKey);
107
105
 
108
106
  if (key === foundKey) {
@@ -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.1 | 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,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}return 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:"/"})}));
@@ -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.1 | 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 default t;
@@ -1,4 +1,4 @@
1
- /*! js-cookie v3.0.0 | MIT */
1
+ /*! js-cookie v3.0.1 | 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) {
@@ -46,8 +49,6 @@ function init (converter, defaultAttributes) {
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,7 +71,8 @@ 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
+ key + '=' + converter.write(value, key) + stringifiedAttributes)
74
76
  }
75
77
 
76
78
  function get (key) {
@@ -86,12 +88,8 @@ 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]);
92
+ var foundKey = decodeURIComponent(parts[0]);
95
93
  jar[foundKey] = converter.read(value, foundKey);
96
94
 
97
95
  if (key === foundKey) {
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "js-cookie",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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"