|
1 | | -/*! |
2 | | - * JavaScript Cookie v2.2.1 |
3 | | - * https://github.com/js-cookie/js-cookie |
4 | | - * |
5 | | - * Copyright 2006, 2015 Klaus Hartl & Fagner Brack |
6 | | - * Released under the MIT license |
7 | | - */ |
8 | | -;(function (factory) { |
9 | | - var registeredInModuleLoader; |
10 | | - if (typeof define === 'function' && define.amd) { |
11 | | - define(factory); |
12 | | - registeredInModuleLoader = true; |
13 | | - } |
14 | | - if (typeof exports === 'object') { |
15 | | - module.exports = factory(); |
16 | | - registeredInModuleLoader = true; |
17 | | - } |
18 | | - if (!registeredInModuleLoader) { |
19 | | - var OldCookies = window.Cookies; |
20 | | - var api = window.Cookies = factory(); |
21 | | - api.noConflict = function () { |
22 | | - window.Cookies = OldCookies; |
23 | | - return api; |
24 | | - }; |
25 | | - } |
26 | | -}(function () { |
27 | | - function extend () { |
28 | | - var i = 0; |
29 | | - var result = {}; |
30 | | - for (; i < arguments.length; i++) { |
31 | | - var attributes = arguments[ i ]; |
32 | | - for (var key in attributes) { |
33 | | - result[key] = attributes[key]; |
34 | | - } |
35 | | - } |
36 | | - return result; |
37 | | - } |
38 | | - |
39 | | - function decode (s) { |
40 | | - return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent); |
41 | | - } |
42 | | - |
43 | | - function init (converter) { |
44 | | - function api() {} |
45 | | - |
46 | | - function set (key, value, attributes) { |
47 | | - if (typeof document === 'undefined') { |
48 | | - return; |
49 | | - } |
50 | | - |
51 | | - attributes = extend({ |
52 | | - path: '/' |
53 | | - }, api.defaults, attributes); |
54 | | - |
55 | | - if (typeof attributes.expires === 'number') { |
56 | | - attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5); |
57 | | - } |
58 | | - |
59 | | - // We're using "expires" because "max-age" is not supported by IE |
60 | | - attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; |
61 | | - |
62 | | - try { |
63 | | - var result = JSON.stringify(value); |
64 | | - if (/^[\{\[]/.test(result)) { |
65 | | - value = result; |
66 | | - } |
67 | | - } catch (e) {} |
68 | | - |
69 | | - value = converter.write ? |
70 | | - converter.write(value, key) : |
71 | | - encodeURIComponent(String(value)) |
72 | | - .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); |
73 | | - |
74 | | - key = encodeURIComponent(String(key)) |
75 | | - .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent) |
76 | | - .replace(/[\(\)]/g, escape); |
77 | | - |
78 | | - var stringifiedAttributes = ''; |
79 | | - for (var attributeName in attributes) { |
80 | | - if (!attributes[attributeName]) { |
81 | | - continue; |
82 | | - } |
83 | | - stringifiedAttributes += '; ' + attributeName; |
84 | | - if (attributes[attributeName] === true) { |
85 | | - continue; |
86 | | - } |
87 | | - |
88 | | - // Considers RFC 6265 section 5.2: |
89 | | - // ... |
90 | | - // 3. If the remaining unparsed-attributes contains a %x3B (";") |
91 | | - // character: |
92 | | - // Consume the characters of the unparsed-attributes up to, |
93 | | - // not including, the first %x3B (";") character. |
94 | | - // ... |
95 | | - stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; |
96 | | - } |
97 | | - |
98 | | - return (document.cookie = key + '=' + value + stringifiedAttributes); |
99 | | - } |
100 | | - |
101 | | - function get (key, json) { |
102 | | - if (typeof document === 'undefined') { |
103 | | - return; |
104 | | - } |
105 | | - |
106 | | - var jar = {}; |
107 | | - // To prevent the for loop in the first place assign an empty array |
108 | | - // in case there are no cookies at all. |
109 | | - var cookies = document.cookie ? document.cookie.split('; ') : []; |
110 | | - var i = 0; |
111 | | - |
112 | | - for (; i < cookies.length; i++) { |
113 | | - var parts = cookies[i].split('='); |
114 | | - var cookie = parts.slice(1).join('='); |
115 | | - |
116 | | - if (!json && cookie.charAt(0) === '"') { |
117 | | - cookie = cookie.slice(1, -1); |
118 | | - } |
119 | | - |
120 | | - try { |
121 | | - var name = decode(parts[0]); |
122 | | - cookie = (converter.read || converter)(cookie, name) || |
123 | | - decode(cookie); |
124 | | - |
125 | | - if (json) { |
126 | | - try { |
127 | | - cookie = JSON.parse(cookie); |
128 | | - } catch (e) {} |
129 | | - } |
130 | | - |
131 | | - jar[name] = cookie; |
132 | | - |
133 | | - if (key === name) { |
134 | | - break; |
135 | | - } |
136 | | - } catch (e) {} |
137 | | - } |
138 | | - |
139 | | - return key ? jar[key] : jar; |
140 | | - } |
141 | | - |
142 | | - api.set = set; |
143 | | - api.get = function (key) { |
144 | | - return get(key, false /* read as raw */); |
145 | | - }; |
146 | | - api.getJSON = function (key) { |
147 | | - return get(key, true /* read as json */); |
148 | | - }; |
149 | | - api.remove = function (key, attributes) { |
150 | | - set(key, '', extend(attributes, { |
151 | | - expires: -1 |
152 | | - })); |
153 | | - }; |
154 | | - |
155 | | - api.defaults = {}; |
156 | | - |
157 | | - api.withConverter = init; |
158 | | - |
159 | | - return api; |
160 | | - } |
161 | | - |
162 | | - return init(function () {}); |
163 | | -})); |
| 1 | +/*! js-cookie v3.0.1 | MIT */ |
| 2 | +; |
| 3 | +(function (global, factory) { |
| 4 | + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 5 | + typeof define === 'function' && define.amd ? define(factory) : |
| 6 | + (global = global || self, (function () { |
| 7 | + var current = global.Cookies; |
| 8 | + var exports = global.Cookies = factory(); |
| 9 | + exports.noConflict = function () { global.Cookies = current; return exports; }; |
| 10 | + }())); |
| 11 | +}(this, (function () { 'use strict'; |
| 12 | + |
| 13 | + /* eslint-disable no-var */ |
| 14 | + function assign (target) { |
| 15 | + for (var i = 1; i < arguments.length; i++) { |
| 16 | + var source = arguments[i]; |
| 17 | + for (var key in source) { |
| 18 | + target[key] = source[key]; |
| 19 | + } |
| 20 | + } |
| 21 | + return target |
| 22 | + } |
| 23 | + /* eslint-enable no-var */ |
| 24 | + |
| 25 | + /* eslint-disable no-var */ |
| 26 | + var defaultConverter = { |
| 27 | + read: function (value) { |
| 28 | + if (value[0] === '"') { |
| 29 | + value = value.slice(1, -1); |
| 30 | + } |
| 31 | + return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent) |
| 32 | + }, |
| 33 | + write: function (value) { |
| 34 | + return encodeURIComponent(value).replace( |
| 35 | + /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, |
| 36 | + decodeURIComponent |
| 37 | + ) |
| 38 | + } |
| 39 | + }; |
| 40 | + /* eslint-enable no-var */ |
| 41 | + |
| 42 | + /* eslint-disable no-var */ |
| 43 | + |
| 44 | + function init (converter, defaultAttributes) { |
| 45 | + function set (key, value, attributes) { |
| 46 | + if (typeof document === 'undefined') { |
| 47 | + return |
| 48 | + } |
| 49 | + |
| 50 | + attributes = assign({}, defaultAttributes, attributes); |
| 51 | + |
| 52 | + if (typeof attributes.expires === 'number') { |
| 53 | + attributes.expires = new Date(Date.now() + attributes.expires * 864e5); |
| 54 | + } |
| 55 | + if (attributes.expires) { |
| 56 | + attributes.expires = attributes.expires.toUTCString(); |
| 57 | + } |
| 58 | + |
| 59 | + key = encodeURIComponent(key) |
| 60 | + .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent) |
| 61 | + .replace(/[()]/g, escape); |
| 62 | + |
| 63 | + var stringifiedAttributes = ''; |
| 64 | + for (var attributeName in attributes) { |
| 65 | + if (!attributes[attributeName]) { |
| 66 | + continue |
| 67 | + } |
| 68 | + |
| 69 | + stringifiedAttributes += '; ' + attributeName; |
| 70 | + |
| 71 | + if (attributes[attributeName] === true) { |
| 72 | + continue |
| 73 | + } |
| 74 | + |
| 75 | + // Considers RFC 6265 section 5.2: |
| 76 | + // ... |
| 77 | + // 3. If the remaining unparsed-attributes contains a %x3B (";") |
| 78 | + // character: |
| 79 | + // Consume the characters of the unparsed-attributes up to, |
| 80 | + // not including, the first %x3B (";") character. |
| 81 | + // ... |
| 82 | + stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; |
| 83 | + } |
| 84 | + |
| 85 | + return (document.cookie = |
| 86 | + key + '=' + converter.write(value, key) + stringifiedAttributes) |
| 87 | + } |
| 88 | + |
| 89 | + function get (key) { |
| 90 | + if (typeof document === 'undefined' || (arguments.length && !key)) { |
| 91 | + return |
| 92 | + } |
| 93 | + |
| 94 | + // To prevent the for loop in the first place assign an empty array |
| 95 | + // in case there are no cookies at all. |
| 96 | + var cookies = document.cookie ? document.cookie.split('; ') : []; |
| 97 | + var jar = {}; |
| 98 | + for (var i = 0; i < cookies.length; i++) { |
| 99 | + var parts = cookies[i].split('='); |
| 100 | + var value = parts.slice(1).join('='); |
| 101 | + |
| 102 | + try { |
| 103 | + var foundKey = decodeURIComponent(parts[0]); |
| 104 | + jar[foundKey] = converter.read(value, foundKey); |
| 105 | + |
| 106 | + if (key === foundKey) { |
| 107 | + break |
| 108 | + } |
| 109 | + } catch (e) {} |
| 110 | + } |
| 111 | + |
| 112 | + return key ? jar[key] : jar |
| 113 | + } |
| 114 | + |
| 115 | + return Object.create( |
| 116 | + { |
| 117 | + set: set, |
| 118 | + get: get, |
| 119 | + remove: function (key, attributes) { |
| 120 | + set( |
| 121 | + key, |
| 122 | + '', |
| 123 | + assign({}, attributes, { |
| 124 | + expires: -1 |
| 125 | + }) |
| 126 | + ); |
| 127 | + }, |
| 128 | + withAttributes: function (attributes) { |
| 129 | + return init(this.converter, assign({}, this.attributes, attributes)) |
| 130 | + }, |
| 131 | + withConverter: function (converter) { |
| 132 | + return init(assign({}, this.converter, converter), this.attributes) |
| 133 | + } |
| 134 | + }, |
| 135 | + { |
| 136 | + attributes: { value: Object.freeze(defaultAttributes) }, |
| 137 | + converter: { value: Object.freeze(converter) } |
| 138 | + } |
| 139 | + ) |
| 140 | + } |
| 141 | + |
| 142 | + var api = init(defaultConverter, { path: '/' }); |
| 143 | + /* eslint-enable no-var */ |
| 144 | + |
| 145 | + return api; |
| 146 | + |
| 147 | +}))); |
0 commit comments