@kavach/cookie 1.0.0-next.3

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.
@@ -0,0 +1,23 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.2 coverage /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > vitest run --coverage
4
+
5
+ c
6
+ RUN v0.24.5 /Users/Jerry/Code/Vikalp/kavach/packages/cookie
7
+ Coverage enabled with c8
8
+
9
+ ✓ spec/serialize.spec.js (11 tests) 16ms
10
+ ✓ spec/parse.spec.js (10 tests) 16ms
11
+
12
+ Test Files 2 passed (2)
13
+ Tests 21 passed (21)
14
+ Start at 11:09:04
15
+ Duration 4.35s (transform 784ms, setup 0ms, collect 242ms, tests 32ms)
16
+
17
+ % Coverage report from c8
18
+ ----------|---------|----------|---------|---------|-------------------
19
+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
20
+ ----------|---------|----------|---------|---------|-------------------
21
+ All files | 100 | 100 | 100 | 100 |
22
+ index.js | 100 | 100 | 100 | 100 |
23
+ ----------|---------|----------|---------|---------|-------------------
@@ -0,0 +1,16 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.2 format /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > prettier --write --plugin-search-dir=. .
4
+
5
+ .eslintrc 33ms
6
+ benchmark/index.js 21ms
7
+ benchmark/parse-top.js 19ms
8
+ benchmark/parse.js 23ms
9
+ benchmark/top-sites.js 12ms
10
+ package.json 4ms
11
+ README.md 132ms
12
+ spec/parse.spec.js 26ms
13
+ spec/serialize.spec.js 51ms
14
+ src/index.js 32ms
15
+ tsconfig.json 3ms
16
+ vitest.config.js 5ms
@@ -0,0 +1,6 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.2 lint /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > prettier --check --plugin-search-dir=. . && eslint .
4
+
5
+ Checking formatting...
6
+ All matched files use Prettier code style!
@@ -0,0 +1,4 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.3 prepublishOnly /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > tsc
4
+
@@ -0,0 +1,15 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.3 test:ci /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > vitest run
4
+
5
+ c
6
+ RUN v0.24.5 /Users/Jerry/Code/Vikalp/kavach/packages/cookie
7
+
8
+ ✓ spec/serialize.spec.js (11 tests) 13ms
9
+ ✓ spec/parse.spec.js (10 tests) 81ms
10
+
11
+ Test Files 2 passed (2)
12
+ Tests 21 passed (21)
13
+ Start at 11:57:43
14
+ Duration 3.68s (transform 1.91s, setup 1ms, collect 340ms, tests 94ms)
15
+
@@ -0,0 +1,23 @@
1
+
2
+ > @kavach/cookie@1.0.0-next.3 upgrade /Users/Jerry/Code/Vikalp/kavach/packages/cookie
3
+ > pnpm upgrade
4
+
5
+ ../.. | Progress: resolved 1, reused 0, downloaded 0, added 0
6
+ ../.. | Progress: resolved 5, reused 5, downloaded 0, added 0
7
+ ../.. | Progress: resolved 6, reused 6, downloaded 0, added 0
8
+ ../.. | Progress: resolved 10, reused 10, downloaded 0, added 0
9
+ ../.. | Progress: resolved 11, reused 10, downloaded 0, added 0
10
+ ../.. | Progress: resolved 12, reused 12, downloaded 0, added 0
11
+ ../.. | Progress: resolved 13, reused 12, downloaded 0, added 0
12
+ ../.. | Progress: resolved 63, reused 63, downloaded 0, added 0
13
+ ../.. | Progress: resolved 212, reused 170, downloaded 0, added 0
14
+ ../.. | +5 +
15
+ ../.. | Progress: resolved 213, reused 171, downloaded 0, added 0, done
16
+
17
+ devDependencies:
18
+ - @types/node
19
+ + @types/node 18.11.18
20
+ - vite
21
+ + vite 4.0.3
22
+
23
+ Done in 15.7s
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Jerry Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # @kavach/cookie
2
+
3
+ Basic HTTP cookie parser and serializer for HTTP servers.
4
+
5
+ ## Installation
6
+
7
+ This is a [Node.js](https://nodejs.org/en/) module available through the
8
+ [npm registry](https://www.npmjs.com/). Installation is done using the
9
+ [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
10
+
11
+ ```sh
12
+ npm install @kavach/cookie
13
+ ```
14
+
15
+ ## API
16
+
17
+ ```js
18
+ import * as cookie from '@kavach/cookie'
19
+ ```
20
+
21
+ ### parse(str, options)
22
+
23
+ Parse an HTTP `Cookie` header string and return an object of all cookie name-value pairs.
24
+ The `str` argument is the string representing a `Cookie` header value and the `options` parameter is an
25
+ optional object containing additional parsing options.
26
+
27
+ ```js
28
+ import { parse } from '@kavach/cookie'
29
+ let cookies = parse('foo=bar; equation=E%3Dmc%5E2')
30
+ // { foo: 'bar', equation: 'E=mc^2' }
31
+ ```
32
+
33
+ #### Parse Options
34
+
35
+ The `parse` function accepts these properties in the options object.
36
+
37
+ ##### decode
38
+
39
+ Specifies a function that will be used to decode a cookie's value. Since the value of a cookie
40
+ has a limited character set (and must be a simple string), this function can be used to decode
41
+ a previously-encoded cookie value into a JavaScript string or other object.
42
+
43
+ The default function is the global `decodeURIComponent`, which will decode any URL-encoded
44
+ sequences into their byte representations.
45
+
46
+ **note** if an error is thrown from this function, the original, non-decoded cookie value will
47
+ be returned as the cookie's value.
48
+
49
+ ### serialize(name, value, options)
50
+
51
+ Serialize a cookie name-value pair into a `Set-Cookie` header string. The `name` argument is the
52
+ name for the cookie, the `value` argument is the value to set the cookie to, and the `options`
53
+ argument is an optional object containing additional serialization options.
54
+
55
+ ```js
56
+ import { serialize } from '@kavacg/cookie'
57
+ let setCookie = serialize('foo', 'bar')
58
+ // foo=bar
59
+ ```
60
+
61
+ #### Serialize Options
62
+
63
+ The `serialize` function accepts these properties in the options object.
64
+
65
+ ##### domain
66
+
67
+ Specifies the value for the [`Domain` `Set-Cookie` attribute]([rfc-6265-5.2.3]). By default, no
68
+ domain is set, and most clients will consider the cookie to apply to only the current domain.
69
+
70
+ ##### encode
71
+
72
+ Specifies a function that will be used to encode a cookie's value. Since the value of a cookie
73
+ has a limited character set (and must be a simple string), this function can be used to encode
74
+ a value into a string suited for a cookie's value.
75
+
76
+ The default function is the global `encodeURIComponent`, which will encode a JavaScript string
77
+ into UTF-8 byte sequences and then URL-encode any that fall outside of the cookie range.
78
+
79
+ ##### expires
80
+
81
+ Specifies the `Date` object to be the value for the [`Expires` `Set-Cookie` attribute]([rfc-6265-5.2.1]).
82
+ By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and
83
+ will delete it on a condition like exiting a web browser application.
84
+
85
+ ##### maxAge
86
+
87
+ Specifies the `number` (in seconds) to be the value for the [`Max-Age` `Set-Cookie` attribute]([rfc-6265-5.2.2]).
88
+ The given number will be converted to an integer by rounding down. By default, no maximum age is set.
89
+
90
+ > **note** the [cookie storage model specification]([rfc-6265-5.3]) states that if both `expires` and
91
+ > `maxAge` are set, then `maxAge` takes precedence, but not all clients obey this, so if both are set,
92
+ > they should point to the same date and time.
93
+
94
+ ##### httpOnly
95
+
96
+ Specifies the `boolean` value for the [`HttpOnly` `Set-Cookie` attribute]([rfc-6265-5.2.6]). When truthy,
97
+ the `HttpOnly` attribute is set, otherwise, it is not. By default, the `HttpOnly` attribute is not set.
98
+
99
+ > **note** be careful when setting this to `true`, as compliant clients will not allow client-side
100
+ > JavaScript to see the cookie in `document.cookie`.
101
+
102
+ ##### path
103
+
104
+ Specifies the value for the [`Path` `Set-Cookie` attribute]([rfc-6265-5.2.4]). By default, the path
105
+ is considered the ["default path"]([rfc-6265-5.1.4]).
106
+
107
+ ##### priority
108
+
109
+ Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute]([rfc-west-cookie-priority-00-4.1]).
110
+
111
+ - `'low'` will set the `Priority` attribute to `Low`.
112
+ - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
113
+ - `'high'` will set the `Priority` attribute to `High`.
114
+
115
+ More information about the different priority levels can be found in
116
+ [the specification]([rfc-west-cookie-priority-00-4.1]).
117
+
118
+ > **note** This is an attribute that has not yet been fully standardized, and may change in the future.
119
+ > This also means many clients may ignore this attribute until they understand it.
120
+
121
+ ##### sameSite
122
+
123
+ Specifies the `boolean` or `string` to be the value for the [`SameSite` `Set-Cookie` attribute]([rfc-6265bis-09-5.4.7]).
124
+
125
+ - `true` will set the `SameSite` attribute to `Strict` for strict same-site enforcement.
126
+ - `false` will not set the `SameSite` attribute.
127
+ - `'lax'` will set the `SameSite` attribute to `Lax` for lax same-site enforcement.
128
+ - `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
129
+ - `'strict'` will set the `SameSite` attribute to `Strict` for strict same-site enforcement.
130
+
131
+ More information about the different enforcement levels can be found in
132
+ [the specification]([rfc-6265bis-09-5.4.7]).
133
+
134
+ > **note** This is an attribute that has not yet been fully standardized and may change in the future.
135
+ > This also means many clients may ignore this attribute until they understand it.
136
+
137
+ ##### secure
138
+
139
+ Specifies the `boolean` value for the [`Secure` `Set-Cookie` attribute]([rfc-6265-5.2.5]). When truthy,
140
+ the `Secure` attribute is set, otherwise, it is not. By default, the `Secure` attribute is not set.
141
+
142
+ > **note**:
143
+ > be careful when setting this to `true`, as compliant clients will not send the cookie back to
144
+ > the server in the future if the browser does not have an HTTPS connection.
145
+
146
+ ## Example
147
+
148
+ The following example uses this module in conjunction with the Node.js core HTTP server
149
+ to prompt a user for their name and display it back on future visits.
150
+
151
+ ```js
152
+ import * as cookie from 'cookie'
153
+ import * as escapeHtml from 'escape-html'
154
+ import * as http from 'http'
155
+ import * as url from 'url'
156
+
157
+ function onRequest(req, res) {
158
+ // Parse the query string
159
+ let query = url.parse(req.url, true, true).query
160
+
161
+ if (query && query.name) {
162
+ // Set a new cookie with the name
163
+ res.setHeader(
164
+ 'Set-Cookie',
165
+ cookie.serialize('name', String(query.name), {
166
+ httpOnly: true,
167
+ maxAge: 60 * 60 * 24 * 7 // 1 week
168
+ })
169
+ )
170
+
171
+ // Redirect back after setting cookie
172
+ res.statusCode = 302
173
+ res.setHeader('Location', req.headers.referer || '/')
174
+ res.end()
175
+ return
176
+ }
177
+
178
+ // Parse the cookies on the request
179
+ let cookies = cookie.parse(req.headers.cookie || '')
180
+
181
+ // Get the visitor name set in the cookie
182
+ let name = cookies.name
183
+
184
+ res.setHeader('Content-Type', 'text/html; charset=UTF-8')
185
+
186
+ if (name) {
187
+ res.write('<p>Welcome back, <b>' + escapeHtml(name) + '</b>!</p>')
188
+ } else {
189
+ res.write('<p>Hello, new visitor!</p>')
190
+ }
191
+
192
+ res.write('<form method="GET">')
193
+ res.write(
194
+ '<input placeholder="enter your name" name="name"> <input type="submit" value="Set Name">'
195
+ )
196
+ res.end('</form>')
197
+ }
198
+
199
+ http.createServer(onRequest).listen(3000)
200
+ ```
201
+
202
+ ## Testing
203
+
204
+ ```sh
205
+ pnpm test
206
+ ```
207
+
208
+ ## Benchmark
209
+
210
+ ```text
211
+ $ pnpm bench
212
+
213
+ > @kavach/cookie@1.0.0-next.0 bench cookie
214
+ > node benchmark/index.js
215
+
216
+
217
+ node@16.15.0
218
+ v8@9.4.146.24-node.20
219
+ uv@1.43.0
220
+ zlib@1.2.11
221
+ brotli@1.0.9
222
+ ares@1.18.1
223
+ modules@93
224
+ nghttp2@1.47.0
225
+ napi@8
226
+ llhttp@6.0.4
227
+ openssl@1.1.1n+quic
228
+ cldr@40.0
229
+ icu@70.1
230
+ tz@2021a3
231
+ unicode@14.0
232
+ ngtcp2@0.1.0-DEV
233
+ nghttp3@0.1.0-DEV
234
+ cookie.parse - generic
235
+
236
+ 6 tests completed.
237
+
238
+ simple x 2,285,991 ops/sec ±1.46% (191 runs sampled)
239
+ decode x 1,720,499 ops/sec ±1.25% (189 runs sampled)
240
+ unquote x 1,883,221 ops/sec ±1.30% (186 runs sampled)
241
+ duplicates x 765,346 ops/sec ±1.46% (185 runs sampled)
242
+ 10 cookies x 225,063 ops/sec ±1.04% (185 runs sampled)
243
+ 100 cookies x 20,354 ops/sec ±1.17% (185 runs sampled)
244
+
245
+ cookie.parse - top sites
246
+
247
+ 16 tests completed.
248
+
249
+ parse accounts.google.com x 1,096,402 ops/sec ±0.76% (193 runs sampled)
250
+ parse apple.com x 2,229,368 ops/sec ±1.14% (184 runs sampled)
251
+ parse cloudflare.com x 665,688 ops/sec ±0.91% (183 runs sampled)
252
+ parse docs.google.com x 974,477 ops/sec ±1.07% (181 runs sampled)
253
+ parse drive.google.com x 1,044,377 ops/sec ±0.95% (188 runs sampled)
254
+ parse en.wikipedia.org x 444,311 ops/sec ±1.14% (184 runs sampled)
255
+ parse linkedin.com x 287,581 ops/sec ±0.84% (186 runs sampled)
256
+ parse maps.google.com x 481,702 ops/sec ±0.88% (185 runs sampled)
257
+ parse microsoft.com x 249,242 ops/sec ±0.92% (183 runs sampled)
258
+ parse play.google.com x 686,403 ops/sec ±0.92% (187 runs sampled)
259
+ parse plus.google.com x 989,099 ops/sec ±0.86% (184 runs sampled)
260
+ parse sites.google.com x 975,948 ops/sec ±1.71% (182 runs sampled)
261
+ parse support.google.com x 552,380 ops/sec ±1.03% (189 runs sampled)
262
+ parse www.google.com x 507,071 ops/sec ±0.96% (181 runs sampled)
263
+ parse youtu.be x 941,225 ops/sec ±0.97% (194 runs sampled)
264
+ parse youtube.com x 976,920 ops/sec ±0.61% (192 runs sampled)
265
+ ```
266
+
267
+ ## References
268
+
269
+ This library is an ES module version of [jshttp/cookie](https://github.com/jshttp/cookie), for working with cookies in kavach.
270
+
271
+ - [RFC 6265: HTTP State Management Mechanism][rfc-6265]
272
+ - [Same-site Cookies][rfc-6265bis-09-5.4.7]
273
+
274
+ [rfc-west-cookie-priority-00-4.1]: https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1
275
+ [rfc-6265bis-09-5.4.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7
276
+ [rfc-6265]: https://tools.ietf.org/html/rfc6265
277
+ [rfc-6265-5.1.4]: https://tools.ietf.org/html/rfc6265#section-5.1.4
278
+ [rfc-6265-5.2.1]: https://tools.ietf.org/html/rfc6265#section-5.2.1
279
+ [rfc-6265-5.2.2]: https://tools.ietf.org/html/rfc6265#section-5.2.2
280
+ [rfc-6265-5.2.3]: https://tools.ietf.org/html/rfc6265#section-5.2.3
281
+ [rfc-6265-5.2.4]: https://tools.ietf.org/html/rfc6265#section-5.2.4
282
+ [rfc-6265-5.2.5]: https://tools.ietf.org/html/rfc6265#section-5.2.5
283
+ [rfc-6265-5.2.6]: https://tools.ietf.org/html/rfc6265#section-5.2.6
284
+ [rfc-6265-5.3]: https://tools.ietf.org/html/rfc6265#section-5.3
@@ -0,0 +1,9 @@
1
+ import { suite as parseSuite } from './parse.js'
2
+ import { suite as parseTopSuite } from './parse-top.js'
3
+
4
+ for (let dep in process.versions) {
5
+ console.log(' %s@%s', dep, process.versions[dep])
6
+ }
7
+
8
+ parseSuite.run({ async: false })
9
+ parseTopSuite.run({ async: false })
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+
5
+ import pkg from 'benchmark'
6
+ import { add, log } from 'beautify-benchmark'
7
+ import { topSites } from './top-sites.js'
8
+ import * as cookie from '../src/index.js'
9
+
10
+ const { Suite } = pkg
11
+ /**
12
+ * Globals for benchmark.js
13
+ */
14
+
15
+ global.cookie = cookie
16
+
17
+ export const suite = new Suite()
18
+
19
+ Object.keys(topSites).forEach(function (domain) {
20
+ suite.add({
21
+ name: 'parse ' + domain,
22
+ minSamples: 100,
23
+ fn: 'let val = cookie.parse(' + JSON.stringify(topSites[domain]) + ')'
24
+ })
25
+ })
26
+
27
+ suite.on('start', function onCycle() {
28
+ process.stdout.write(' cookie.parse - top sites\n\n')
29
+ })
30
+
31
+ suite.on('cycle', function onCycle(event) {
32
+ add(event.target)
33
+ })
34
+
35
+ suite.on('complete', function onComplete() {
36
+ log()
37
+ })
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+
5
+ import pkg from 'benchmark'
6
+ import { add, log } from 'beautify-benchmark'
7
+ import * as cookie from '../src/index.js'
8
+
9
+ const { Suite } = pkg
10
+ /**
11
+ * Globals for benchmark.js
12
+ */
13
+
14
+ global.cookie = cookie
15
+
16
+ export const suite = new Suite()
17
+
18
+ suite.add({
19
+ name: 'simple',
20
+ minSamples: 100,
21
+ fn: 'let val = cookie.parse("foo=bar")'
22
+ })
23
+
24
+ suite.add({
25
+ name: 'decode',
26
+ minSamples: 100,
27
+ fn: 'let val = cookie.parse("foo=hello%20there!")'
28
+ })
29
+
30
+ suite.add({
31
+ name: 'unquote',
32
+ minSamples: 100,
33
+ fn: 'let val = cookie.parse("foo=\\"foo bar\\"")'
34
+ })
35
+
36
+ suite.add({
37
+ name: 'duplicates',
38
+ minSamples: 100,
39
+ fn:
40
+ 'let val = cookie.parse(' +
41
+ JSON.stringify(gencookies(2) + '; ' + gencookies(2)) +
42
+ ')'
43
+ })
44
+
45
+ suite.add({
46
+ name: '10 cookies',
47
+ minSamples: 100,
48
+ fn: 'let val = cookie.parse(' + JSON.stringify(gencookies(10)) + ')'
49
+ })
50
+
51
+ suite.add({
52
+ name: '100 cookies',
53
+ minSamples: 100,
54
+ fn: 'let val = cookie.parse(' + JSON.stringify(gencookies(100)) + ')'
55
+ })
56
+
57
+ suite.on('start', function onCycle() {
58
+ process.stdout.write(' cookie.parse - generic\n\n')
59
+ })
60
+
61
+ suite.on('cycle', function onCycle(event) {
62
+ add(event.target)
63
+ })
64
+
65
+ suite.on('complete', function onComplete() {
66
+ log()
67
+ })
68
+
69
+ // suite.run({ async: false })
70
+
71
+ function gencookies(num) {
72
+ let str = ''
73
+
74
+ for (let i = 0; i < num; i++) {
75
+ str += '; foo' + i + '=bar'
76
+ }
77
+
78
+ return str.slice(2)
79
+ }
@@ -0,0 +1,31 @@
1
+ export const topSites = {
2
+ 'accounts.google.com':
3
+ '__Ulll-UUUU=0:0U0lUlllUUUl0lUl00UUUUUU0lUlll:l0ll0UlUU0l0lUUU',
4
+ 'apple.com': 'lll=UU',
5
+ 'cloudflare.com':
6
+ '__ll_ll=lUllUll.0Ul0Ull0UUUU.ll_U0lllUU0UlUll0lUllU-0000000000-0-UUUl+0Ulll0UUUU0U0Ullll0UUUUUlllU0UUUUlUUUlUUUUUUUlUlUUll0l0UlUlUl0Ul000UUlUU0/0l0l0UU0UllUU0U0lU/lllU0lUllU',
7
+ 'docs.google.com':
8
+ '__Ulll-UUUU=0:Ulll0UlUUllUlUl0UUlUUlUU0UUUUU:U0U0U0llUU0-0Ul0',
9
+ 'drive.google.com':
10
+ '__Ulll-UUUU=0:UUll0UllUUll0lUU0llUUllUllUlll:U0UllUlll-lU0lll',
11
+ 'en.wikipedia.org':
12
+ 'UUU-Ulll-Ulllll=00-Ull-0000; UUU-Ulll-Ulllll-Ulllll=00-Ull-0000; UllUU=UU:UU:Ulllllllllll:00.00:-00.00:l0',
13
+ 'linkedin.com':
14
+ 'UUUUUUUUUU=llll:0000000000000000000; llll=l=0&llll=ll-ll; lllllll="l=0&ll000l0l-0lll-00l0-0000-0lll0ll0ll00"; llllllll="l=0&0000000000000000l0l000-0l0l-0000-0000-0l0l00l0000lUUUUUl_llU0UlUllUUlU0lUlUl00llUl"; llll="l=UUUU00:l=U:l=U:l=U:l=U:l=0000:l=0:l=0:l=0000000000:l=0000000000:l=0:lll=UUUUUlUlUUUUUUllllllU0UUlUlU0lll"',
15
+ 'maps.google.com':
16
+ '0U_UUU=0000-00-00-00; UUU=000=UllUl00U-UU0llllUU0lUUlUl0llUl0U0lllUlUUU0l00UUUllllUlU0l0UllUUlUlU0UllUllU0UUlU00llUUUllUUlUl00lUlUUUlUUU0Ul00lllUUUUllUUl0UUlU0UllUlUUllllUllUllUll0llllllllll0lUUUlU0Ull',
17
+ 'microsoft.com':
18
+ 'llUllllUllllll=0; UUUU=0UUU00U0000000U0000U000000UU00UU; U-UU-UUUUUUUU=lll=00000l0%2200000l%22llllll000l0%22llllllllllll000%22lllllllllll%22llllllllllllllll%22llllllllllllllll%22llllllllllllllllllllll%22llllllllllllllllll%22lll-lll-lllll0l0ll%22llllllllllll%22lllllllllllllllll%2200000l0ll&lll=0ll00ll0-000l-000l-l000-l00ll0l0l00l; U-UU-Ulll=0; lllll_UllUU=0000000000~ll=00~ll=0lll000ll0l0000lll000lll0ll0000l; lllll_UllUU=0000000000~ll=00~ll=0lll000ll0l0000lll000lll0ll0000l',
19
+ 'play.google.com':
20
+ 'UUU=000=Ull0l00UlllUUUlU0UllUl0llU0l-lllUllUl0lllUU0UUU0lUlU-UUll000lUl00U0Ul_UlUU0l0lUUUUlUUl0UlUl0lU0-lll0l0l0UlUllllU0U0UU0U00UllU0l0lU0lll_0lUUU0UllUUUUll0UlUl0l0UUUUU00UUllll',
21
+ 'plus.google.com':
22
+ '__Ulll-UUUU=0:0Ull0lUU0UUUlll0U-UllUUllllUlU:lll00_lllUUUUUUU',
23
+ 'sites.google.com':
24
+ '__Ulll-UUUU=0:_UU0lll0UUUUlUU0lUll0UUlllllUl:UUll0lllU0UUlll0',
25
+ 'support.google.com':
26
+ 'UUU=000=llU0lUlllUUlllUUll0U0UUll0UUlUUlU-lUUllU0UllUlUUlUlU0UlUUU_U-UlUU0lUUlUllUlUlUUl00llllUl0lUUUU00Ul0UUlUll0UUUU_UUlUlllUllllU0U0lllllUlU000UllUl--UUU_ll_lllU0UllUUlllU00UlU; UUU=000=llU0lUlllUUlllUUll0U0UUll0UUlUUlU-lUUllU0UllUlUUlUlU0UlUUU_U-UlUU0lUUlUllUlUlUUl00llllUl0lUUUU00Ul0UUlUll0UUUU_UUlUlllUllllU0U0lllllUlU000UllUl--UUU_ll_lllU0UllUUlllU00UlU',
27
+ 'www.google.com':
28
+ '0U_UUU=0000-00-00-00; UUU=UUUU_UUUlUUUUlUll_lllll0U00UUl0lllUUUUlUU_0_llUl0l0UUlU0_lU; UUU=000=lll0lUlUlllUll00U_lUlUUUUlll0lUlUU0lllUlllUllUUUll0U_U0llUU0UlU0Ull0U_l-_UUl00lUllUl0UUllUlUll0UUllUUUlU0UUlUllUlUUUlUllU-lUUlll0UlU0lUllUUUUlUUUlUlUU0llll_lU0lUlllll_UlUl',
29
+ 'youtu.be': 'UUU=0; UUU=UUUUUUUllUU; UUUUUUU_UUUU0_UUUU=00UlUU-UUU0',
30
+ 'youtube.com': 'UUU=0; UUU=lU0lUUUlUll; UUUUUUU_UUUU0_UUUU=0UUUlUllU0l'
31
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Parse a cookie header.
3
+ *
4
+ * Parse the given cookie header string into an object
5
+ * The object has the various cookies as keys(names) => values
6
+ *
7
+ * @param {string} str
8
+ * @param {object} [options]
9
+ * @return {object}
10
+ * @public
11
+ */
12
+ export function parse(str: string, options?: object): object;
13
+ /**
14
+ * Serialize data into a cookie header.
15
+ *
16
+ * Serialize the a name value pair into a cookie string suitable for
17
+ * http headers. An optional options object specified cookie parameters.
18
+ *
19
+ * serialize('foo', 'bar', { httpOnly: true })
20
+ * => "foo=bar; httpOnly"
21
+ *
22
+ * @param {string} name
23
+ * @param {string} val
24
+ * @param {object} [options]
25
+ * @return {string}
26
+ * @public
27
+ */
28
+ export function serialize(name: string, val: string, options?: object): string;
29
+ declare namespace _default {
30
+ export { parse };
31
+ export { serialize };
32
+ }
33
+ export default _default;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA+BA;;;;;;;;;;GAUG;AAEH,2BANW,MAAM,YACN,MAAM,GACL,MAAM,CAsCjB;AAED;;;;;;;;;;;;;;GAcG;AAEH,gCAPW,MAAM,OACN,MAAM,YACN,MAAM,GACL,MAAM,CA2FjB"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@kavach/cookie",
3
+ "version": "1.0.0-next.3",
4
+ "description": "Cookie serialize/deserialize forked from jshttp/cookie",
5
+ "author": "Jerry Thomas <me@jerrythomas.name>",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "cookie",
9
+ "cookies"
10
+ ],
11
+ "main": "index.js",
12
+ "module": "src/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "type": "module",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/jerrythomas/kavach",
18
+ "directory": "packages/cookie"
19
+ },
20
+ "prettier": "@jerrythomas/prettier-config",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "devDependencies": {
25
+ "@jerrythomas/prettier-config": "^1.0.0",
26
+ "@types/benchmark": "^2.1.2",
27
+ "@types/node": "^18.11.18",
28
+ "@vitest/coverage-c8": "^0.24.5",
29
+ "@vitest/ui": "~0.12.10",
30
+ "beautify-benchmark": "0.2.4",
31
+ "benchmark": "2.1.4",
32
+ "c8": "^7.12.0",
33
+ "safe-buffer": "5.2.1",
34
+ "top-sites": "1.1.97",
35
+ "typescript": "^4.9.4",
36
+ "vite": "^4.0.3",
37
+ "vitest": "0.24.5",
38
+ "eslint-config-library": "1.0.0",
39
+ "shared-config": "1.0.0"
40
+ },
41
+ "exports": {
42
+ "./package.json": "./package.json",
43
+ "./provider.css": "./src/provider.css",
44
+ ".": {
45
+ "types": "./dist/index.d.ts",
46
+ "import": "./src/index.js"
47
+ }
48
+ },
49
+ "scripts": {
50
+ "bench": "node benchmark/index.js",
51
+ "lint": "prettier --check --plugin-search-dir=. . && eslint .",
52
+ "format": "prettier --write --plugin-search-dir=. .",
53
+ "test:ci": "vitest run",
54
+ "test:ui": "vitest --ui",
55
+ "test": "vitest",
56
+ "coverage": "vitest run --coverage",
57
+ "upgrade": "pnpm upgrade"
58
+ }
59
+ }
@@ -0,0 +1,91 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { parse } from '../src/index.js'
3
+
4
+ describe('Cookie Parser', () => {
5
+ it('argument validation', () => {
6
+ expect(parse.bind()).toThrowError(/argument str must be a string/)
7
+ expect(parse.bind(null, 42)).toThrowError(/argument str must be a string/)
8
+ })
9
+
10
+ it('basic', () => {
11
+ expect(parse('foo=bar')).toEqual({ foo: 'bar' })
12
+ expect(parse('foo=123')).toEqual({ foo: '123' })
13
+ })
14
+
15
+ it('ignore spaces', () => {
16
+ expect(parse('FOO = bar; baz = raz')).toEqual({
17
+ FOO: 'bar',
18
+ baz: 'raz'
19
+ })
20
+ })
21
+
22
+ it('escaping', () => {
23
+ expect(parse('foo="bar=123456789&name=Magic+Mouse"')).toEqual({
24
+ foo: 'bar=123456789&name=Magic+Mouse'
25
+ })
26
+
27
+ expect(parse('email=%20%22%2c%3b%2f')).toEqual({ email: ' ",;/' })
28
+ })
29
+
30
+ it('ignore escaping error and return original value', () => {
31
+ expect(parse('foo=%1;bar=bar')).toEqual({ foo: '%1', bar: 'bar' })
32
+ })
33
+
34
+ it('ignore non values', () => {
35
+ expect(parse('foo=%1;bar=bar;HttpOnly;Secure')).toEqual({
36
+ foo: '%1',
37
+ bar: 'bar'
38
+ })
39
+ })
40
+
41
+ it('unencoded', () => {
42
+ expect(
43
+ parse('foo="bar=123456789&name=Magic+Mouse"', {
44
+ decode: function (v) {
45
+ return v
46
+ }
47
+ })
48
+ ).toEqual({ foo: 'bar=123456789&name=Magic+Mouse' })
49
+
50
+ expect(
51
+ parse('email=%20%22%2c%3b%2f', {
52
+ decode: function (v) {
53
+ return v
54
+ }
55
+ })
56
+ ).toEqual({ email: '%20%22%2c%3b%2f' })
57
+ })
58
+
59
+ it('dates', () => {
60
+ expect(
61
+ parse('priority=true; expires=Wed, 29 Jan 2014 17:43:25 GMT; Path=/', {
62
+ decode: function (v) {
63
+ return v
64
+ }
65
+ })
66
+ ).toEqual({
67
+ priority: 'true',
68
+ Path: '/',
69
+ expires: 'Wed, 29 Jan 2014 17:43:25 GMT'
70
+ })
71
+ })
72
+
73
+ it('missing value', () => {
74
+ expect(
75
+ parse('foo; bar=1; fizz= ; buzz=2', {
76
+ decode: function (v) {
77
+ return v
78
+ }
79
+ })
80
+ ).toEqual({ bar: '1', fizz: '', buzz: '2' })
81
+ })
82
+
83
+ it('assign only once', () => {
84
+ expect(parse('foo=%1;bar=bar;foo=boo')).toEqual({ foo: '%1', bar: 'bar' })
85
+ expect(parse('foo=false;bar=bar;foo=true'), {
86
+ foo: 'false',
87
+ bar: 'bar'
88
+ })
89
+ expect(parse('foo=;bar=bar;foo=boo')).toEqual({ foo: '', bar: 'bar' })
90
+ })
91
+ })
@@ -0,0 +1,169 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import cookie from '../src/index.js'
3
+
4
+ describe('Cookie Serialize', () => {
5
+ it('basic', () => {
6
+ expect(cookie.serialize('foo', 'bar')).toEqual('foo=bar')
7
+ expect(cookie.serialize('foo', 'bar baz')).toEqual('foo=bar%20baz')
8
+ expect(cookie.serialize('foo', '')).toEqual('foo=')
9
+ expect(cookie.serialize.bind(cookie, 'foo\n', 'bar')).toThrowError(
10
+ /argument name is invalid/
11
+ )
12
+ expect(cookie.serialize.bind(cookie, 'foo\u280a', 'bar')).toThrowError(
13
+ /argument name is invalid/
14
+ )
15
+ expect(
16
+ cookie.serialize.bind(cookie, 'foo', 'bar', { encode: 42 })
17
+ ).toThrowError(/option encode is invalid/)
18
+ })
19
+
20
+ it('path', () => {
21
+ expect(cookie.serialize('foo', 'bar', { path: '/' })).toEqual(
22
+ 'foo=bar; Path=/'
23
+ )
24
+ expect(
25
+ cookie.serialize.bind(cookie, 'foo', 'bar', {
26
+ path: '/\n'
27
+ })
28
+ ).toThrowError(/option path is invalid/)
29
+ })
30
+
31
+ it('secure', () => {
32
+ expect(cookie.serialize('foo', 'bar', { secure: true })).toEqual(
33
+ 'foo=bar; Secure'
34
+ )
35
+ expect(cookie.serialize('foo', 'bar', { secure: false })).toEqual('foo=bar')
36
+ })
37
+
38
+ it('domain', () => {
39
+ expect(cookie.serialize('foo', 'bar', { domain: 'example.com' })).toEqual(
40
+ 'foo=bar; Domain=example.com'
41
+ )
42
+ expect(
43
+ cookie.serialize.bind(cookie, 'foo', 'bar', {
44
+ domain: 'example.com\n'
45
+ })
46
+ ).toThrowError(/option domain is invalid/)
47
+ })
48
+
49
+ it('httpOnly', () => {
50
+ expect(cookie.serialize('foo', 'bar', { httpOnly: true })).toEqual(
51
+ 'foo=bar; HttpOnly'
52
+ )
53
+ })
54
+
55
+ it('maxAge', () => {
56
+ expect(() =>
57
+ cookie.serialize('foo', 'bar', {
58
+ maxAge: 'buzz'
59
+ })
60
+ ).toThrowError(/option maxAge is invalid/)
61
+
62
+ expect(() =>
63
+ cookie.serialize('foo', 'bar', {
64
+ maxAge: Infinity
65
+ })
66
+ ).toThrowError(/option maxAge is invalid/)
67
+
68
+ expect(cookie.serialize('foo', 'bar', { maxAge: 1000 })).toEqual(
69
+ 'foo=bar; Max-Age=1000'
70
+ )
71
+ expect(cookie.serialize('foo', 'bar', { maxAge: '1000' })).toEqual(
72
+ 'foo=bar; Max-Age=1000'
73
+ )
74
+ expect(cookie.serialize('foo', 'bar', { maxAge: 0 })).toEqual(
75
+ 'foo=bar; Max-Age=0'
76
+ )
77
+ expect(cookie.serialize('foo', 'bar', { maxAge: '0' })).toEqual(
78
+ 'foo=bar; Max-Age=0'
79
+ )
80
+ expect(cookie.serialize('foo', 'bar', { maxAge: null })).toEqual('foo=bar')
81
+ expect(cookie.serialize('foo', 'bar', { maxAge: undefined })).toEqual(
82
+ 'foo=bar'
83
+ )
84
+ expect(cookie.serialize('foo', 'bar', { maxAge: 3.14 })).toEqual(
85
+ 'foo=bar; Max-Age=3'
86
+ )
87
+ })
88
+
89
+ it('expires', () => {
90
+ expect(
91
+ cookie.serialize('foo', 'bar', {
92
+ expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900))
93
+ })
94
+ ).toEqual('foo=bar; Expires=Sun, 24 Dec 2000 10:30:59 GMT')
95
+
96
+ expect(
97
+ cookie.serialize.bind(cookie, 'foo', 'bar', {
98
+ expires: Date.now()
99
+ })
100
+ ).toThrowError(/option expires is invalid/)
101
+ })
102
+
103
+ it('sameSite', () => {
104
+ expect(cookie.serialize('foo', 'bar', { sameSite: true })).toEqual(
105
+ 'foo=bar; SameSite=Strict'
106
+ )
107
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'Strict' })).toEqual(
108
+ 'foo=bar; SameSite=Strict'
109
+ )
110
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'strict' })).toEqual(
111
+ 'foo=bar; SameSite=Strict'
112
+ )
113
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'Lax' })).toEqual(
114
+ 'foo=bar; SameSite=Lax'
115
+ )
116
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'lax' })).toEqual(
117
+ 'foo=bar; SameSite=Lax'
118
+ )
119
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'None' })).toEqual(
120
+ 'foo=bar; SameSite=None'
121
+ )
122
+ expect(cookie.serialize('foo', 'bar', { sameSite: 'none' })).toEqual(
123
+ 'foo=bar; SameSite=None'
124
+ )
125
+ expect(cookie.serialize('foo', 'bar', { sameSite: false })).toEqual(
126
+ 'foo=bar'
127
+ )
128
+
129
+ expect(
130
+ cookie.serialize.bind(cookie, 'foo', 'bar', {
131
+ sameSite: 'foo'
132
+ })
133
+ ).toThrowError(/option sameSite is invalid/)
134
+ })
135
+
136
+ it('escaping', () => {
137
+ expect(cookie.serialize('cat', '+ ')).toEqual('cat=%2B%20')
138
+ })
139
+
140
+ it('parse->serialize', () => {
141
+ expect(
142
+ cookie.parse(cookie.serialize('cat', 'foo=123&name=baz five'))
143
+ ).toEqual({
144
+ cat: 'foo=123&name=baz five'
145
+ })
146
+
147
+ expect(cookie.parse(cookie.serialize('cat', ' ";/'))).toEqual({
148
+ cat: ' ";/'
149
+ })
150
+ })
151
+
152
+ it('unencoded', () => {
153
+ expect(
154
+ cookie.serialize('cat', '+ ', {
155
+ encode: function (value) {
156
+ return value
157
+ }
158
+ })
159
+ ).toEqual('cat=+ ')
160
+
161
+ expect(
162
+ cookie.serialize.bind(cookie, 'cat', '+ \n', {
163
+ encode: function (value) {
164
+ return value
165
+ }
166
+ })
167
+ ).toThrowError(/argument val is invalid/)
168
+ })
169
+ })
package/src/index.js ADDED
@@ -0,0 +1,204 @@
1
+ /*!
2
+ * cookie
3
+ * Copyright(c) 2012-2014 Roman Shtylman
4
+ * Copyright(c) 2015 Douglas Christopher Wilson
5
+ * MIT Licensed
6
+ *
7
+ * Converted to ESM for use in SvelteKit apps
8
+ */
9
+
10
+ 'use strict'
11
+
12
+ /**
13
+ * Module variables.
14
+ * @private
15
+ */
16
+
17
+ var decode = decodeURIComponent
18
+ var encode = encodeURIComponent
19
+ var pairSplitRegExp = /; */
20
+
21
+ /**
22
+ * RegExp to match field-content in RFC 7230 sec 3.2
23
+ *
24
+ * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
25
+ * field-vchar = VCHAR / obs-text
26
+ * obs-text = %x80-FF
27
+ */
28
+
29
+ // eslint-disable-next-line no-control-regex
30
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/
31
+
32
+ /**
33
+ * Parse a cookie header.
34
+ *
35
+ * Parse the given cookie header string into an object
36
+ * The object has the various cookies as keys(names) => values
37
+ *
38
+ * @param {string} str
39
+ * @param {object} [options]
40
+ * @return {object}
41
+ * @public
42
+ */
43
+
44
+ export function parse(str, options) {
45
+ if (typeof str !== 'string') {
46
+ throw new TypeError('argument str must be a string')
47
+ }
48
+
49
+ var obj = {}
50
+ var opt = options || {}
51
+ var pairs = str.split(pairSplitRegExp)
52
+ var dec = opt.decode || decode
53
+
54
+ for (var i = 0; i < pairs.length; i++) {
55
+ var pair = pairs[i]
56
+ var eq_idx = pair.indexOf('=')
57
+
58
+ // skip things that don't look like key=value
59
+ if (eq_idx < 0) {
60
+ continue
61
+ }
62
+
63
+ var key = pair.slice(0, eq_idx).trim()
64
+ var val = pair.slice(++eq_idx, pair.length).trim()
65
+
66
+ // quoted values
67
+ if ('"' == val[0]) {
68
+ val = val.slice(1, -1)
69
+ }
70
+
71
+ // only assign once
72
+ if (undefined == obj[key]) {
73
+ obj[key] = tryDecode(val, dec)
74
+ }
75
+ }
76
+
77
+ return obj
78
+ }
79
+
80
+ /**
81
+ * Serialize data into a cookie header.
82
+ *
83
+ * Serialize the a name value pair into a cookie string suitable for
84
+ * http headers. An optional options object specified cookie parameters.
85
+ *
86
+ * serialize('foo', 'bar', { httpOnly: true })
87
+ * => "foo=bar; httpOnly"
88
+ *
89
+ * @param {string} name
90
+ * @param {string} val
91
+ * @param {object} [options]
92
+ * @return {string}
93
+ * @public
94
+ */
95
+
96
+ export function serialize(name, val, options) {
97
+ var opt = options || {}
98
+ var enc = opt.encode || encode
99
+
100
+ if (typeof enc !== 'function') {
101
+ throw new TypeError('option encode is invalid')
102
+ }
103
+
104
+ if (!fieldContentRegExp.test(name)) {
105
+ throw new TypeError('argument name is invalid')
106
+ }
107
+
108
+ var value = enc(val)
109
+
110
+ if (value && !fieldContentRegExp.test(value)) {
111
+ throw new TypeError('argument val is invalid')
112
+ }
113
+
114
+ var str = name + '=' + value
115
+
116
+ if (null != opt.maxAge) {
117
+ var maxAge = opt.maxAge - 0
118
+
119
+ if (isNaN(maxAge) || !isFinite(maxAge)) {
120
+ throw new TypeError('option maxAge is invalid')
121
+ }
122
+
123
+ str += '; Max-Age=' + Math.floor(maxAge)
124
+ }
125
+
126
+ if (opt.domain) {
127
+ if (!fieldContentRegExp.test(opt.domain)) {
128
+ throw new TypeError('option domain is invalid')
129
+ }
130
+
131
+ str += '; Domain=' + opt.domain
132
+ }
133
+
134
+ if (opt.path) {
135
+ if (!fieldContentRegExp.test(opt.path)) {
136
+ throw new TypeError('option path is invalid')
137
+ }
138
+
139
+ str += '; Path=' + opt.path
140
+ }
141
+
142
+ if (opt.expires) {
143
+ if (typeof opt.expires.toUTCString !== 'function') {
144
+ throw new TypeError('option expires is invalid')
145
+ }
146
+
147
+ str += '; Expires=' + opt.expires.toUTCString()
148
+ }
149
+
150
+ if (opt.httpOnly) {
151
+ str += '; HttpOnly'
152
+ }
153
+
154
+ if (opt.secure) {
155
+ str += '; Secure'
156
+ }
157
+
158
+ if (opt.sameSite) {
159
+ var sameSite =
160
+ typeof opt.sameSite === 'string'
161
+ ? opt.sameSite.toLowerCase()
162
+ : opt.sameSite
163
+
164
+ switch (sameSite) {
165
+ case true:
166
+ str += '; SameSite=Strict'
167
+ break
168
+ case 'lax':
169
+ str += '; SameSite=Lax'
170
+ break
171
+ case 'strict':
172
+ str += '; SameSite=Strict'
173
+ break
174
+ case 'none':
175
+ str += '; SameSite=None'
176
+ break
177
+ default:
178
+ throw new TypeError('option sameSite is invalid')
179
+ }
180
+ }
181
+
182
+ return str
183
+ }
184
+
185
+ /**
186
+ * Try decoding a string using a decoding function.
187
+ *
188
+ * @param {string} str
189
+ * @param {function} decode
190
+ * @private
191
+ */
192
+
193
+ function tryDecode(str, decode) {
194
+ try {
195
+ return decode(str)
196
+ } catch (e) {
197
+ return str
198
+ }
199
+ }
200
+
201
+ export default {
202
+ parse,
203
+ serialize
204
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "shared-config/jsconfig.json",
3
+ "include": ["src/**/*.js"],
4
+ "compilerOptions": {
5
+ "outDir": "dist",
6
+ "checkJs": false
7
+ }
8
+ }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vite'
2
+
3
+ export default defineConfig({
4
+ plugins: [],
5
+ test: {
6
+ globals: true,
7
+ coverage: {
8
+ reporter: ['html', 'lcov', 'text'],
9
+ all: false,
10
+ include: ['src']
11
+ }
12
+ }
13
+ })