tiny-cookie
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -0,1 +1,5 @@ | ||
### v2.3.1 | ||
- **Fix**: Fix path option is ignored when removeCookie is called #27 | ||
### v2.3.0 | ||
@@ -2,0 +6,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.Cookie = global.Cookie || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.Cookie = {})); | ||
}(this, function (exports) { 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function hasOwn(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
// Escape special characters. | ||
function escapeRe(str) { | ||
return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | ||
} | ||
return target; | ||
}; | ||
// Return a future date by the given string. | ||
function computeExpires(str) { | ||
var lastCh = str.charAt(str.length - 1); | ||
var value = parseInt(str, 10); | ||
var expires = new Date(); | ||
switch (lastCh) { | ||
case 'Y': | ||
expires.setFullYear(expires.getFullYear() + value);break; | ||
case 'M': | ||
expires.setMonth(expires.getMonth() + value);break; | ||
case 'D': | ||
expires.setDate(expires.getDate() + value);break; | ||
case 'h': | ||
expires.setHours(expires.getHours() + value);break; | ||
case 'm': | ||
expires.setMinutes(expires.getMinutes() + value);break; | ||
case 's': | ||
expires.setSeconds(expires.getSeconds() + value);break; | ||
default: | ||
expires = new Date(str); | ||
return _extends.apply(this, arguments); | ||
} | ||
return expires; | ||
} | ||
function hasOwn(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} // Escape special characters. | ||
// Convert an object to a cookie option string. | ||
function convert(opts) { | ||
var res = ''; | ||
// eslint-disable-next-line | ||
for (var key in opts) { | ||
if (hasOwn(opts, key)) { | ||
if (/^expires$/i.test(key)) { | ||
var expires = opts[key]; | ||
function escapeRe(str) { | ||
return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | ||
} // Return a future date by the given string. | ||
if ((typeof expires === 'undefined' ? 'undefined' : _typeof(expires)) !== 'object') { | ||
expires += typeof expires === 'number' ? 'D' : ''; | ||
expires = computeExpires(expires); | ||
function computeExpires(str) { | ||
var lastCh = str.charAt(str.length - 1); | ||
var value = parseInt(str, 10); | ||
var expires = new Date(); | ||
switch (lastCh) { | ||
case 'Y': | ||
expires.setFullYear(expires.getFullYear() + value); | ||
break; | ||
case 'M': | ||
expires.setMonth(expires.getMonth() + value); | ||
break; | ||
case 'D': | ||
expires.setDate(expires.getDate() + value); | ||
break; | ||
case 'h': | ||
expires.setHours(expires.getHours() + value); | ||
break; | ||
case 'm': | ||
expires.setMinutes(expires.getMinutes() + value); | ||
break; | ||
case 's': | ||
expires.setSeconds(expires.getSeconds() + value); | ||
break; | ||
default: | ||
expires = new Date(str); | ||
} | ||
return expires; | ||
} // Convert an object to a cookie option string. | ||
function convert(opts) { | ||
var res = ''; // eslint-disable-next-line | ||
for (var key in opts) { | ||
if (hasOwn(opts, key)) { | ||
if (/^expires$/i.test(key)) { | ||
var expires = opts[key]; | ||
if (typeof expires !== 'object') { | ||
expires += typeof expires === 'number' ? 'D' : ''; | ||
expires = computeExpires(expires); | ||
} | ||
res += ";" + key + "=" + expires.toUTCString(); | ||
} else if (/^secure$/.test(key)) { | ||
if (opts[key]) { | ||
res += ";" + key; | ||
} | ||
} else { | ||
res += ";" + key + "=" + opts[key]; | ||
} | ||
res += ';' + key + '=' + expires.toUTCString(); | ||
} else if (/^secure$/.test(key)) { | ||
if (opts[key]) { | ||
res += ';' + key; | ||
} | ||
} else { | ||
res += ';' + key + '=' + opts[key]; | ||
} | ||
} | ||
} | ||
if (!hasOwn(opts, 'path')) { | ||
res += ';path=/'; | ||
if (!hasOwn(opts, 'path')) { | ||
res += ';path=/'; | ||
} | ||
return res; | ||
} | ||
return res; | ||
} | ||
function isEnabled() { | ||
var key = '@key@'; | ||
var value = '1'; | ||
var re = new RegExp("(?:^|; )" + key + "=" + value + "(?:;|$)"); | ||
document.cookie = key + "=" + value; | ||
var enabled = re.test(document.cookie); | ||
// Check if the browser cookie is enabled. | ||
function isEnabled() { | ||
var key = '@key@'; | ||
var value = '1'; | ||
var re = new RegExp('(?:^|; )' + key + '=' + value + '(?:;|$)'); | ||
if (enabled) { | ||
// eslint-disable-next-line | ||
remove(key); | ||
} | ||
document.cookie = key + '=' + value; | ||
return enabled; | ||
} // Get the cookie value by key. | ||
var enabled = re.test(document.cookie); | ||
if (enabled) { | ||
// eslint-disable-next-line | ||
remove(key); | ||
} | ||
function get(key, decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
return enabled; | ||
} | ||
if (typeof key !== 'string' || !key) { | ||
return null; | ||
} | ||
// Get the cookie value by key. | ||
function get(key) { | ||
var decoder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : decodeURIComponent; | ||
var reKey = new RegExp("(?:^|; )" + escapeRe(key) + "(?:=([^;]*))?(?:;|$)"); | ||
var match = reKey.exec(document.cookie); | ||
if (typeof key !== 'string' || !key) { | ||
return null; | ||
} | ||
if (match === null) { | ||
return null; | ||
} | ||
var reKey = new RegExp('(?:^|; )' + escapeRe(key) + '(?:=([^;]*))?(?:;|$)'); | ||
var match = reKey.exec(document.cookie); | ||
return typeof decoder === 'function' ? decoder(match[1]) : match[1]; | ||
} // The all cookies | ||
if (match === null) { | ||
return null; | ||
} | ||
return typeof decoder === 'function' ? decoder(match[1]) : match[1]; | ||
} | ||
function getAll(decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
// The all cookies | ||
function getAll() { | ||
var decoder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : decodeURIComponent; | ||
var reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g; | ||
var cookies = {}; | ||
var match; | ||
/* eslint-disable no-cond-assign */ | ||
var reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g; | ||
var cookies = {}; | ||
var match = void 0; | ||
while (match = reKey.exec(document.cookie)) { | ||
reKey.lastIndex = match.index + match.length - 1; | ||
cookies[match[1]] = typeof decoder === 'function' ? decoder(match[2]) : match[2]; | ||
} | ||
/* eslint-disable no-cond-assign */ | ||
while (match = reKey.exec(document.cookie)) { | ||
reKey.lastIndex = match.index + match.length - 1; | ||
cookies[match[1]] = typeof decoder === 'function' ? decoder(match[2]) : match[2]; | ||
} | ||
return cookies; | ||
} // Set a cookie. | ||
return cookies; | ||
} | ||
// Set a cookie. | ||
function set(key, value) { | ||
var encoder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : encodeURIComponent; | ||
var options = arguments[3]; | ||
function set$1(key, value, encoder, options) { | ||
if (encoder === void 0) { | ||
encoder = encodeURIComponent; | ||
} | ||
if ((typeof encoder === 'undefined' ? 'undefined' : _typeof(encoder)) === 'object' && encoder !== null) { | ||
/* eslint-disable no-param-reassign */ | ||
options = encoder; | ||
encoder = encodeURIComponent; | ||
/* eslint-enable no-param-reassign */ | ||
} | ||
var attrsStr = convert(options || {}); | ||
var valueStr = typeof encoder === 'function' ? encoder(value) : value; | ||
var newCookie = key + '=' + valueStr + attrsStr; | ||
document.cookie = newCookie; | ||
} | ||
if (typeof encoder === 'object' && encoder !== null) { | ||
/* eslint-disable no-param-reassign */ | ||
options = encoder; | ||
encoder = encodeURIComponent; | ||
/* eslint-enable no-param-reassign */ | ||
} | ||
// Remove a cookie by the specified key. | ||
function remove(key, options) { | ||
var opts = { expires: -1 }; | ||
var attrsStr = convert(options || {}); | ||
var valueStr = typeof encoder === 'function' ? encoder(value) : value; | ||
var newCookie = key + "=" + valueStr + attrsStr; | ||
document.cookie = newCookie; | ||
} // Remove a cookie by the specified key. | ||
if (options && options.domain) { | ||
opts.domain = options.domain; | ||
} | ||
return set(key, 'a', opts); | ||
} | ||
function remove(key, options) { | ||
var opts = { | ||
expires: -1 | ||
}; | ||
// Get the cookie's value without decoding. | ||
function getRaw(key) { | ||
return get(key, null); | ||
} | ||
if (options) { | ||
opts = _extends({}, options, opts); | ||
} | ||
// Set a cookie without encoding the value. | ||
function setRaw(key, value, options) { | ||
return set(key, value, null, options); | ||
} | ||
return set$1(key, 'a', opts); | ||
} // Get the cookie's value without decoding. | ||
exports.isEnabled = isEnabled; | ||
exports.get = get; | ||
exports.getAll = getAll; | ||
exports.set = set; | ||
exports.getRaw = getRaw; | ||
exports.setRaw = setRaw; | ||
exports.remove = remove; | ||
exports.isCookieEnabled = isEnabled; | ||
exports.getCookie = get; | ||
exports.getAllCookies = getAll; | ||
exports.setCookie = set; | ||
exports.getRawCookie = getRaw; | ||
exports.setRawCookie = setRaw; | ||
exports.removeCookie = remove; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function getRaw(key) { | ||
return get(key, null); | ||
} // Set a cookie without encoding the value. | ||
}))); | ||
function setRaw(key, value, options) { | ||
return set$1(key, value, null, options); | ||
} | ||
exports.isEnabled = isEnabled; | ||
exports.isCookieEnabled = isEnabled; | ||
exports.get = get; | ||
exports.getCookie = get; | ||
exports.getAll = getAll; | ||
exports.getAllCookies = getAll; | ||
exports.set = set$1; | ||
exports.setCookie = set$1; | ||
exports.getRaw = getRaw; | ||
exports.getRawCookie = getRaw; | ||
exports.setRaw = setRaw; | ||
exports.setRawCookie = setRaw; | ||
exports.remove = remove; | ||
exports.removeCookie = remove; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Cookie=e.Cookie||{})}(this,function(e){"use strict";function t(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function o(e){return e.replace(/[.*+?^$|[\](){}\\-]/g,"\\$&")}function n(e){var t=e.charAt(e.length-1),o=parseInt(e,10),n=new Date;switch(t){case"Y":n.setFullYear(n.getFullYear()+o);break;case"M":n.setMonth(n.getMonth()+o);break;case"D":n.setDate(n.getDate()+o);break;case"h":n.setHours(n.getHours()+o);break;case"m":n.setMinutes(n.getMinutes()+o);break;case"s":n.setSeconds(n.getSeconds()+o);break;default:n=new Date(e)}return n}function r(e){var o="";for(var r in e)if(t(e,r))if(/^expires$/i.test(r)){var i=e[r];"object"!==(void 0===i?"undefined":l(i))&&(i+="number"==typeof i?"D":"",i=n(i)),o+=";"+r+"="+i.toUTCString()}else/^secure$/.test(r)?e[r]&&(o+=";"+r):o+=";"+r+"="+e[r];return t(e,"path")||(o+=";path=/"),o}function i(){var e=RegExp("(?:^|; )@key@=1(?:;|$)");document.cookie="@key@=1";var t=e.test(document.cookie);return t&&f("@key@"),t}function u(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:decodeURIComponent;if("string"!=typeof e||!e)return null;var n=RegExp("(?:^|; )"+o(e)+"(?:=([^;]*))?(?:;|$)"),r=n.exec(document.cookie);return null===r?null:"function"==typeof t?t(r[1]):r[1]}function c(){for(var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:decodeURIComponent,t=/(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g,o={},n=void 0;n=t.exec(document.cookie);)t.lastIndex=n.index+n.length-1,o[n[1]]="function"==typeof e?e(n[2]):n[2];return o}function a(e,t){var o=arguments.length>2&&arguments[2]!==undefined?arguments[2]:encodeURIComponent,n=arguments[3];"object"===(void 0===o?"undefined":l(o))&&null!==o&&(n=o,o=encodeURIComponent);var i=r(n||{}),u="function"==typeof o?o(t):t,c=e+"="+u+i;document.cookie=c}function f(e,t){var o={expires:-1};return t&&t.domain&&(o.domain=t.domain),a(e,"a",o)}function s(e){return u(e,null)}function d(e,t,o){return a(e,t,null,o)}var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.isEnabled=i,e.get=u,e.getAll=c,e.set=a,e.getRaw=s,e.setRaw=d,e.remove=f,e.isCookieEnabled=i,e.getCookie=u,e.getAllCookies=c,e.setCookie=a,e.getRawCookie=s,e.setRawCookie=d,e.removeCookie=f,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Cookie={})}(this,function(e){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function u(e){var t=e.charAt(e.length-1),o=parseInt(e,10),n=new Date;switch(t){case"Y":n.setFullYear(n.getFullYear()+o);break;case"M":n.setMonth(n.getMonth()+o);break;case"D":n.setDate(n.getDate()+o);break;case"h":n.setHours(n.getHours()+o);break;case"m":n.setMinutes(n.getMinutes()+o);break;case"s":n.setSeconds(n.getSeconds()+o);break;default:n=new Date(e)}return n}function t(){var e="@key@",t=/(?:^|; )@key@=1(?:;|$)/;document.cookie=e+"=1";var o=t.test(document.cookie);return o&&a(e),o}function o(e,t){if(void 0===t&&(t=decodeURIComponent),"string"!=typeof e||!e)return null;var o=RegExp("(?:^|; )"+e.replace(/[.*+?^$|[\](){}\\-]/g,"\\$&")+"(?:=([^;]*))?(?:;|$)").exec(document.cookie);return null===o?null:"function"==typeof t?t(o[1]):o[1]}function r(e){void 0===e&&(e=decodeURIComponent);for(var t,o=/(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g,n={};t=o.exec(document.cookie);)o.lastIndex=t.index+t.length-1,n[t[1]]="function"==typeof e?e(t[2]):t[2];return n}function i(e,t,o,n){void 0===o&&(o=encodeURIComponent),"object"==typeof o&&null!==o&&(n=o,o=encodeURIComponent);var r=function(e){var t="";for(var o in e)if(c(e,o))if(/^expires$/i.test(o)){var n=e[o];"object"!=typeof n&&(n=u(n+="number"==typeof n?"D":"")),t+=";"+o+"="+n.toUTCString()}else/^secure$/.test(o)?e[o]&&(t+=";"+o):t+=";"+o+"="+e[o];return c(e,"path")||(t+=";path=/"),t}(n||{}),i="function"==typeof o?o(t):t;document.cookie=e+"="+i+r}function a(e,t){var o={expires:-1};return t&&(o=n({},t,o)),i(e,"a",o)}function s(e){return o(e,null)}function f(e,t,o){return i(e,t,null,o)}e.isEnabled=t,e.isCookieEnabled=t,e.get=o,e.getCookie=o,e.getAll=r,e.getAllCookies=r,e.set=i,e.setCookie=i,e.getRaw=s,e.getRawCookie=s,e.setRaw=f,e.setRawCookie=f,e.remove=a,e.removeCookie=a,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -1,13 +0,10 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import { escapeRe, convert } from './util'; | ||
import { escapeRe, convert } from './util'; // Check if the browser cookie is enabled. | ||
// Check if the browser cookie is enabled. | ||
function isEnabled() { | ||
var key = '@key@'; | ||
var value = '1'; | ||
var re = new RegExp('(?:^|; )' + key + '=' + value + '(?:;|$)'); | ||
document.cookie = key + '=' + value; | ||
var re = new RegExp("(?:^|; )" + key + "=" + value + "(?:;|$)"); | ||
document.cookie = key + "=" + value; | ||
var enabled = re.test(document.cookie); | ||
@@ -21,8 +18,10 @@ | ||
return enabled; | ||
} | ||
} // Get the cookie value by key. | ||
// Get the cookie value by key. | ||
function get(key) { | ||
var decoder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : decodeURIComponent; | ||
function get(key, decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
if (typeof key !== 'string' || !key) { | ||
@@ -32,3 +31,3 @@ return null; | ||
var reKey = new RegExp('(?:^|; )' + escapeRe(key) + '(?:=([^;]*))?(?:;|$)'); | ||
var reKey = new RegExp("(?:^|; )" + escapeRe(key) + "(?:=([^;]*))?(?:;|$)"); | ||
var match = reKey.exec(document.cookie); | ||
@@ -41,13 +40,15 @@ | ||
return typeof decoder === 'function' ? decoder(match[1]) : match[1]; | ||
} | ||
} // The all cookies | ||
// The all cookies | ||
function getAll() { | ||
var decoder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : decodeURIComponent; | ||
function getAll(decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
var reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g; | ||
var cookies = {}; | ||
var match = void 0; | ||
var match; | ||
/* eslint-disable no-cond-assign */ | ||
/* eslint-disable no-cond-assign */ | ||
while (match = reKey.exec(document.cookie)) { | ||
@@ -59,10 +60,11 @@ reKey.lastIndex = match.index + match.length - 1; | ||
return cookies; | ||
} | ||
} // Set a cookie. | ||
// Set a cookie. | ||
function set(key, value) { | ||
var encoder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : encodeURIComponent; | ||
var options = arguments[3]; | ||
if ((typeof encoder === 'undefined' ? 'undefined' : _typeof(encoder)) === 'object' && encoder !== null) { | ||
function set(key, value, encoder, options) { | ||
if (encoder === void 0) { | ||
encoder = encodeURIComponent; | ||
} | ||
if (typeof encoder === 'object' && encoder !== null) { | ||
/* eslint-disable no-param-reassign */ | ||
@@ -73,25 +75,28 @@ options = encoder; | ||
} | ||
var attrsStr = convert(options || {}); | ||
var valueStr = typeof encoder === 'function' ? encoder(value) : value; | ||
var newCookie = key + '=' + valueStr + attrsStr; | ||
var newCookie = key + "=" + valueStr + attrsStr; | ||
document.cookie = newCookie; | ||
} | ||
} // Remove a cookie by the specified key. | ||
// Remove a cookie by the specified key. | ||
function remove(key, options) { | ||
var opts = { expires: -1 }; | ||
var opts = { | ||
expires: -1 | ||
}; | ||
if (options && options.domain) { | ||
opts.domain = options.domain; | ||
if (options) { | ||
opts = _extends({}, options, opts); | ||
} | ||
return set(key, 'a', opts); | ||
} | ||
} // Get the cookie's value without decoding. | ||
// Get the cookie's value without decoding. | ||
function getRaw(key) { | ||
return get(key, null); | ||
} | ||
} // Set a cookie without encoding the value. | ||
// Set a cookie without encoding the value. | ||
function setRaw(key, value, options) { | ||
@@ -98,0 +103,0 @@ return set(key, value, null, options); |
@@ -1,13 +0,11 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function hasOwn(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
} // Escape special characters. | ||
// Escape special characters. | ||
function escapeRe(str) { | ||
return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | ||
} | ||
} // Return a future date by the given string. | ||
// Return a future date by the given string. | ||
function computeExpires(str) { | ||
@@ -20,13 +18,25 @@ var lastCh = str.charAt(str.length - 1); | ||
case 'Y': | ||
expires.setFullYear(expires.getFullYear() + value);break; | ||
expires.setFullYear(expires.getFullYear() + value); | ||
break; | ||
case 'M': | ||
expires.setMonth(expires.getMonth() + value);break; | ||
expires.setMonth(expires.getMonth() + value); | ||
break; | ||
case 'D': | ||
expires.setDate(expires.getDate() + value);break; | ||
expires.setDate(expires.getDate() + value); | ||
break; | ||
case 'h': | ||
expires.setHours(expires.getHours() + value);break; | ||
expires.setHours(expires.getHours() + value); | ||
break; | ||
case 'm': | ||
expires.setMinutes(expires.getMinutes() + value);break; | ||
expires.setMinutes(expires.getMinutes() + value); | ||
break; | ||
case 's': | ||
expires.setSeconds(expires.getSeconds() + value);break; | ||
expires.setSeconds(expires.getSeconds() + value); | ||
break; | ||
default: | ||
@@ -37,9 +47,8 @@ expires = new Date(str); | ||
return expires; | ||
} | ||
} // Convert an object to a cookie option string. | ||
// Convert an object to a cookie option string. | ||
function convert(opts) { | ||
var res = ''; | ||
var res = ''; // eslint-disable-next-line | ||
// eslint-disable-next-line | ||
for (var key in opts) { | ||
@@ -50,13 +59,14 @@ if (hasOwn(opts, key)) { | ||
if ((typeof expires === 'undefined' ? 'undefined' : _typeof(expires)) !== 'object') { | ||
if (typeof expires !== 'object') { | ||
expires += typeof expires === 'number' ? 'D' : ''; | ||
expires = computeExpires(expires); | ||
} | ||
res += ';' + key + '=' + expires.toUTCString(); | ||
res += ";" + key + "=" + expires.toUTCString(); | ||
} else if (/^secure$/.test(key)) { | ||
if (opts[key]) { | ||
res += ';' + key; | ||
res += ";" + key; | ||
} | ||
} else { | ||
res += ';' + key + '=' + opts[key]; | ||
res += ";" + key + "=" + opts[key]; | ||
} | ||
@@ -63,0 +73,0 @@ } |
@@ -1,9 +0,15 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.removeCookie = exports.setRawCookie = exports.getRawCookie = exports.setCookie = exports.getAllCookies = exports.getCookie = exports.isCookieEnabled = exports.remove = exports.setRaw = exports.getRaw = exports.set = exports.getAll = exports.get = exports.isEnabled = undefined; | ||
exports.isCookieEnabled = exports.isEnabled = isEnabled; | ||
exports.getCookie = exports.get = get; | ||
exports.getAllCookies = exports.getAll = getAll; | ||
exports.setCookie = exports.set = set; | ||
exports.getRawCookie = exports.getRaw = getRaw; | ||
exports.setRawCookie = exports.setRaw = setRaw; | ||
exports.removeCookie = exports.remove = remove; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _util = require("./util"); | ||
var _util = require('./util'); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
@@ -14,6 +20,4 @@ // Check if the browser cookie is enabled. | ||
var value = '1'; | ||
var re = new RegExp('(?:^|; )' + key + '=' + value + '(?:;|$)'); | ||
document.cookie = key + '=' + value; | ||
var re = new RegExp("(?:^|; )" + key + "=" + value + "(?:;|$)"); | ||
document.cookie = key + "=" + value; | ||
var enabled = re.test(document.cookie); | ||
@@ -27,8 +31,10 @@ | ||
return enabled; | ||
} | ||
} // Get the cookie value by key. | ||
// Get the cookie value by key. | ||
function get(key) { | ||
var decoder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : decodeURIComponent; | ||
function get(key, decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
if (typeof key !== 'string' || !key) { | ||
@@ -38,3 +44,3 @@ return null; | ||
var reKey = new RegExp('(?:^|; )' + (0, _util.escapeRe)(key) + '(?:=([^;]*))?(?:;|$)'); | ||
var reKey = new RegExp("(?:^|; )" + (0, _util.escapeRe)(key) + "(?:=([^;]*))?(?:;|$)"); | ||
var match = reKey.exec(document.cookie); | ||
@@ -47,13 +53,15 @@ | ||
return typeof decoder === 'function' ? decoder(match[1]) : match[1]; | ||
} | ||
} // The all cookies | ||
// The all cookies | ||
function getAll() { | ||
var decoder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : decodeURIComponent; | ||
function getAll(decoder) { | ||
if (decoder === void 0) { | ||
decoder = decodeURIComponent; | ||
} | ||
var reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g; | ||
var cookies = {}; | ||
var match = void 0; | ||
var match; | ||
/* eslint-disable no-cond-assign */ | ||
/* eslint-disable no-cond-assign */ | ||
while (match = reKey.exec(document.cookie)) { | ||
@@ -65,10 +73,11 @@ reKey.lastIndex = match.index + match.length - 1; | ||
return cookies; | ||
} | ||
} // Set a cookie. | ||
// Set a cookie. | ||
function set(key, value) { | ||
var encoder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : encodeURIComponent; | ||
var options = arguments[3]; | ||
if ((typeof encoder === 'undefined' ? 'undefined' : _typeof(encoder)) === 'object' && encoder !== null) { | ||
function set(key, value, encoder, options) { | ||
if (encoder === void 0) { | ||
encoder = encodeURIComponent; | ||
} | ||
if (typeof encoder === 'object' && encoder !== null) { | ||
/* eslint-disable no-param-reassign */ | ||
@@ -79,42 +88,30 @@ options = encoder; | ||
} | ||
var attrsStr = (0, _util.convert)(options || {}); | ||
var valueStr = typeof encoder === 'function' ? encoder(value) : value; | ||
var newCookie = key + '=' + valueStr + attrsStr; | ||
var newCookie = key + "=" + valueStr + attrsStr; | ||
document.cookie = newCookie; | ||
} | ||
} // Remove a cookie by the specified key. | ||
// Remove a cookie by the specified key. | ||
function remove(key, options) { | ||
var opts = { expires: -1 }; | ||
var opts = { | ||
expires: -1 | ||
}; | ||
if (options && options.domain) { | ||
opts.domain = options.domain; | ||
if (options) { | ||
opts = _extends({}, options, opts); | ||
} | ||
return set(key, 'a', opts); | ||
} | ||
} // Get the cookie's value without decoding. | ||
// Get the cookie's value without decoding. | ||
function getRaw(key) { | ||
return get(key, null); | ||
} | ||
} // Set a cookie without encoding the value. | ||
// Set a cookie without encoding the value. | ||
function setRaw(key, value, options) { | ||
return set(key, value, null, options); | ||
} | ||
exports.isEnabled = isEnabled; | ||
exports.get = get; | ||
exports.getAll = getAll; | ||
exports.set = set; | ||
exports.getRaw = getRaw; | ||
exports.setRaw = setRaw; | ||
exports.remove = remove; | ||
exports.isCookieEnabled = isEnabled; | ||
exports.getCookie = get; | ||
exports.getAllCookies = getAll; | ||
exports.setCookie = set; | ||
exports.getRawCookie = getRaw; | ||
exports.setRawCookie = setRaw; | ||
exports.removeCookie = remove; | ||
} |
@@ -1,17 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.hasOwn = hasOwn; | ||
exports.escapeRe = escapeRe; | ||
exports.computeExpires = computeExpires; | ||
exports.convert = convert; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function hasOwn(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
} // Escape special characters. | ||
// Escape special characters. | ||
function escapeRe(str) { | ||
return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | ||
} | ||
} // Return a future date by the given string. | ||
// Return a future date by the given string. | ||
function computeExpires(str) { | ||
@@ -24,13 +26,25 @@ var lastCh = str.charAt(str.length - 1); | ||
case 'Y': | ||
expires.setFullYear(expires.getFullYear() + value);break; | ||
expires.setFullYear(expires.getFullYear() + value); | ||
break; | ||
case 'M': | ||
expires.setMonth(expires.getMonth() + value);break; | ||
expires.setMonth(expires.getMonth() + value); | ||
break; | ||
case 'D': | ||
expires.setDate(expires.getDate() + value);break; | ||
expires.setDate(expires.getDate() + value); | ||
break; | ||
case 'h': | ||
expires.setHours(expires.getHours() + value);break; | ||
expires.setHours(expires.getHours() + value); | ||
break; | ||
case 'm': | ||
expires.setMinutes(expires.getMinutes() + value);break; | ||
expires.setMinutes(expires.getMinutes() + value); | ||
break; | ||
case 's': | ||
expires.setSeconds(expires.getSeconds() + value);break; | ||
expires.setSeconds(expires.getSeconds() + value); | ||
break; | ||
default: | ||
@@ -41,9 +55,8 @@ expires = new Date(str); | ||
return expires; | ||
} | ||
} // Convert an object to a cookie option string. | ||
// Convert an object to a cookie option string. | ||
function convert(opts) { | ||
var res = ''; | ||
var res = ''; // eslint-disable-next-line | ||
// eslint-disable-next-line | ||
for (var key in opts) { | ||
@@ -54,13 +67,14 @@ if (hasOwn(opts, key)) { | ||
if ((typeof expires === 'undefined' ? 'undefined' : _typeof(expires)) !== 'object') { | ||
if (typeof expires !== 'object') { | ||
expires += typeof expires === 'number' ? 'D' : ''; | ||
expires = computeExpires(expires); | ||
} | ||
res += ';' + key + '=' + expires.toUTCString(); | ||
res += ";" + key + "=" + expires.toUTCString(); | ||
} else if (/^secure$/.test(key)) { | ||
if (opts[key]) { | ||
res += ';' + key; | ||
res += ";" + key; | ||
} | ||
} else { | ||
res += ';' + key + '=' + opts[key]; | ||
res += ";" + key + "=" + opts[key]; | ||
} | ||
@@ -75,7 +89,2 @@ } | ||
return res; | ||
} | ||
exports.hasOwn = hasOwn; | ||
exports.escapeRe = escapeRe; | ||
exports.computeExpires = computeExpires; | ||
exports.convert = convert; | ||
} |
{ | ||
"name": "tiny-cookie", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A tiny cookie manipulation plugin", | ||
@@ -25,4 +25,4 @@ "main": "lib/index.js", | ||
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c -i src/index.js -o dist/tiny-cookie.js", | ||
"build:umd:min": "cross-env NODE_ENV=production rollup -c -i src/index.js -o dist/tiny-cookie.min.js", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c rollup.config.js", | ||
"build:umd:min": "cross-env NODE_ENV=production rollup -c rollup.config.js", | ||
"build": "npm run clean && npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min" | ||
@@ -41,8 +41,8 @@ }, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.25.0", | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.2.2", | ||
"@babel/node": "^7.2.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.2.0", | ||
"@babel/preset-env": "^7.2.3", | ||
"babel-eslint": "^7.2.3", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.5.2", | ||
"babelrc-rollup": "^3.0.0", | ||
"chai": "^4.0.2", | ||
@@ -52,15 +52,15 @@ "cross-env": "^5.0.1", | ||
"eslint-config-airbnb-base": "^11.2.0", | ||
"eslint-plugin-import": "^2.6.0", | ||
"express": "^4.15.3", | ||
"karma": "^1.7.0", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-coverage": "^1.1.1", | ||
"eslint-plugin-import": "^2.14.0", | ||
"express": "^4.16.4", | ||
"karma": "^3.1.4", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage": "^1.1.2", | ||
"karma-mocha": "^1.3.0", | ||
"karma-sauce-launcher": "^1.1.0", | ||
"mocha": "^3.4.2", | ||
"karma-sauce-launcher": "^2.0.2", | ||
"mocha": "^5.2.0", | ||
"pre-commit": "^1.2.2", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.43.0", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-uglify": "^1.0.2" | ||
"rollup": "^1.1.0", | ||
"rollup-plugin-babel": "^4.3.0", | ||
"rollup-plugin-uglify": "^6.0.0" | ||
}, | ||
@@ -67,0 +67,0 @@ "keywords": [ |
@@ -68,6 +68,6 @@ import { escapeRe, convert } from './util'; | ||
function remove(key, options) { | ||
const opts = { expires: -1 }; | ||
let opts = { expires: -1 }; | ||
if (options && options.domain) { | ||
opts.domain = options.domain; | ||
if (options) { | ||
opts = { ...options, ...opts }; | ||
} | ||
@@ -74,0 +74,0 @@ |
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
709
32603