cookie-es 1.0.0 → 1.1.0
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/README.md +41 -6
- package/dist/index.cjs +21 -9
- package/dist/index.d.cts +151 -0
- package/dist/index.d.mts +151 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +21 -9
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
# cookie-es
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
<!-- automd:badges bundlejs -->
|
|
5
|
+
|
|
6
|
+
[](https://npmjs.com/package/cookie-es)
|
|
7
|
+
[](https://npmjs.com/package/cookie-es)
|
|
8
|
+
[](https://bundlejs.com/?q=cookie-es)
|
|
9
|
+
|
|
10
|
+
<!-- /automd -->
|
|
5
11
|
|
|
6
12
|
ESM build of [cookie](https://www.npmjs.com/package/cookie) with bundled types.
|
|
7
13
|
|
|
@@ -9,24 +15,53 @@ ESM build of [cookie](https://www.npmjs.com/package/cookie) with bundled types.
|
|
|
9
15
|
|
|
10
16
|
Install:
|
|
11
17
|
|
|
18
|
+
<!-- automd:pm-install -->
|
|
19
|
+
|
|
12
20
|
```sh
|
|
21
|
+
# ✨ Auto-detect
|
|
22
|
+
npx nypm install cookie-es
|
|
23
|
+
|
|
13
24
|
# npm
|
|
14
|
-
npm
|
|
25
|
+
npm install cookie-es
|
|
15
26
|
|
|
16
27
|
# yarn
|
|
17
28
|
yarn add cookie-es
|
|
29
|
+
|
|
30
|
+
# pnpm
|
|
31
|
+
pnpm install cookie-es
|
|
32
|
+
|
|
33
|
+
# bun
|
|
34
|
+
bun install cookie-es
|
|
18
35
|
```
|
|
19
36
|
|
|
37
|
+
<!-- /automd-->
|
|
38
|
+
|
|
20
39
|
Import:
|
|
21
40
|
|
|
41
|
+
|
|
42
|
+
<!-- automd:jsimport cdn cjs src=./src/index.ts -->
|
|
43
|
+
|
|
44
|
+
**ESM** (Node.js, Bun)
|
|
45
|
+
|
|
22
46
|
```js
|
|
23
|
-
|
|
24
|
-
|
|
47
|
+
import { parse, serialize } from "cookie-es";
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**CommonJS** (Legacy Node.js)
|
|
25
51
|
|
|
26
|
-
|
|
27
|
-
const { parse, serialize } = require(
|
|
52
|
+
```js
|
|
53
|
+
const { parse, serialize } = require("cookie-es");
|
|
28
54
|
```
|
|
29
55
|
|
|
56
|
+
**CDN** (Deno, Bun and Browsers)
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { parse, serialize } from "https://esm.sh/cookie-es";
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
<!-- /automd -->
|
|
63
|
+
|
|
64
|
+
|
|
30
65
|
## License
|
|
31
66
|
|
|
32
67
|
[MIT](./LICENSE)
|
package/dist/index.cjs
CHANGED
|
@@ -81,38 +81,50 @@ function serialize(name, value, options) {
|
|
|
81
81
|
if (opt.priority) {
|
|
82
82
|
const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
83
83
|
switch (priority) {
|
|
84
|
-
case "low":
|
|
84
|
+
case "low": {
|
|
85
85
|
str += "; Priority=Low";
|
|
86
86
|
break;
|
|
87
|
-
|
|
87
|
+
}
|
|
88
|
+
case "medium": {
|
|
88
89
|
str += "; Priority=Medium";
|
|
89
90
|
break;
|
|
90
|
-
|
|
91
|
+
}
|
|
92
|
+
case "high": {
|
|
91
93
|
str += "; Priority=High";
|
|
92
94
|
break;
|
|
93
|
-
|
|
95
|
+
}
|
|
96
|
+
default: {
|
|
94
97
|
throw new TypeError("option priority is invalid");
|
|
98
|
+
}
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
if (opt.sameSite) {
|
|
98
102
|
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
99
103
|
switch (sameSite) {
|
|
100
|
-
case true:
|
|
104
|
+
case true: {
|
|
101
105
|
str += "; SameSite=Strict";
|
|
102
106
|
break;
|
|
103
|
-
|
|
107
|
+
}
|
|
108
|
+
case "lax": {
|
|
104
109
|
str += "; SameSite=Lax";
|
|
105
110
|
break;
|
|
106
|
-
|
|
111
|
+
}
|
|
112
|
+
case "strict": {
|
|
107
113
|
str += "; SameSite=Strict";
|
|
108
114
|
break;
|
|
109
|
-
|
|
115
|
+
}
|
|
116
|
+
case "none": {
|
|
110
117
|
str += "; SameSite=None";
|
|
111
118
|
break;
|
|
112
|
-
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
113
121
|
throw new TypeError("option sameSite is invalid");
|
|
122
|
+
}
|
|
114
123
|
}
|
|
115
124
|
}
|
|
125
|
+
if (opt.partitioned) {
|
|
126
|
+
str += "; Partitioned";
|
|
127
|
+
}
|
|
116
128
|
return str;
|
|
117
129
|
}
|
|
118
130
|
function isDate(val) {
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic HTTP cookie parser and serializer for HTTP servers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Additional serialization options
|
|
6
|
+
*/
|
|
7
|
+
interface CookieSerializeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
|
|
10
|
+
* domain is set, and most clients will consider the cookie to apply to only
|
|
11
|
+
* the current domain.
|
|
12
|
+
*/
|
|
13
|
+
domain?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Specifies a function that will be used to encode a cookie's value. Since
|
|
16
|
+
* value of a cookie has a limited character set (and must be a simple
|
|
17
|
+
* string), this function can be used to encode a value into a string suited
|
|
18
|
+
* for a cookie's value.
|
|
19
|
+
*
|
|
20
|
+
* The default function is the global `encodeURIComponent`, which will
|
|
21
|
+
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
|
22
|
+
* any that fall outside of the cookie range.
|
|
23
|
+
*/
|
|
24
|
+
encode?(value: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
|
|
27
|
+
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
|
28
|
+
* it on a condition like exiting a web browser application.
|
|
29
|
+
*
|
|
30
|
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
|
31
|
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
32
|
+
* possible not all clients by obey this, so if both are set, they should
|
|
33
|
+
* point to the same date and time.
|
|
34
|
+
*/
|
|
35
|
+
expires?: Date | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
|
|
38
|
+
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
|
39
|
+
* default, the `HttpOnly` attribute is not set.
|
|
40
|
+
*
|
|
41
|
+
* *Note* be careful when setting this to true, as compliant clients will
|
|
42
|
+
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
|
43
|
+
*/
|
|
44
|
+
httpOnly?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Specifies the number (in seconds) to be the value for the `Max-Age`
|
|
47
|
+
* `Set-Cookie` attribute. The given number will be converted to an integer
|
|
48
|
+
* by rounding down. By default, no maximum age is set.
|
|
49
|
+
*
|
|
50
|
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
|
51
|
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
52
|
+
* possible not all clients by obey this, so if both are set, they should
|
|
53
|
+
* point to the same date and time.
|
|
54
|
+
*/
|
|
55
|
+
maxAge?: number | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
|
|
58
|
+
* By default, the path is considered the "default path".
|
|
59
|
+
*/
|
|
60
|
+
path?: string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
|
|
63
|
+
*
|
|
64
|
+
* - `'low'` will set the `Priority` attribute to `Low`.
|
|
65
|
+
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
|
|
66
|
+
* - `'high'` will set the `Priority` attribute to `High`.
|
|
67
|
+
*
|
|
68
|
+
* More information about the different priority levels can be found in
|
|
69
|
+
* [the specification][rfc-west-cookie-priority-00-4.1].
|
|
70
|
+
*
|
|
71
|
+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
72
|
+
* This also means many clients may ignore this attribute until they understand it.
|
|
73
|
+
*/
|
|
74
|
+
priority?: "low" | "medium" | "high" | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
|
|
77
|
+
*
|
|
78
|
+
* - `true` will set the `SameSite` attribute to `Strict` for strict same
|
|
79
|
+
* site enforcement.
|
|
80
|
+
* - `false` will not set the `SameSite` attribute.
|
|
81
|
+
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
|
|
82
|
+
* enforcement.
|
|
83
|
+
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
|
|
84
|
+
* site enforcement.
|
|
85
|
+
* - `'none'` will set the SameSite attribute to None for an explicit
|
|
86
|
+
* cross-site cookie.
|
|
87
|
+
*
|
|
88
|
+
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
|
|
89
|
+
*
|
|
90
|
+
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
|
91
|
+
*/
|
|
92
|
+
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
|
|
95
|
+
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
|
96
|
+
*
|
|
97
|
+
* *Note* be careful when setting this to `true`, as compliant clients will
|
|
98
|
+
* not send the cookie back to the server in the future if the browser does
|
|
99
|
+
* not have an HTTPS connection.
|
|
100
|
+
*/
|
|
101
|
+
secure?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
|
|
104
|
+
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
|
|
105
|
+
* `Partitioned` attribute is not set.
|
|
106
|
+
*
|
|
107
|
+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
108
|
+
* This also means many clients may ignore this attribute until they understand it.
|
|
109
|
+
*
|
|
110
|
+
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
|
|
111
|
+
*/
|
|
112
|
+
partitioned?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Additional parsing options
|
|
116
|
+
*/
|
|
117
|
+
interface CookieParseOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Specifies a function that will be used to decode a cookie's value. Since
|
|
120
|
+
* the value of a cookie has a limited character set (and must be a simple
|
|
121
|
+
* string), this function can be used to decode a previously-encoded cookie
|
|
122
|
+
* value into a JavaScript string or other object.
|
|
123
|
+
*
|
|
124
|
+
* The default function is the global `decodeURIComponent`, which will decode
|
|
125
|
+
* any URL-encoded sequences into their byte representations.
|
|
126
|
+
*
|
|
127
|
+
* *Note* if an error is thrown from this function, the original, non-decoded
|
|
128
|
+
* cookie value will be returned as the cookie's value.
|
|
129
|
+
*/
|
|
130
|
+
decode?(value: string): string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
135
|
+
* name-value pairs.
|
|
136
|
+
*
|
|
137
|
+
* @param str the string representing a `Cookie` header value
|
|
138
|
+
* @param [options] object containing parsing options
|
|
139
|
+
*/
|
|
140
|
+
declare function parse(str: string, options?: CookieParseOptions): Record<string, string>;
|
|
141
|
+
/**
|
|
142
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
|
143
|
+
*
|
|
144
|
+
* @param name the name for the cookie
|
|
145
|
+
* @param value value to set the cookie to
|
|
146
|
+
* @param [options] object containing serialization options
|
|
147
|
+
* @throws {TypeError} when `maxAge` options is invalid
|
|
148
|
+
*/
|
|
149
|
+
declare function serialize(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
150
|
+
|
|
151
|
+
export { type CookieParseOptions, type CookieSerializeOptions, parse, serialize };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic HTTP cookie parser and serializer for HTTP servers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Additional serialization options
|
|
6
|
+
*/
|
|
7
|
+
interface CookieSerializeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
|
|
10
|
+
* domain is set, and most clients will consider the cookie to apply to only
|
|
11
|
+
* the current domain.
|
|
12
|
+
*/
|
|
13
|
+
domain?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Specifies a function that will be used to encode a cookie's value. Since
|
|
16
|
+
* value of a cookie has a limited character set (and must be a simple
|
|
17
|
+
* string), this function can be used to encode a value into a string suited
|
|
18
|
+
* for a cookie's value.
|
|
19
|
+
*
|
|
20
|
+
* The default function is the global `encodeURIComponent`, which will
|
|
21
|
+
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
|
22
|
+
* any that fall outside of the cookie range.
|
|
23
|
+
*/
|
|
24
|
+
encode?(value: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
|
|
27
|
+
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
|
28
|
+
* it on a condition like exiting a web browser application.
|
|
29
|
+
*
|
|
30
|
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
|
31
|
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
32
|
+
* possible not all clients by obey this, so if both are set, they should
|
|
33
|
+
* point to the same date and time.
|
|
34
|
+
*/
|
|
35
|
+
expires?: Date | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
|
|
38
|
+
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
|
39
|
+
* default, the `HttpOnly` attribute is not set.
|
|
40
|
+
*
|
|
41
|
+
* *Note* be careful when setting this to true, as compliant clients will
|
|
42
|
+
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
|
43
|
+
*/
|
|
44
|
+
httpOnly?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Specifies the number (in seconds) to be the value for the `Max-Age`
|
|
47
|
+
* `Set-Cookie` attribute. The given number will be converted to an integer
|
|
48
|
+
* by rounding down. By default, no maximum age is set.
|
|
49
|
+
*
|
|
50
|
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
|
51
|
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
|
52
|
+
* possible not all clients by obey this, so if both are set, they should
|
|
53
|
+
* point to the same date and time.
|
|
54
|
+
*/
|
|
55
|
+
maxAge?: number | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
|
|
58
|
+
* By default, the path is considered the "default path".
|
|
59
|
+
*/
|
|
60
|
+
path?: string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
|
|
63
|
+
*
|
|
64
|
+
* - `'low'` will set the `Priority` attribute to `Low`.
|
|
65
|
+
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
|
|
66
|
+
* - `'high'` will set the `Priority` attribute to `High`.
|
|
67
|
+
*
|
|
68
|
+
* More information about the different priority levels can be found in
|
|
69
|
+
* [the specification][rfc-west-cookie-priority-00-4.1].
|
|
70
|
+
*
|
|
71
|
+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
72
|
+
* This also means many clients may ignore this attribute until they understand it.
|
|
73
|
+
*/
|
|
74
|
+
priority?: "low" | "medium" | "high" | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
|
|
77
|
+
*
|
|
78
|
+
* - `true` will set the `SameSite` attribute to `Strict` for strict same
|
|
79
|
+
* site enforcement.
|
|
80
|
+
* - `false` will not set the `SameSite` attribute.
|
|
81
|
+
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
|
|
82
|
+
* enforcement.
|
|
83
|
+
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
|
|
84
|
+
* site enforcement.
|
|
85
|
+
* - `'none'` will set the SameSite attribute to None for an explicit
|
|
86
|
+
* cross-site cookie.
|
|
87
|
+
*
|
|
88
|
+
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
|
|
89
|
+
*
|
|
90
|
+
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
|
91
|
+
*/
|
|
92
|
+
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
|
|
95
|
+
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
|
96
|
+
*
|
|
97
|
+
* *Note* be careful when setting this to `true`, as compliant clients will
|
|
98
|
+
* not send the cookie back to the server in the future if the browser does
|
|
99
|
+
* not have an HTTPS connection.
|
|
100
|
+
*/
|
|
101
|
+
secure?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
|
|
104
|
+
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
|
|
105
|
+
* `Partitioned` attribute is not set.
|
|
106
|
+
*
|
|
107
|
+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
108
|
+
* This also means many clients may ignore this attribute until they understand it.
|
|
109
|
+
*
|
|
110
|
+
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
|
|
111
|
+
*/
|
|
112
|
+
partitioned?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Additional parsing options
|
|
116
|
+
*/
|
|
117
|
+
interface CookieParseOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Specifies a function that will be used to decode a cookie's value. Since
|
|
120
|
+
* the value of a cookie has a limited character set (and must be a simple
|
|
121
|
+
* string), this function can be used to decode a previously-encoded cookie
|
|
122
|
+
* value into a JavaScript string or other object.
|
|
123
|
+
*
|
|
124
|
+
* The default function is the global `decodeURIComponent`, which will decode
|
|
125
|
+
* any URL-encoded sequences into their byte representations.
|
|
126
|
+
*
|
|
127
|
+
* *Note* if an error is thrown from this function, the original, non-decoded
|
|
128
|
+
* cookie value will be returned as the cookie's value.
|
|
129
|
+
*/
|
|
130
|
+
decode?(value: string): string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
135
|
+
* name-value pairs.
|
|
136
|
+
*
|
|
137
|
+
* @param str the string representing a `Cookie` header value
|
|
138
|
+
* @param [options] object containing parsing options
|
|
139
|
+
*/
|
|
140
|
+
declare function parse(str: string, options?: CookieParseOptions): Record<string, string>;
|
|
141
|
+
/**
|
|
142
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
|
143
|
+
*
|
|
144
|
+
* @param name the name for the cookie
|
|
145
|
+
* @param value value to set the cookie to
|
|
146
|
+
* @param [options] object containing serialization options
|
|
147
|
+
* @throws {TypeError} when `maxAge` options is invalid
|
|
148
|
+
*/
|
|
149
|
+
declare function serialize(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
150
|
+
|
|
151
|
+
export { type CookieParseOptions, type CookieSerializeOptions, parse, serialize };
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,17 @@ interface CookieSerializeOptions {
|
|
|
99
99
|
* not have an HTTPS connection.
|
|
100
100
|
*/
|
|
101
101
|
secure?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
|
|
104
|
+
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
|
|
105
|
+
* `Partitioned` attribute is not set.
|
|
106
|
+
*
|
|
107
|
+
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
108
|
+
* This also means many clients may ignore this attribute until they understand it.
|
|
109
|
+
*
|
|
110
|
+
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
|
|
111
|
+
*/
|
|
112
|
+
partitioned?: boolean;
|
|
102
113
|
}
|
|
103
114
|
/**
|
|
104
115
|
* Additional parsing options
|
|
@@ -137,4 +148,4 @@ declare function parse(str: string, options?: CookieParseOptions): Record<string
|
|
|
137
148
|
*/
|
|
138
149
|
declare function serialize(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
139
150
|
|
|
140
|
-
export { CookieParseOptions, CookieSerializeOptions, parse, serialize };
|
|
151
|
+
export { type CookieParseOptions, type CookieSerializeOptions, parse, serialize };
|
package/dist/index.mjs
CHANGED
|
@@ -79,38 +79,50 @@ function serialize(name, value, options) {
|
|
|
79
79
|
if (opt.priority) {
|
|
80
80
|
const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
81
81
|
switch (priority) {
|
|
82
|
-
case "low":
|
|
82
|
+
case "low": {
|
|
83
83
|
str += "; Priority=Low";
|
|
84
84
|
break;
|
|
85
|
-
|
|
85
|
+
}
|
|
86
|
+
case "medium": {
|
|
86
87
|
str += "; Priority=Medium";
|
|
87
88
|
break;
|
|
88
|
-
|
|
89
|
+
}
|
|
90
|
+
case "high": {
|
|
89
91
|
str += "; Priority=High";
|
|
90
92
|
break;
|
|
91
|
-
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
92
95
|
throw new TypeError("option priority is invalid");
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
if (opt.sameSite) {
|
|
96
100
|
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
97
101
|
switch (sameSite) {
|
|
98
|
-
case true:
|
|
102
|
+
case true: {
|
|
99
103
|
str += "; SameSite=Strict";
|
|
100
104
|
break;
|
|
101
|
-
|
|
105
|
+
}
|
|
106
|
+
case "lax": {
|
|
102
107
|
str += "; SameSite=Lax";
|
|
103
108
|
break;
|
|
104
|
-
|
|
109
|
+
}
|
|
110
|
+
case "strict": {
|
|
105
111
|
str += "; SameSite=Strict";
|
|
106
112
|
break;
|
|
107
|
-
|
|
113
|
+
}
|
|
114
|
+
case "none": {
|
|
108
115
|
str += "; SameSite=None";
|
|
109
116
|
break;
|
|
110
|
-
|
|
117
|
+
}
|
|
118
|
+
default: {
|
|
111
119
|
throw new TypeError("option sameSite is invalid");
|
|
120
|
+
}
|
|
112
121
|
}
|
|
113
122
|
}
|
|
123
|
+
if (opt.partitioned) {
|
|
124
|
+
str += "; Partitioned";
|
|
125
|
+
}
|
|
114
126
|
return str;
|
|
115
127
|
}
|
|
116
128
|
function isDate(val) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cookie-es",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": "unjs/cookie-es",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -22,19 +22,20 @@
|
|
|
22
22
|
"build": "unbuild",
|
|
23
23
|
"dev": "vitest",
|
|
24
24
|
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
|
|
25
|
-
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
|
|
25
|
+
"lint:fix": "automd && eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
|
|
26
26
|
"release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
|
|
27
27
|
"test": "pnpm lint && vitest run --coverage"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@vitest/coverage-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"eslint
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
30
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
31
|
+
"automd": "^0.3.7",
|
|
32
|
+
"changelogen": "^0.5.5",
|
|
33
|
+
"eslint": "^8.57.0",
|
|
34
|
+
"eslint-config-unjs": "^0.2.1",
|
|
35
|
+
"prettier": "^3.2.5",
|
|
36
|
+
"typescript": "^5.4.3",
|
|
37
|
+
"unbuild": "^2.0.0",
|
|
38
|
+
"vitest": "^1.4.0"
|
|
38
39
|
},
|
|
39
|
-
"packageManager": "pnpm@8.
|
|
40
|
+
"packageManager": "pnpm@8.15.5"
|
|
40
41
|
}
|