1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- Object.defineProperty(exports, '__esModule', { value: true });
- function parseCookie(str) {
- const obj = {};
- let index = 0;
- while (index < str.length) {
- const eqIdx = str.indexOf('=', index);
-
- if (eqIdx === -1) {
- break;
- }
- let endIdx = str.indexOf(';', index);
- if (endIdx === -1) {
- endIdx = str.length;
- } else if (endIdx < eqIdx) {
-
- index = str.lastIndexOf(';', eqIdx - 1) + 1;
- continue;
- }
- const key = str.slice(index, eqIdx).trim();
-
- if (undefined === obj[key]) {
- let val = str.slice(eqIdx + 1, endIdx).trim();
-
- if (val.charCodeAt(0) === 0x22) {
- val = val.slice(1, -1);
- }
- try {
- obj[key] = val.indexOf('%') !== -1 ? decodeURIComponent(val) : val;
- } catch (e) {
- obj[key] = val;
- }
- }
- index = endIdx + 1;
- }
- return obj;
- }
- exports.parseCookie = parseCookie;
|