cookie-es 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -12
- package/dist/index.mjs +0 -99
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/cookie/types.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Parse options.
|
|
4
3
|
*/
|
|
@@ -130,8 +129,6 @@ interface SetCookie {
|
|
|
130
129
|
* Backward compatibility serialize options.
|
|
131
130
|
*/
|
|
132
131
|
type CookieSerializeOptions = CookieStringifyOptions & Omit<SetCookie, "name" | "value">;
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/cookie/parse.d.ts
|
|
135
132
|
/**
|
|
136
133
|
* Parse a `Cookie` header.
|
|
137
134
|
*
|
|
@@ -142,8 +139,6 @@ declare function parse(str: string, options: CookieParseOptions & {
|
|
|
142
139
|
allowMultiple: true;
|
|
143
140
|
}): MultiCookies;
|
|
144
141
|
declare function parse(str: string, options?: CookieParseOptions): Cookies;
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/cookie/serialize.d.ts
|
|
147
142
|
/**
|
|
148
143
|
* Stringifies an object into an HTTP `Cookie` header.
|
|
149
144
|
*/
|
|
@@ -159,8 +154,6 @@ declare function stringifyCookie(cookie: Cookies, options?: CookieStringifyOptio
|
|
|
159
154
|
*/
|
|
160
155
|
declare function serialize(cookie: SetCookie, options?: CookieStringifyOptions): string;
|
|
161
156
|
declare function serialize(name: string, val: string, options?: CookieSerializeOptions): string;
|
|
162
|
-
//#endregion
|
|
163
|
-
//#region src/set-cookie/types.d.ts
|
|
164
157
|
interface SetCookieParseOptions {
|
|
165
158
|
/**
|
|
166
159
|
* Custom decode function to use on cookie values.
|
|
@@ -225,14 +218,10 @@ interface SetCookie$1 {
|
|
|
225
218
|
priority?: "low" | "medium" | "high" | undefined;
|
|
226
219
|
[key: string]: unknown;
|
|
227
220
|
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/set-cookie/parse.d.ts
|
|
230
221
|
/**
|
|
231
222
|
* Parse a [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header string into an object.
|
|
232
223
|
*/
|
|
233
224
|
declare function parseSetCookie(str: string, options?: SetCookieParseOptions): SetCookie$1 | undefined;
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/set-cookie/split.d.ts
|
|
236
225
|
/**
|
|
237
226
|
* Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
238
227
|
* that are within a single set-cookie field-value, such as in the Expires portion.
|
|
@@ -240,5 +229,4 @@ declare function parseSetCookie(str: string, options?: SetCookieParseOptions): S
|
|
|
240
229
|
* See https://tools.ietf.org/html/rfc2616#section-4.2
|
|
241
230
|
*/
|
|
242
231
|
declare function splitSetCookieString(cookiesString: string | string[]): string[];
|
|
243
|
-
//#endregion
|
|
244
232
|
export { type CookieParseOptions, type CookieSerializeOptions, type CookieStringifyOptions, type Cookies, type MultiCookies, type SetCookie, type SetCookieParseOptions, parse, parse as parseCookie, parseSetCookie, serialize, serialize as serializeCookie, splitSetCookieString, stringifyCookie };
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
//#region src/_utils.ts
|
|
2
|
-
/**
|
|
3
|
-
* RFC 6265bis cookie-age-limit: 400 days in seconds.
|
|
4
|
-
*/
|
|
5
1
|
const COOKIE_MAX_AGE_LIMIT = 400 * 24 * 60 * 60;
|
|
6
|
-
/**
|
|
7
|
-
* Find the `;` character between `min` and `len` in str.
|
|
8
|
-
*/
|
|
9
2
|
function endIndex(str, min, len) {
|
|
10
3
|
const index = str.indexOf(";", min);
|
|
11
4
|
return index === -1 ? len : index;
|
|
12
5
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Find the `=` character between `min` and `max` in str.
|
|
15
|
-
*/
|
|
16
6
|
function eqIndex(str, min, max) {
|
|
17
7
|
const index = str.indexOf("=", min);
|
|
18
8
|
return index < max ? index : -1;
|
|
19
9
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Slice out a value between start to max.
|
|
22
|
-
*/
|
|
23
10
|
function valueSlice(str, min, max) {
|
|
24
11
|
if (min === max) return "";
|
|
25
12
|
let start = min;
|
|
@@ -35,8 +22,6 @@ function valueSlice(str, min, max) {
|
|
|
35
22
|
}
|
|
36
23
|
return str.slice(start, end);
|
|
37
24
|
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/cookie/parse.ts
|
|
40
25
|
const NullObject = /* @__PURE__ */ (() => {
|
|
41
26
|
const C = function() {};
|
|
42
27
|
C.prototype = Object.create(null);
|
|
@@ -73,9 +58,6 @@ function parse(str, options) {
|
|
|
73
58
|
} while (index < len);
|
|
74
59
|
return obj;
|
|
75
60
|
}
|
|
76
|
-
/**
|
|
77
|
-
* URL-decode string value. Optimized to skip native call when no %.
|
|
78
|
-
*/
|
|
79
61
|
function decode(str) {
|
|
80
62
|
if (!str.includes("%")) return str;
|
|
81
63
|
try {
|
|
@@ -84,72 +66,11 @@ function decode(str) {
|
|
|
84
66
|
return str;
|
|
85
67
|
}
|
|
86
68
|
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/cookie/serialize.ts
|
|
89
|
-
/**
|
|
90
|
-
* RegExp to match cookie-name in RFC 6265bis sec 4.1.1
|
|
91
|
-
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
|
|
92
|
-
* which has been replaced by the token definition in RFC 7230 appendix B.
|
|
93
|
-
*
|
|
94
|
-
* cookie-name = token
|
|
95
|
-
* token = 1*tchar
|
|
96
|
-
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
|
|
97
|
-
* "*" / "+" / "-" / "." / "^" / "_" /
|
|
98
|
-
* "`" / "|" / "~" / DIGIT / ALPHA
|
|
99
|
-
*
|
|
100
|
-
* Note: Allowing more characters - https://github.com/jshttp/cookie/issues/191
|
|
101
|
-
* Allow same range as cookie value, except `=`, which delimits end of name.
|
|
102
|
-
*/
|
|
103
69
|
const cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
|
|
104
|
-
/**
|
|
105
|
-
* RegExp to match cookie-value in RFC 6265bis sec 4.1.1
|
|
106
|
-
*
|
|
107
|
-
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
|
108
|
-
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
|
109
|
-
* ; US-ASCII characters excluding CTLs,
|
|
110
|
-
* ; whitespace DQUOTE, comma, semicolon,
|
|
111
|
-
* ; and backslash
|
|
112
|
-
*
|
|
113
|
-
* Allowing more characters: https://github.com/jshttp/cookie/issues/191
|
|
114
|
-
* Comma, backslash, and DQUOTE are not part of the parsing algorithm.
|
|
115
|
-
*/
|
|
116
70
|
const cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
|
|
117
|
-
/**
|
|
118
|
-
* RegExp to match domain-value in RFC 6265bis sec 4.1.1
|
|
119
|
-
*
|
|
120
|
-
* domain-value = <subdomain>
|
|
121
|
-
* ; defined in [RFC1034], Section 3.5, as
|
|
122
|
-
* ; enhanced by [RFC1123], Section 2.1
|
|
123
|
-
* <subdomain> = <label> | <subdomain> "." <label>
|
|
124
|
-
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
|
|
125
|
-
* Labels must be 63 characters or less.
|
|
126
|
-
* 'let-dig' not 'letter' in the first char, per RFC1123
|
|
127
|
-
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
|
|
128
|
-
* <let-dig-hyp> = <let-dig> | "-"
|
|
129
|
-
* <let-dig> = <letter> | <digit>
|
|
130
|
-
* <letter> = any one of the 52 alphabetic characters A through Z in
|
|
131
|
-
* upper case and a through z in lower case
|
|
132
|
-
* <digit> = any one of the ten digits 0 through 9
|
|
133
|
-
*
|
|
134
|
-
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
|
|
135
|
-
*
|
|
136
|
-
* > (Note that a leading %x2E ("."), if present, is ignored even though that
|
|
137
|
-
* character is not permitted, but a trailing %x2E ("."), if present, will
|
|
138
|
-
* cause the user agent to ignore the attribute.)
|
|
139
|
-
*/
|
|
140
71
|
const domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
141
|
-
/**
|
|
142
|
-
* RegExp to match path-value in RFC 6265bis sec 4.1.1
|
|
143
|
-
*
|
|
144
|
-
* path-value = <any CHAR except CTLs or ";">
|
|
145
|
-
* CHAR = %x01-7F
|
|
146
|
-
* ; defined in RFC 5234 appendix B.1
|
|
147
|
-
*/
|
|
148
72
|
const pathValueRegExp = /^[\u0020-\u003A\u003C-\u007E]*$/;
|
|
149
73
|
const __toString = Object.prototype.toString;
|
|
150
|
-
/**
|
|
151
|
-
* Stringifies an object into an HTTP `Cookie` header.
|
|
152
|
-
*/
|
|
153
74
|
function stringifyCookie(cookie, options) {
|
|
154
75
|
const enc = options?.encode || encodeURIComponent;
|
|
155
76
|
const keys = Object.keys(cookie);
|
|
@@ -234,22 +155,11 @@ function serialize(_name, _val, _opts) {
|
|
|
234
155
|
}
|
|
235
156
|
return str;
|
|
236
157
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Determine if value is a Date.
|
|
239
|
-
*/
|
|
240
158
|
function isDate(val) {
|
|
241
159
|
return __toString.call(val) === "[object Date]";
|
|
242
160
|
}
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/set-cookie/parse.ts
|
|
245
|
-
/**
|
|
246
|
-
* RegExp to match max-age-value in RFC 6265 sec 5.6.2
|
|
247
|
-
*/
|
|
248
161
|
const maxAgeRegExp = /^-?\d+$/;
|
|
249
162
|
const _nullProto = Object.getPrototypeOf({});
|
|
250
|
-
/**
|
|
251
|
-
* Parse a [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header string into an object.
|
|
252
|
-
*/
|
|
253
163
|
function parseSetCookie(str, options) {
|
|
254
164
|
const len = str.length;
|
|
255
165
|
let _endIdx = len;
|
|
@@ -354,14 +264,6 @@ function _decode(value, decode) {
|
|
|
354
264
|
return value;
|
|
355
265
|
}
|
|
356
266
|
}
|
|
357
|
-
//#endregion
|
|
358
|
-
//#region src/set-cookie/split.ts
|
|
359
|
-
/**
|
|
360
|
-
* Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
361
|
-
* that are within a single set-cookie field-value, such as in the Expires portion.
|
|
362
|
-
*
|
|
363
|
-
* See https://tools.ietf.org/html/rfc2616#section-4.2
|
|
364
|
-
*/
|
|
365
267
|
function splitSetCookieString(cookiesString) {
|
|
366
268
|
if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
|
|
367
269
|
if (typeof cookiesString !== "string") return [];
|
|
@@ -403,5 +305,4 @@ function splitSetCookieString(cookiesString) {
|
|
|
403
305
|
}
|
|
404
306
|
return cookiesStrings;
|
|
405
307
|
}
|
|
406
|
-
//#endregion
|
|
407
308
|
export { parse, parse as parseCookie, parseSetCookie, serialize, serialize as serializeCookie, splitSetCookieString, stringifyCookie };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cookie-es",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "unjs/cookie-es",
|
|
6
6
|
"files": [
|
|
@@ -27,10 +27,12 @@
|
|
|
27
27
|
"changelogen": "^0.6.2",
|
|
28
28
|
"cookie": "^1.1.1",
|
|
29
29
|
"eslint-config-unjs": "^0.6.2",
|
|
30
|
+
"magic-string": "^0.30.21",
|
|
30
31
|
"mitata": "^1.0.34",
|
|
31
32
|
"obuild": "^0.4.32",
|
|
32
33
|
"oxfmt": "^0.41.0",
|
|
33
34
|
"oxlint": "^1.56.0",
|
|
35
|
+
"rolldown": "1.0.0-rc.11",
|
|
34
36
|
"typescript": "^6.0.2",
|
|
35
37
|
"vitest": "^4.1.1"
|
|
36
38
|
},
|