2 * JavaScript Cookie v2.1.3
3 * https://github.com/js-cookie/js-cookie
5 * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
6 * Released under the MIT license
9 var registeredInModuleLoader = false;
10 if (typeof define === 'function' && define.amd) {
12 registeredInModuleLoader = true;
14 if (typeof exports === 'object') {
15 module.exports = factory();
16 registeredInModuleLoader = true;
18 if (!registeredInModuleLoader) {
19 var OldCookies = window.Cookies;
20 var api = window.Cookies = factory();
21 api.noConflict = function () {
22 window.Cookies = OldCookies;
30 for (; i < arguments.length; i++) {
31 var attributes = arguments[ i ];
32 for (var key in attributes) {
33 result[key] = attributes[key];
39 function init (converter) {
40 function api (key, value, attributes) {
42 if (typeof document === 'undefined') {
48 if (arguments.length > 1) {
51 }, api.defaults, attributes);
53 if (typeof attributes.expires === 'number') {
54 var expires = new Date();
55 expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
56 attributes.expires = expires;
60 result = JSON.stringify(value);
61 if (/^[\{\[]/.test(result)) {
66 if (!converter.write) {
67 value = encodeURIComponent(String(value))
68 .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
70 value = converter.write(value, key);
73 key = encodeURIComponent(String(key));
74 key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
75 key = key.replace(/[\(\)]/g, escape);
77 return (document.cookie = [
79 attributes.expires ? '; expires=' + attributes.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
80 attributes.path ? '; path=' + attributes.path : '',
81 attributes.domain ? '; domain=' + attributes.domain : '',
82 attributes.secure ? '; secure' : ''
92 // To prevent the for loop in the first place assign an empty array
93 // in case there are no cookies at all. Also prevents odd result when
95 var cookies = document.cookie ? document.cookie.split('; ') : [];
96 var rdecode = /(%[0-9A-Z]{2})+/g;
99 for (; i < cookies.length; i++) {
100 var parts = cookies[i].split('=');
101 var cookie = parts.slice(1).join('=');
103 if (cookie.charAt(0) === '"') {
104 cookie = cookie.slice(1, -1);
108 var name = parts[0].replace(rdecode, decodeURIComponent);
109 cookie = converter.read ?
110 converter.read(cookie, name) : converter(cookie, name) ||
111 cookie.replace(rdecode, decodeURIComponent);
115 cookie = JSON.parse(cookie);
125 result[name] = cookie;
134 api.get = function (key) {
135 return api.call(api, key);
137 api.getJSON = function () {
140 }, [].slice.call(arguments));
144 api.remove = function (key, attributes) {
145 api(key, '', extend(attributes, {
150 api.withConverter = init;
155 return init(function () {});