UNPKG

cookie-storage-v2

Version:

A lightweight JavaScript UMD to handle cookies through Web Storage Interface

1 lines 36.8 kB
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///cookie-storage.min.js","webpack:///webpack/bootstrap 154f36952f7c5d71e507","webpack:///./src/utils.js","webpack:///./src/main.js","webpack:///./src/cookie-storage.js","webpack:///./src/format-metadata.js","webpack:///./src/expiration-date.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","isObject","value","toString","checkEmpty","key","Error","setProperty","obj","descriptor","writable","tryParse","parsed","JSON","parse","e","_classCallCheck","instance","Constructor","TypeError","copyKeys","storage","keys","forEach","_utils","_createClass","defineProperties","target","props","length","protoProps","staticProps","_cookieStorage","_cookieStorage2","default","BANNED_KEYS","CookieStorage","options","test","stringify","setItem","getItem","removeItem","_this","clear","_interopRequireDefault","findCookie","cookie","nameEQ","trim","indexOf","initialize","api","prop","$cookie","split","index","substring","decodeURIComponent","_formatMetadata","_formatMetadata2","_expirationDate","_expirationDate2","document","set","data","assign","path","metadata","expires","Date","domain","secure","encodeURIComponent","find","days","indexEQ","buildMetadataFor","formatMetadata","alterDate","arguments","undefined","opt","date","minutes","setMinutes","getMinutes","hours","setHours","getHours","setDate","getDate","months","setMonth","getMonth","years","setFullYear","getFullYear","buildExpiration","toUTCString"],"mappings":";CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,cAAAD,IAEAD,EAAA,cAAAC,KACCK,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAP,OAGA,IAAAC,GAAAO,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAV,W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,OAAOC,eAAenB,EAAS,cAC7BgC,OAAO,IAEThC,EAAQgE,QMvfgBgE,EN8hBxB/H,EAAOD,QAAUA,EAAiB","file":"cookie-storage.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"cookieStorage\"] = factory();\n\telse\n\t\troot[\"cookieStorage\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"cookieStorage\"] = factory();\n\telse\n\t\troot[\"cookieStorage\"] = factory();\n})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 1);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.isObject = isObject;\nexports.checkEmpty = checkEmpty;\nexports.setProperty = setProperty;\nexports.tryParse = tryParse;\n/**\n * Determines whether a value is a plain object.\n *\n * @param {any} value: the object to test\n * @return {boolean}\n */\nfunction isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Validates if the key is not empty.\n * (null, undefined or empty string)\n *\n * @param {string} key: keyname of an element in the storage mechanism\n * @return {void}\n */\nfunction checkEmpty(key) {\n if (key == null || key === '') {\n throw new Error('The key provided can not be empty');\n }\n}\n\n/**\n * Creates a non-enumerable read-only property.\n *\n * @param {object} obj: the object to add the property\n * @param {string} name: the name of the property\n * @param {any} value: the value of the property\n * @return {void}\n */\nfunction setProperty(obj, name, value) {\n var descriptor = {\n configurable: false,\n enumerable: false,\n writable: false\n };\n if (typeof value !== 'undefined') {\n descriptor.value = value;\n }\n Object.defineProperty(obj, name, descriptor);\n}\n\n/**\n * Try to parse a value from JSON.\n *\n * @param {string} value: the value to parse\n * @return {any}\n */\nfunction tryParse(value) {\n var parsed = void 0;\n try {\n parsed = JSON.parse(value);\n } catch (e) {\n parsed = value;\n }\n return parsed;\n}\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _utils = __webpack_require__(0);\n\nvar _cookieStorage = __webpack_require__(2);\n\nvar _cookieStorage2 = _interopRequireDefault(_cookieStorage);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n/**\n * @private\n *\n * Keys not allowed for cookies.\n *\n * @type {RegExp}\n */\nvar BANNED_KEYS = /^(?:expires|max-age|path|domain|secure)$/i;\n\n/**\n * @private\n *\n * Copies all existing keys in the storage.\n *\n * @param {CookieStorage} instance: the object to where copy the keys\n * @param {object} storage: the storage mechanism\n * @return {object}\n */\nfunction copyKeys(instance, storage) {\n Object.keys(storage).forEach(function (key) {\n instance[key] = (0, _utils.tryParse)(storage[key]);\n });\n return instance;\n}\n\n/**\n * @private\n *\n * Implementation of the Web Storage interface.\n * It saves and retrieves values as JSON.\n *\n * @see\n * https://developer.mozilla.org/en-US/docs/Web/API/Storage\n *\n * @type {class}\n */\n\nvar CookieStorage = function () {\n /**\n * Creates an instance of CookieStorage.\n *\n * @memberOf CookieStorage\n */\n function CookieStorage() {\n _classCallCheck(this, CookieStorage);\n\n copyKeys(this, _cookieStorage2.default);\n }\n\n /**\n * Stores a value given a key name.\n *\n * @param {string} key: keyname of the storage\n * @param {any} value: data to save in the storage\n * @param {object} options: additional options for cookieStore\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n\n\n _createClass(CookieStorage, [{\n key: 'setItem',\n value: function setItem(key, value, options) {\n (0, _utils.checkEmpty)(key);\n if (BANNED_KEYS.test(key)) {\n throw new Error('The key is a reserved word, therefore not allowed');\n }\n this[key] = value;\n // prevents converting strings to JSON to avoid extra quotes\n if (typeof value !== 'string') value = JSON.stringify(value);\n _cookieStorage2.default.setItem(key, value, options);\n // checks if the cookie was created, or delete it if the domain or path are not valid\n if (_cookieStorage2.default.getItem(key) === null) {\n delete this[key];\n }\n }\n\n /**\n * Retrieves a value by its key name.\n *\n * @param {string} key: keyname of the storage\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n\n }, {\n key: 'getItem',\n value: function getItem(key) {\n (0, _utils.checkEmpty)(key);\n var value = _cookieStorage2.default.getItem(key);\n if (value == null) {\n // null or undefined\n delete this[key];\n value = null;\n } else {\n value = (0, _utils.tryParse)(value);\n this[key] = value;\n }\n return value;\n }\n\n /**\n * Deletes a key from the storage.\n *\n * @param {string} key: keyname of the storage\n * @param {object} options: additional options for cookieStore\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n\n }, {\n key: 'removeItem',\n value: function removeItem(key, options) {\n (0, _utils.checkEmpty)(key);\n delete this[key];\n _cookieStorage2.default.removeItem(key, options);\n }\n\n /**\n * Removes all keys from the storage.\n *\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n\n }, {\n key: 'clear',\n value: function clear() {\n var _this = this;\n\n Object.keys(this).forEach(function (key) {\n delete _this[key];\n }, this);\n _cookieStorage2.default.clear();\n }\n\n /**\n * Gets the number of data items stored in the storage object.\n *\n * @readonly\n *\n * @memberOf CookieStorage\n */\n\n }, {\n key: 'length',\n get: function get() {\n return Object.keys(this).length;\n }\n }]);\n\n return CookieStorage;\n}();\n\n/**\n * @public API\n */\n\n\nexports.default = new CookieStorage();\nmodule.exports = exports['default'];\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _utils = __webpack_require__(0);\n\nvar _formatMetadata = __webpack_require__(3);\n\nvar _formatMetadata2 = _interopRequireDefault(_formatMetadata);\n\nvar _expirationDate = __webpack_require__(4);\n\nvar _expirationDate2 = _interopRequireDefault(_expirationDate);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\n/**\n * @private\n *\n * Proxy for document.cookie\n *\n * @see\n * https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie\n *\n * @type {object}\n */\nvar $cookie = {\n get: function get() {\n return document.cookie;\n },\n set: function set(value) {\n document.cookie = value;\n },\n data: {} // metadata associated to the cookies\n};\n\n/**\n * @private\n *\n * Finds an element in the array.\n *\n * @param {string} cookie: key=value\n * @return {boolean}\n */\nfunction findCookie(cookie) {\n var nameEQ = this.toString();\n // prevent leading spaces before the key\n return cookie.trim().indexOf(nameEQ) === 0;\n}\n\n/**\n * @public\n *\n * Create, read, and delete elements from document.cookie,\n * and implements the Web Storage interface.\n *\n * @return {object}\n */\nfunction cookieStorage() {\n var api = {\n setItem: function setItem(key, value, options) {\n options = Object.assign({ path: '/' }, options);\n // keep track of the metadata associated to the cookie\n $cookie.data[key] = { path: options.path };\n var metadata = $cookie.data[key];\n if ((0, _utils.isObject)(options.expires) || options.expires instanceof Date) {\n metadata.expires = (0, _expirationDate2.default)(options.expires);\n }\n if (options.domain && typeof options.domain === 'string') {\n metadata.domain = options.domain.trim();\n }\n if (options.secure === true) metadata.secure = true;\n var cookie = key + '=' + encodeURIComponent(value) + (0, _formatMetadata2.default)(metadata);\n // TODO: should encodeURIComponent(key) ?\n $cookie.set(cookie);\n },\n getItem: function getItem(key) {\n var value = null;\n var nameEQ = key + '=';\n var cookie = $cookie.get().split(';').find(findCookie, nameEQ);\n if (cookie) {\n // prevent leading spaces before the key name\n value = cookie.trim().substring(nameEQ.length, cookie.length);\n value = decodeURIComponent(value);\n }\n if (value === null) delete $cookie.data[key];\n return value;\n },\n removeItem: function removeItem(key, options) {\n var metadata = Object.assign({}, $cookie.data[key], options);\n metadata.expires = { days: -1 };\n api.setItem(key, '', metadata);\n delete $cookie.data[key];\n },\n clear: function clear() {\n var key = void 0,\n indexEQ = void 0;\n $cookie.get().split(';').forEach(function (cookie) {\n indexEQ = cookie.indexOf('=');\n if (indexEQ > -1) {\n key = cookie.substring(0, indexEQ);\n // prevent leading spaces before the key\n api.removeItem(key.trim());\n }\n });\n }\n };\n\n return initialize(api);\n}\n\n/**\n * @private\n *\n * Copy the current items in the cookie storage.\n *\n * @param {object} api: the storage mechanism to initialize\n * @return {object}\n */\nfunction initialize(api) {\n // sets API members to read-only and non-enumerable\n for (var prop in api) {\n // eslint-disable-line\n (0, _utils.setProperty)(api, prop);\n }\n // copies all existing elements in the storage\n $cookie.get().split(';').forEach(function (cookie) {\n var index = cookie.indexOf('=');\n var key = cookie.substring(0, index).trim();\n var value = cookie.substring(index + 1).trim();\n if (key) api[key] = decodeURIComponent(value);\n });\n return api;\n}\n\n/**\n * @public API\n */\nexports.default = cookieStorage();\nmodule.exports = exports['default'];\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = formatMetadata;\n/**\n * @private\n *\n * Builds the string for the cookie metadata.\n *\n * @param {string} key: name of the metadata\n * @param {object} data: metadata of the cookie\n * @return {string}\n */\nfunction buildMetadataFor(key, data) {\n if (!data[key]) return '';\n return ';' + key + '=' + data[key];\n}\n\n/**\n * Builds the whole string for the cookie metadata.\n *\n * @param {object} data: metadata of the cookie\n * @return {string}\n */\nfunction formatMetadata(data) {\n var expires = buildMetadataFor('expires', data);\n var domain = buildMetadataFor('domain', data);\n var path = buildMetadataFor('path', data);\n var secure = data.secure ? ';secure' : '';\n return '' + expires + domain + path + secure;\n}\nmodule.exports = exports['default'];\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = buildExpiration;\n/**\n * @private\n *\n * Adds or subtracts date portions to the given date and returns the new date.\n * @see https://gist.github.com/jherax/bbc43e479a492cc9cbfc7ccc20c53cd2\n *\n * @param {object} options: It contains the date parts to add or remove, and can have the following properties:\n * - {Date} date: if provided, this date will be affected, otherwise the current date will be used.\n * - {number} minutes: minutes to add/subtract\n * - {number} hours: hours to add/subtract\n * - {number} days: days to add/subtract\n * - {number} months: months to add/subtract\n * - {number} years: years to add/subtract\n * @return {Date}\n */\nfunction alterDate() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n var opt = Object.assign({}, options);\n var d = opt.date instanceof Date ? opt.date : new Date();\n if (+opt.minutes) d.setMinutes(d.getMinutes() + opt.minutes);\n if (+opt.hours) d.setHours(d.getHours() + opt.hours);\n if (+opt.days) d.setDate(d.getDate() + opt.days);\n if (+opt.months) d.setMonth(d.getMonth() + opt.months);\n if (+opt.years) d.setFullYear(d.getFullYear() + opt.years);\n return d;\n}\n\n/**\n * Builds the expiration for the cookie.\n *\n * @param {Date|object} date: the expiration date\n * @return {string}\n */\nfunction buildExpiration(date) {\n var expires = date instanceof Date ? alterDate({ date: date }) : alterDate(date);\n return expires.toUTCString();\n}\nmodule.exports = exports[\"default\"];\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// cookie-storage.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 154f36952f7c5d71e507","/**\n * Determines whether a value is a plain object.\n *\n * @param {any} value: the object to test\n * @return {boolean}\n */\nexport function isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Validates if the key is not empty.\n * (null, undefined or empty string)\n *\n * @param {string} key: keyname of an element in the storage mechanism\n * @return {void}\n */\nexport function checkEmpty(key) {\n if (key == null || key === '') {\n throw new Error('The key provided can not be empty');\n }\n}\n\n/**\n * Creates a non-enumerable read-only property.\n *\n * @param {object} obj: the object to add the property\n * @param {string} name: the name of the property\n * @param {any} value: the value of the property\n * @return {void}\n */\nexport function setProperty(obj, name, value) {\n const descriptor = {\n configurable: false,\n enumerable: false,\n writable: false,\n };\n if (typeof value !== 'undefined') {\n descriptor.value = value;\n }\n Object.defineProperty(obj, name, descriptor);\n}\n\n/**\n * Try to parse a value from JSON.\n *\n * @param {string} value: the value to parse\n * @return {any}\n */\nexport function tryParse(value) {\n let parsed;\n try {\n parsed = JSON.parse(value);\n } catch (e) {\n parsed = value;\n }\n return parsed;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.js","import {checkEmpty, tryParse} from './utils';\nimport cookieStore from './cookie-storage';\n\n/**\n * @private\n *\n * Keys not allowed for cookies.\n *\n * @type {RegExp}\n */\nconst BANNED_KEYS = /^(?:expires|max-age|path|domain|secure)$/i;\n\n/**\n * @private\n *\n * Copies all existing keys in the storage.\n *\n * @param {CookieStorage} instance: the object to where copy the keys\n * @param {object} storage: the storage mechanism\n * @return {object}\n */\nfunction copyKeys(instance, storage) {\n Object.keys(storage).forEach((key) => {\n instance[key] = tryParse(storage[key]);\n });\n return instance;\n}\n\n/**\n * @private\n *\n * Implementation of the Web Storage interface.\n * It saves and retrieves values as JSON.\n *\n * @see\n * https://developer.mozilla.org/en-US/docs/Web/API/Storage\n *\n * @type {class}\n */\nclass CookieStorage {\n /**\n * Creates an instance of CookieStorage.\n *\n * @memberOf CookieStorage\n */\n constructor() {\n copyKeys(this, cookieStore);\n }\n\n /**\n * Stores a value given a key name.\n *\n * @param {string} key: keyname of the storage\n * @param {any} value: data to save in the storage\n * @param {object} options: additional options for cookieStore\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n setItem(key, value, options) {\n checkEmpty(key);\n if (BANNED_KEYS.test(key)) {\n throw new Error('The key is a reserved word, therefore not allowed');\n }\n this[key] = value;\n // prevents converting strings to JSON to avoid extra quotes\n if (typeof value !== 'string') value = JSON.stringify(value);\n cookieStore.setItem(key, value, options);\n // checks if the cookie was created, or delete it if the domain or path are not valid\n if (cookieStore.getItem(key) === null) {\n delete this[key];\n }\n }\n\n /**\n * Retrieves a value by its key name.\n *\n * @param {string} key: keyname of the storage\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n getItem(key) {\n checkEmpty(key);\n let value = cookieStore.getItem(key);\n if (value == null) { // null or undefined\n delete this[key];\n value = null;\n } else {\n value = tryParse(value);\n this[key] = value;\n }\n return value;\n }\n\n /**\n * Deletes a key from the storage.\n *\n * @param {string} key: keyname of the storage\n * @param {object} options: additional options for cookieStore\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n removeItem(key, options) {\n checkEmpty(key);\n delete this[key];\n cookieStore.removeItem(key, options);\n }\n\n /**\n * Removes all keys from the storage.\n *\n * @return {void}\n *\n * @memberOf CookieStorage\n */\n clear() {\n Object.keys(this).forEach((key) => {\n delete this[key];\n }, this);\n cookieStore.clear();\n }\n\n /**\n * Gets the number of data items stored in the storage object.\n *\n * @readonly\n *\n * @memberOf CookieStorage\n */\n get length() {\n return Object.keys(this).length;\n }\n}\n\n/**\n * @public API\n */\nexport default new CookieStorage();\n\n\n\n// WEBPACK FOOTER //\n// ./src/main.js","import {isObject, setProperty} from './utils';\nimport formatMetadata from './format-metadata';\nimport buildExpiration from './expiration-date';\n\n/**\n * @private\n *\n * Proxy for document.cookie\n *\n * @see\n * https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie\n *\n * @type {object}\n */\nconst $cookie = {\n get: () => document.cookie,\n set: (value) => {\n document.cookie = value;\n },\n data: {}, // metadata associated to the cookies\n};\n\n/**\n * @private\n *\n * Finds an element in the array.\n *\n * @param {string} cookie: key=value\n * @return {boolean}\n */\nfunction findCookie(cookie) {\n const nameEQ = this.toString();\n // prevent leading spaces before the key\n return cookie.trim().indexOf(nameEQ) === 0;\n}\n\n/**\n * @public\n *\n * Create, read, and delete elements from document.cookie,\n * and implements the Web Storage interface.\n *\n * @return {object}\n */\nfunction cookieStorage() {\n const api = {\n\n setItem(key, value, options) {\n options = Object.assign({path: '/'}, options);\n // keep track of the metadata associated to the cookie\n $cookie.data[key] = {path: options.path};\n const metadata = $cookie.data[key];\n if (isObject(options.expires) || options.expires instanceof Date) {\n metadata.expires = buildExpiration(options.expires);\n }\n if (options.domain && typeof options.domain === 'string') {\n metadata.domain = options.domain.trim();\n }\n if (options.secure === true) metadata.secure = true;\n const cookie = `${key}=${encodeURIComponent(value)}${formatMetadata(metadata)}`;\n // TODO: should encodeURIComponent(key) ?\n $cookie.set(cookie);\n },\n\n getItem(key) {\n let value = null;\n const nameEQ = `${key}=`;\n const cookie = $cookie.get().split(';').find(findCookie, nameEQ);\n if (cookie) {\n // prevent leading spaces before the key name\n value = cookie.trim().substring(nameEQ.length, cookie.length);\n value = decodeURIComponent(value);\n }\n if (value === null) delete $cookie.data[key];\n return value;\n },\n\n removeItem(key, options) {\n const metadata = Object.assign({}, $cookie.data[key], options);\n metadata.expires = {days: -1};\n api.setItem(key, '', metadata);\n delete $cookie.data[key];\n },\n\n clear() {\n let key, indexEQ;\n $cookie.get().split(';').forEach((cookie) => {\n indexEQ = cookie.indexOf('=');\n if (indexEQ > -1) {\n key = cookie.substring(0, indexEQ);\n // prevent leading spaces before the key\n api.removeItem(key.trim());\n }\n });\n },\n };\n\n return initialize(api);\n}\n\n/**\n * @private\n *\n * Copy the current items in the cookie storage.\n *\n * @param {object} api: the storage mechanism to initialize\n * @return {object}\n */\nfunction initialize(api) {\n // sets API members to read-only and non-enumerable\n for (let prop in api) { // eslint-disable-line\n setProperty(api, prop);\n }\n // copies all existing elements in the storage\n $cookie.get().split(';').forEach((cookie) => {\n const index = cookie.indexOf('=');\n const key = cookie.substring(0, index).trim();\n const value = cookie.substring(index + 1).trim();\n if (key) api[key] = decodeURIComponent(value);\n });\n return api;\n}\n\n/**\n * @public API\n */\nexport default cookieStorage();\n\n\n\n// WEBPACK FOOTER //\n// ./src/cookie-storage.js","/**\n * @private\n *\n * Builds the string for the cookie metadata.\n *\n * @param {string} key: name of the metadata\n * @param {object} data: metadata of the cookie\n * @return {string}\n */\nfunction buildMetadataFor(key, data) {\n if (!data[key]) return '';\n return `;${key}=${data[key]}`;\n}\n\n/**\n * Builds the whole string for the cookie metadata.\n *\n * @param {object} data: metadata of the cookie\n * @return {string}\n */\nexport default function formatMetadata(data) {\n const expires = buildMetadataFor('expires', data);\n const domain = buildMetadataFor('domain', data);\n const path = buildMetadataFor('path', data);\n const secure = data.secure ? ';secure' : '';\n return `${expires}${domain}${path}${secure}`;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/format-metadata.js","/**\n * @private\n *\n * Adds or subtracts date portions to the given date and returns the new date.\n * @see https://gist.github.com/jherax/bbc43e479a492cc9cbfc7ccc20c53cd2\n *\n * @param {object} options: It contains the date parts to add or remove, and can have the following properties:\n * - {Date} date: if provided, this date will be affected, otherwise the current date will be used.\n * - {number} minutes: minutes to add/subtract\n * - {number} hours: hours to add/subtract\n * - {number} days: days to add/subtract\n * - {number} months: months to add/subtract\n * - {number} years: years to add/subtract\n * @return {Date}\n */\nfunction alterDate(options = {}) {\n const opt = Object.assign({}, options);\n const d = opt.date instanceof Date ? opt.date : new Date();\n if (+opt.minutes) d.setMinutes(d.getMinutes() + opt.minutes);\n if (+opt.hours) d.setHours(d.getHours() + opt.hours);\n if (+opt.days) d.setDate(d.getDate() + opt.days);\n if (+opt.months) d.setMonth(d.getMonth() + opt.months);\n if (+opt.years) d.setFullYear(d.getFullYear() + opt.years);\n return d;\n}\n\n/**\n * Builds the expiration for the cookie.\n *\n * @param {Date|object} date: the expiration date\n * @return {string}\n */\nexport default function buildExpiration(date) {\n const expires = (date instanceof Date ?\n alterDate({date}) :\n alterDate(date));\n return expires.toUTCString();\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/expiration-date.js"],"sourceRoot":""}