Leon4gr45 commited on
Commit
04ba84a
·
verified ·
1 Parent(s): 978a508

Include updated package-lock.json (part 22)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. node_modules/hast-util-sanitize/readme.md +470 -0
  2. node_modules/hast-util-to-jsx-runtime/index.d.ts +18 -0
  3. node_modules/hast-util-to-jsx-runtime/index.js +2 -0
  4. node_modules/hast-util-to-jsx-runtime/lib/index.d.ts +16 -0
  5. node_modules/hast-util-to-jsx-runtime/lib/index.d.ts.map +1 -0
  6. node_modules/hast-util-to-jsx-runtime/lib/index.js +787 -0
  7. node_modules/hast-util-to-jsx-runtime/lib/types.d.ts +446 -0
  8. node_modules/hast-util-to-jsx-runtime/lib/types.js +2 -0
  9. node_modules/hast-util-to-jsx-runtime/license +22 -0
  10. node_modules/hast-util-to-jsx-runtime/package.json +138 -0
  11. node_modules/hast-util-to-jsx-runtime/readme.md +886 -0
  12. node_modules/hast-util-whitespace/index.d.ts +1 -0
  13. node_modules/hast-util-whitespace/index.js +1 -0
  14. node_modules/hast-util-whitespace/lib/index.d.ts +13 -0
  15. node_modules/hast-util-whitespace/lib/index.js +34 -0
  16. node_modules/hast-util-whitespace/license +22 -0
  17. node_modules/hast-util-whitespace/package.json +83 -0
  18. node_modules/hast-util-whitespace/readme.md +231 -0
  19. node_modules/headers-polyfill/LICENSE +9 -0
  20. node_modules/headers-polyfill/README.md +204 -0
  21. node_modules/headers-polyfill/lib/index.cjs +303 -0
  22. node_modules/headers-polyfill/lib/index.cjs.map +1 -0
  23. node_modules/headers-polyfill/lib/index.d.cts +103 -0
  24. node_modules/headers-polyfill/lib/index.d.mts +103 -0
  25. node_modules/headers-polyfill/lib/index.mjs +292 -0
  26. node_modules/headers-polyfill/lib/index.mjs.map +1 -0
  27. node_modules/headers-polyfill/package.json +50 -0
  28. node_modules/headers-polyfill/src/Headers.test.ts +483 -0
  29. node_modules/headers-polyfill/src/Headers.ts +198 -0
  30. node_modules/headers-polyfill/src/getRawHeaders.test.ts +19 -0
  31. node_modules/headers-polyfill/src/getRawHeaders.ts +14 -0
  32. node_modules/headers-polyfill/src/glossary.ts +4 -0
  33. node_modules/headers-polyfill/src/index.ts +21 -0
  34. node_modules/headers-polyfill/src/transformers/appendHeader.test.ts +62 -0
  35. node_modules/headers-polyfill/src/transformers/appendHeader.ts +21 -0
  36. node_modules/headers-polyfill/src/transformers/flattenHeadersList.test.ts +16 -0
  37. node_modules/headers-polyfill/src/transformers/flattenHeadersList.ts +7 -0
  38. node_modules/headers-polyfill/src/transformers/flattenHeadersObject.test.ts +16 -0
  39. node_modules/headers-polyfill/src/transformers/flattenHeadersObject.ts +15 -0
  40. node_modules/headers-polyfill/src/transformers/headersToList.node.test.ts +40 -0
  41. node_modules/headers-polyfill/src/transformers/headersToList.test.ts +39 -0
  42. node_modules/headers-polyfill/src/transformers/headersToList.ts +15 -0
  43. node_modules/headers-polyfill/src/transformers/headersToObject.node.test.ts +56 -0
  44. node_modules/headers-polyfill/src/transformers/headersToObject.test.ts +55 -0
  45. node_modules/headers-polyfill/src/transformers/headersToObject.ts +23 -0
  46. node_modules/headers-polyfill/src/transformers/headersToString.test.ts +51 -0
  47. node_modules/headers-polyfill/src/transformers/headersToString.ts +14 -0
  48. node_modules/headers-polyfill/src/transformers/listToHeaders.test.ts +19 -0
  49. node_modules/headers-polyfill/src/transformers/listToHeaders.ts +16 -0
  50. node_modules/headers-polyfill/src/transformers/objectToHeaders.test.ts +21 -0
node_modules/hast-util-sanitize/readme.md ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # hast-util-sanitize
2
+
3
+ [![Build][build-badge]][build]
4
+ [![Coverage][coverage-badge]][coverage]
5
+ [![Downloads][downloads-badge]][downloads]
6
+ [![Size][size-badge]][size]
7
+ [![Sponsors][sponsors-badge]][collective]
8
+ [![Backers][backers-badge]][collective]
9
+ [![Chat][chat-badge]][chat]
10
+
11
+ [hast][] utility to make trees safe.
12
+
13
+ ## Contents
14
+
15
+ * [What is this?](#what-is-this)
16
+ * [When should I use this?](#when-should-i-use-this)
17
+ * [Install](#install)
18
+ * [Use](#use)
19
+ * [API](#api)
20
+ * [`defaultSchema`](#defaultschema)
21
+ * [`sanitize(tree[, options])`](#sanitizetree-options)
22
+ * [`Schema`](#schema)
23
+ * [Types](#types)
24
+ * [Compatibility](#compatibility)
25
+ * [Security](#security)
26
+ * [Related](#related)
27
+ * [Contribute](#contribute)
28
+ * [License](#license)
29
+
30
+ ## What is this?
31
+
32
+ This package is a utility that can make a tree that potentially contains
33
+ dangerous user content safe for use.
34
+ It defaults to what GitHub does to clean unsafe markup, but you can change that.
35
+
36
+ ## When should I use this?
37
+
38
+ This package is needed whenever you deal with potentially dangerous user
39
+ content.
40
+
41
+ The plugin [`rehype-sanitize`][rehype-sanitize] wraps this utility to also
42
+ sanitize HTML at a higher-level (easier) abstraction.
43
+
44
+ ## Install
45
+
46
+ This package is [ESM only][esm].
47
+ In Node.js (version 16+), install with [npm][]:
48
+
49
+ ```sh
50
+ npm install hast-util-sanitize
51
+ ```
52
+
53
+ In Deno with [`esm.sh`][esmsh]:
54
+
55
+ ```js
56
+ import {sanitize} from 'https://esm.sh/hast-util-sanitize@5'
57
+ ```
58
+
59
+ In browsers with [`esm.sh`][esmsh]:
60
+
61
+ ```html
62
+ <script type="module">
63
+ import {sanitize} from 'https://esm.sh/hast-util-sanitize@5?bundle'
64
+ </script>
65
+ ```
66
+
67
+ ## Use
68
+
69
+ ```js
70
+ import {h} from 'hastscript'
71
+ import {sanitize} from 'hast-util-sanitize'
72
+ import {toHtml} from 'hast-util-to-html'
73
+ import {u} from 'unist-builder'
74
+
75
+ const unsafe = h('div', {onmouseover: 'alert("alpha")'}, [
76
+ h(
77
+ 'a',
78
+ {href: 'jAva script:alert("bravo")', onclick: 'alert("charlie")'},
79
+ 'delta'
80
+ ),
81
+ u('text', '\n'),
82
+ h('script', 'alert("charlie")'),
83
+ u('text', '\n'),
84
+ h('img', {src: 'x', onerror: 'alert("delta")'}),
85
+ u('text', '\n'),
86
+ h('iframe', {src: 'javascript:alert("echo")'}),
87
+ u('text', '\n'),
88
+ h('math', h('mi', {'xlink:href': 'data:x,<script>alert("foxtrot")</script>'}))
89
+ ])
90
+
91
+ const safe = sanitize(unsafe)
92
+
93
+ console.log(toHtml(unsafe))
94
+ console.log(toHtml(safe))
95
+ ```
96
+
97
+ Unsafe:
98
+
99
+ ```html
100
+ <div onmouseover="alert(&#x22;alpha&#x22;)"><a href="jAva script:alert(&#x22;bravo&#x22;)" onclick="alert(&#x22;charlie&#x22;)">delta</a>
101
+ <script>alert("charlie")</script>
102
+ <img src="x" onerror="alert(&#x22;delta&#x22;)">
103
+ <iframe src="javascript:alert(&#x22;echo&#x22;)"></iframe>
104
+ <math><mi xlink:href="data:x,<script>alert(&#x22;foxtrot&#x22;)</script>"></mi></math></div>
105
+ ```
106
+
107
+ Safe:
108
+
109
+ ```html
110
+ <div><a>delta</a>
111
+
112
+ <img src="x">
113
+
114
+ </div>
115
+ ```
116
+
117
+ ## API
118
+
119
+ This package exports the identifiers [`defaultSchema`][api-default-schema] and
120
+ [`sanitize`][api-sanitize].
121
+ There is no default export.
122
+
123
+ ### `defaultSchema`
124
+
125
+ Default schema ([`Schema`][api-schema]).
126
+
127
+ Follows [GitHub][] style sanitation.
128
+
129
+ ### `sanitize(tree[, options])`
130
+
131
+ Sanitize a tree.
132
+
133
+ ###### Parameters
134
+
135
+ * `tree` ([`Node`][node])
136
+ — unsafe tree
137
+ * `options` ([`Schema`][api-schema], default:
138
+ [`defaultSchema`][api-default-schema])
139
+ — configuration
140
+
141
+ ###### Returns
142
+
143
+ New, safe tree ([`Node`][node]).
144
+
145
+ ### `Schema`
146
+
147
+ Schema that defines what nodes and properties are allowed.
148
+
149
+ The default schema is [`defaultSchema`][api-default-schema], which follows how
150
+ GitHub cleans.
151
+ If any top-level key is missing in the given schema, the corresponding
152
+ value of the default schema is used.
153
+
154
+ To extend the standard schema with a few changes, clone `defaultSchema`
155
+ like so:
156
+
157
+ ```js
158
+ import deepmerge from 'deepmerge'
159
+ import {h} from 'hastscript'
160
+ import {defaultSchema, sanitize} from 'hast-util-sanitize'
161
+
162
+ // This allows `className` on all elements.
163
+ const schema = deepmerge(defaultSchema, {attributes: {'*': ['className']}})
164
+
165
+ const tree = sanitize(h('div', {className: ['foo']}), schema)
166
+
167
+ // `tree` still has `className`.
168
+ console.log(tree)
169
+ // {
170
+ // type: 'element',
171
+ // tagName: 'div',
172
+ // properties: {className: ['foo']},
173
+ // children: []
174
+ // }
175
+ ```
176
+
177
+ ##### Fields
178
+
179
+ ###### `allowComments`
180
+
181
+ Whether to allow comment nodes (`boolean`, default: `false`).
182
+
183
+ For example:
184
+
185
+ ```js
186
+ allowComments: true
187
+ ```
188
+
189
+ ###### `allowDoctypes`
190
+
191
+ Whether to allow doctype nodes (`boolean`, default: `false`).
192
+
193
+ For example:
194
+
195
+ ```js
196
+ allowDoctypes: true
197
+ ```
198
+
199
+ ###### `ancestors`
200
+
201
+ Map of tag names to a list of tag names which are required ancestors
202
+ (`Record<string, Array<string>>`, default: `defaultSchema.ancestors`).
203
+
204
+ Elements with these tag names will be ignored if they occur outside of one
205
+ of their allowed parents.
206
+
207
+ For example:
208
+
209
+ ```js
210
+ ancestors: {
211
+ tbody: ['table'],
212
+ // …
213
+ tr: ['table']
214
+ }
215
+ ```
216
+
217
+ ###### `attributes`
218
+
219
+ Map of tag names to allowed [property names][name]
220
+ (`Record<string, Array<[string, ...Array<RegExp | boolean | number | string>] | string>`,
221
+ default: `defaultSchema.attributes`).
222
+
223
+ The special key `'*'` as a tag name defines property names allowed on all
224
+ elements.
225
+
226
+ The special value `'data*'` as a property name can be used to allow all `data`
227
+ properties.
228
+
229
+ For example:
230
+
231
+ ```js
232
+ attributes: {
233
+ a: [
234
+ 'ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy', /* … */, 'href'
235
+ ],
236
+ // …
237
+ '*': [
238
+ 'abbr',
239
+ 'accept',
240
+ 'acceptCharset',
241
+ // …
242
+ 'vAlign',
243
+ 'value',
244
+ 'width'
245
+ ]
246
+ }
247
+ ```
248
+
249
+ Instead of a single string in the array, which allows any property value for
250
+ the field, you can use an array to allow several values.
251
+ For example, `input: ['type']` allows `type` set to any value on `input`s.
252
+ But `input: [['type', 'checkbox', 'radio']]` allows `type` when set to
253
+ `'checkbox'` or `'radio'`.
254
+
255
+ You can use regexes, so for example `span: [['className', /^hljs-/]]` allows
256
+ any class that starts with `hljs-` on `span`s.
257
+
258
+ When comma- or space-separated values are used (such as `className`), each
259
+ value in is checked individually.
260
+ For example, to allow certain classes on `span`s for syntax highlighting, use
261
+ `span: [['className', 'number', 'operator', 'token']]`.
262
+ This will allow `'number'`, `'operator'`, and `'token'` classes, but drop
263
+ others.
264
+
265
+ ###### `clobber`
266
+
267
+ List of [*property names*][name] that clobber (`Array<string>`, default:
268
+ `defaultSchema.clobber`).
269
+
270
+ For example:
271
+
272
+ ```js
273
+ clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name']
274
+ ```
275
+
276
+ ###### `clobberPrefix`
277
+
278
+ Prefix to use before clobbering properties (`string`, default:
279
+ `defaultSchema.clobberPrefix`).
280
+
281
+ For example:
282
+
283
+ ```js
284
+ clobberPrefix: 'user-content-'
285
+ ```
286
+
287
+ ###### `protocols`
288
+
289
+ Map of [*property names*][name] to allowed protocols
290
+ (`Record<string, Array<string>>`, default: `defaultSchema.protocols`).
291
+
292
+ This defines URLs that are always allowed to have local URLs (relative to
293
+ the current website, such as `this`, `#this`, `/this`, or `?this`), and
294
+ only allowed to have remote URLs (such as `https://example.com`) if they
295
+ use a known protocol.
296
+
297
+ For example:
298
+
299
+ ```js
300
+ protocols: {
301
+ cite: ['http', 'https'],
302
+ // …
303
+ src: ['http', 'https']
304
+ }
305
+ ```
306
+
307
+ ###### `required`
308
+
309
+ Map of tag names to required [*property names*][name] with a default value
310
+ (`Record<string, Record<string, unknown>>`, default: `defaultSchema.required`).
311
+
312
+ This defines properties that must be set.
313
+ If a field does not exist (after the element was made safe), these will be
314
+ added with the given value.
315
+
316
+ For example:
317
+
318
+ ```js
319
+ required: {
320
+ input: {disabled: true, type: 'checkbox'}
321
+ }
322
+ ```
323
+
324
+ > 👉 **Note**: properties are first checked based on `schema.attributes`,
325
+ > then on `schema.required`.
326
+ > That means properties could be removed by `attributes` and then added
327
+ > again with `required`.
328
+
329
+ ###### `strip`
330
+
331
+ List of tag names to strip from the tree (`Array<string>`, default:
332
+ `defaultSchema.strip`).
333
+
334
+ By default, unsafe elements (those not in `schema.tagNames`) are replaced by
335
+ what they contain.
336
+ This option can drop their contents.
337
+
338
+ For example:
339
+
340
+ ```js
341
+ strip: ['script']
342
+ ```
343
+
344
+ ###### `tagNames`
345
+
346
+ List of allowed tag names (`Array<string>`, default: `defaultSchema.tagNames`).
347
+
348
+ For example:
349
+
350
+ ```js
351
+ tagNames: [
352
+ 'a',
353
+ 'b',
354
+ // …
355
+ 'ul',
356
+ 'var'
357
+ ]
358
+ ```
359
+
360
+ ## Types
361
+
362
+ This package is fully typed with [TypeScript][].
363
+ It exports the additional type [`Schema`][api-schema].
364
+
365
+ ## Compatibility
366
+
367
+ Projects maintained by the unified collective are compatible with maintained
368
+ versions of Node.js.
369
+
370
+ When we cut a new major release, we drop support for unmaintained versions of
371
+ Node.
372
+ This means we try to keep the current release line, `hast-util-sanitize@^5`,
373
+ compatible with Node.js 16.
374
+
375
+ ## Security
376
+
377
+ By default, `hast-util-sanitize` will make everything safe to use.
378
+ Assuming you understand that certain attributes (including a limited set of
379
+ classes) can be generated by users, and you write your CSS (and JS)
380
+ accordingly.
381
+ When used incorrectly, deviating from the defaults can open you up to a
382
+ [cross-site scripting (XSS)][xss] attack.
383
+
384
+ Use `hast-util-sanitize` after the last unsafe thing: everything after it could
385
+ be unsafe (but is fine if you do trust it).
386
+
387
+ ## Related
388
+
389
+ * [`rehype-sanitize`](https://github.com/rehypejs/rehype-sanitize)
390
+ — rehype plugin
391
+
392
+ ## Contribute
393
+
394
+ See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
395
+ ways to get started.
396
+ See [`support.md`][support] for ways to get help.
397
+
398
+ This project has a [code of conduct][coc].
399
+ By interacting with this repository, organization, or community you agree to
400
+ abide by its terms.
401
+
402
+ ## License
403
+
404
+ [MIT][license] © [Titus Wormer][author]
405
+
406
+ <!-- Definitions -->
407
+
408
+ [build-badge]: https://github.com/syntax-tree/hast-util-sanitize/workflows/main/badge.svg
409
+
410
+ [build]: https://github.com/syntax-tree/hast-util-sanitize/actions
411
+
412
+ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-sanitize.svg
413
+
414
+ [coverage]: https://codecov.io/github/syntax-tree/hast-util-sanitize
415
+
416
+ [downloads-badge]: https://img.shields.io/npm/dm/hast-util-sanitize.svg
417
+
418
+ [downloads]: https://www.npmjs.com/package/hast-util-sanitize
419
+
420
+ [size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-sanitize
421
+
422
+ [size]: https://bundlejs.com/?q=hast-util-sanitize
423
+
424
+ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
425
+
426
+ [backers-badge]: https://opencollective.com/unified/backers/badge.svg
427
+
428
+ [collective]: https://opencollective.com/unified
429
+
430
+ [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
431
+
432
+ [chat]: https://github.com/syntax-tree/unist/discussions
433
+
434
+ [npm]: https://docs.npmjs.com/cli/install
435
+
436
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
437
+
438
+ [esmsh]: https://esm.sh
439
+
440
+ [typescript]: https://www.typescriptlang.org
441
+
442
+ [license]: license
443
+
444
+ [author]: https://wooorm.com
445
+
446
+ [health]: https://github.com/syntax-tree/.github
447
+
448
+ [contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
449
+
450
+ [support]: https://github.com/syntax-tree/.github/blob/main/support.md
451
+
452
+ [coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
453
+
454
+ [hast]: https://github.com/syntax-tree/hast
455
+
456
+ [node]: https://github.com/syntax-tree/hast#nodes
457
+
458
+ [name]: https://github.com/syntax-tree/hast#propertyname
459
+
460
+ [github]: https://github.com/gjtorikian/html-pipeline/blob/a2e02ac/lib/html_pipeline/sanitization_filter.rb
461
+
462
+ [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
463
+
464
+ [rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize
465
+
466
+ [api-default-schema]: #defaultschema
467
+
468
+ [api-sanitize]: #sanitizetree-options
469
+
470
+ [api-schema]: #schema
node_modules/hast-util-to-jsx-runtime/index.d.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type {
2
+ Components,
3
+ CreateEvaluater,
4
+ ElementAttributeNameCase,
5
+ EvaluateExpression,
6
+ EvaluateProgram,
7
+ Evaluater,
8
+ ExtraProps,
9
+ Fragment,
10
+ Jsx,
11
+ JsxDev,
12
+ Options,
13
+ Props,
14
+ Source,
15
+ Space,
16
+ StylePropertyNameCase
17
+ } from './lib/types.js'
18
+ export {toJsxRuntime} from './lib/index.js'
node_modules/hast-util-to-jsx-runtime/index.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // Note: types exposed from `index.d.ts`.
2
+ export {toJsxRuntime} from './lib/index.js'
node_modules/hast-util-to-jsx-runtime/lib/index.d.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Transform a hast tree to preact, react, solid, svelte, vue, etc.,
3
+ * with an automatic JSX runtime.
4
+ *
5
+ * @param {Nodes} tree
6
+ * Tree to transform.
7
+ * @param {Options} options
8
+ * Configuration (required).
9
+ * @returns {JsxElement}
10
+ * JSX element.
11
+ */
12
+ export function toJsxRuntime(tree: Nodes, options: Options): JsxElement;
13
+ import type { Nodes } from 'hast';
14
+ import type { Options } from 'hast-util-to-jsx-runtime';
15
+ import type { JsxElement } from './types.js';
16
+ //# sourceMappingURL=index.d.ts.map
node_modules/hast-util-to-jsx-runtime/lib/index.d.ts.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AAEH,mCARW,KAAK,WAEL,OAAO,GAEL,UAAU,CAgEtB;2BAnHqD,MAAM;6BADd,0BAA0B;gCAMP,YAAY"}
node_modules/hast-util-to-jsx-runtime/lib/index.js ADDED
@@ -0,0 +1,787 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @import {Identifier, Literal, MemberExpression} from 'estree'
3
+ * @import {Jsx, JsxDev, Options, Props} from 'hast-util-to-jsx-runtime'
4
+ * @import {Element, Nodes, Parents, Root, Text} from 'hast'
5
+ * @import {MdxFlowExpressionHast, MdxTextExpressionHast} from 'mdast-util-mdx-expression'
6
+ * @import {MdxJsxFlowElementHast, MdxJsxTextElementHast} from 'mdast-util-mdx-jsx'
7
+ * @import {MdxjsEsmHast} from 'mdast-util-mdxjs-esm'
8
+ * @import {Position} from 'unist'
9
+ * @import {Child, Create, Field, JsxElement, State, Style} from './types.js'
10
+ */
11
+
12
+ import {stringify as commas} from 'comma-separated-tokens'
13
+ import {ok as assert} from 'devlop'
14
+ import {name as isIdentifierName} from 'estree-util-is-identifier-name'
15
+ import {whitespace} from 'hast-util-whitespace'
16
+ import {find, hastToReact, html, svg} from 'property-information'
17
+ import {stringify as spaces} from 'space-separated-tokens'
18
+ import styleToJs from 'style-to-js'
19
+ import {pointStart} from 'unist-util-position'
20
+ import {VFileMessage} from 'vfile-message'
21
+
22
+ // To do: next major: `Object.hasOwn`.
23
+ const own = {}.hasOwnProperty
24
+
25
+ /** @type {Map<string, number>} */
26
+ const emptyMap = new Map()
27
+
28
+ const cap = /[A-Z]/g
29
+
30
+ // `react-dom` triggers a warning for *any* white space in tables.
31
+ // To follow GFM, `mdast-util-to-hast` injects line endings between elements.
32
+ // Other tools might do so too, but they don’t do here, so we remove all of
33
+ // that.
34
+
35
+ // See: <https://github.com/facebook/react/pull/7081>.
36
+ // See: <https://github.com/facebook/react/pull/7515>.
37
+ // See: <https://github.com/remarkjs/remark-react/issues/64>.
38
+ // See: <https://github.com/rehypejs/rehype-react/pull/29>.
39
+ // See: <https://github.com/rehypejs/rehype-react/pull/32>.
40
+ // See: <https://github.com/rehypejs/rehype-react/pull/45>.
41
+ const tableElements = new Set(['table', 'tbody', 'thead', 'tfoot', 'tr'])
42
+
43
+ const tableCellElement = new Set(['td', 'th'])
44
+
45
+ const docs = 'https://github.com/syntax-tree/hast-util-to-jsx-runtime'
46
+
47
+ /**
48
+ * Transform a hast tree to preact, react, solid, svelte, vue, etc.,
49
+ * with an automatic JSX runtime.
50
+ *
51
+ * @param {Nodes} tree
52
+ * Tree to transform.
53
+ * @param {Options} options
54
+ * Configuration (required).
55
+ * @returns {JsxElement}
56
+ * JSX element.
57
+ */
58
+
59
+ export function toJsxRuntime(tree, options) {
60
+ if (!options || options.Fragment === undefined) {
61
+ throw new TypeError('Expected `Fragment` in options')
62
+ }
63
+
64
+ const filePath = options.filePath || undefined
65
+ /** @type {Create} */
66
+ let create
67
+
68
+ if (options.development) {
69
+ if (typeof options.jsxDEV !== 'function') {
70
+ throw new TypeError(
71
+ 'Expected `jsxDEV` in options when `development: true`'
72
+ )
73
+ }
74
+
75
+ create = developmentCreate(filePath, options.jsxDEV)
76
+ } else {
77
+ if (typeof options.jsx !== 'function') {
78
+ throw new TypeError('Expected `jsx` in production options')
79
+ }
80
+
81
+ if (typeof options.jsxs !== 'function') {
82
+ throw new TypeError('Expected `jsxs` in production options')
83
+ }
84
+
85
+ create = productionCreate(filePath, options.jsx, options.jsxs)
86
+ }
87
+
88
+ /** @type {State} */
89
+ const state = {
90
+ Fragment: options.Fragment,
91
+ ancestors: [],
92
+ components: options.components || {},
93
+ create,
94
+ elementAttributeNameCase: options.elementAttributeNameCase || 'react',
95
+ evaluater: options.createEvaluater ? options.createEvaluater() : undefined,
96
+ filePath,
97
+ ignoreInvalidStyle: options.ignoreInvalidStyle || false,
98
+ passKeys: options.passKeys !== false,
99
+ passNode: options.passNode || false,
100
+ schema: options.space === 'svg' ? svg : html,
101
+ stylePropertyNameCase: options.stylePropertyNameCase || 'dom',
102
+ tableCellAlignToStyle: options.tableCellAlignToStyle !== false
103
+ }
104
+
105
+ const result = one(state, tree, undefined)
106
+
107
+ // JSX element.
108
+ if (result && typeof result !== 'string') {
109
+ return result
110
+ }
111
+
112
+ // Text node or something that turned into nothing.
113
+ return state.create(
114
+ tree,
115
+ state.Fragment,
116
+ {children: result || undefined},
117
+ undefined
118
+ )
119
+ }
120
+
121
+ /**
122
+ * Transform a node.
123
+ *
124
+ * @param {State} state
125
+ * Info passed around.
126
+ * @param {Nodes} node
127
+ * Current node.
128
+ * @param {string | undefined} key
129
+ * Key.
130
+ * @returns {Child | undefined}
131
+ * Child, optional.
132
+ */
133
+ function one(state, node, key) {
134
+ if (node.type === 'element') {
135
+ return element(state, node, key)
136
+ }
137
+
138
+ if (node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') {
139
+ return mdxExpression(state, node)
140
+ }
141
+
142
+ if (node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') {
143
+ return mdxJsxElement(state, node, key)
144
+ }
145
+
146
+ if (node.type === 'mdxjsEsm') {
147
+ return mdxEsm(state, node)
148
+ }
149
+
150
+ if (node.type === 'root') {
151
+ return root(state, node, key)
152
+ }
153
+
154
+ if (node.type === 'text') {
155
+ return text(state, node)
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Handle element.
161
+ *
162
+ * @param {State} state
163
+ * Info passed around.
164
+ * @param {Element} node
165
+ * Current node.
166
+ * @param {string | undefined} key
167
+ * Key.
168
+ * @returns {Child | undefined}
169
+ * Child, optional.
170
+ */
171
+ function element(state, node, key) {
172
+ const parentSchema = state.schema
173
+ let schema = parentSchema
174
+
175
+ if (node.tagName.toLowerCase() === 'svg' && parentSchema.space === 'html') {
176
+ schema = svg
177
+ state.schema = schema
178
+ }
179
+
180
+ state.ancestors.push(node)
181
+
182
+ const type = findComponentFromName(state, node.tagName, false)
183
+ const props = createElementProps(state, node)
184
+ let children = createChildren(state, node)
185
+
186
+ if (tableElements.has(node.tagName)) {
187
+ children = children.filter(function (child) {
188
+ return typeof child === 'string' ? !whitespace(child) : true
189
+ })
190
+ }
191
+
192
+ addNode(state, props, type, node)
193
+ addChildren(props, children)
194
+
195
+ // Restore.
196
+ state.ancestors.pop()
197
+ state.schema = parentSchema
198
+
199
+ return state.create(node, type, props, key)
200
+ }
201
+
202
+ /**
203
+ * Handle MDX expression.
204
+ *
205
+ * @param {State} state
206
+ * Info passed around.
207
+ * @param {MdxFlowExpressionHast | MdxTextExpressionHast} node
208
+ * Current node.
209
+ * @returns {Child | undefined}
210
+ * Child, optional.
211
+ */
212
+ function mdxExpression(state, node) {
213
+ if (node.data && node.data.estree && state.evaluater) {
214
+ const program = node.data.estree
215
+ const expression = program.body[0]
216
+ assert(expression.type === 'ExpressionStatement')
217
+
218
+ // Assume result is a child.
219
+ return /** @type {Child | undefined} */ (
220
+ state.evaluater.evaluateExpression(expression.expression)
221
+ )
222
+ }
223
+
224
+ crashEstree(state, node.position)
225
+ }
226
+
227
+ /**
228
+ * Handle MDX ESM.
229
+ *
230
+ * @param {State} state
231
+ * Info passed around.
232
+ * @param {MdxjsEsmHast} node
233
+ * Current node.
234
+ * @returns {Child | undefined}
235
+ * Child, optional.
236
+ */
237
+ function mdxEsm(state, node) {
238
+ if (node.data && node.data.estree && state.evaluater) {
239
+ // Assume result is a child.
240
+ return /** @type {Child | undefined} */ (
241
+ state.evaluater.evaluateProgram(node.data.estree)
242
+ )
243
+ }
244
+
245
+ crashEstree(state, node.position)
246
+ }
247
+
248
+ /**
249
+ * Handle MDX JSX.
250
+ *
251
+ * @param {State} state
252
+ * Info passed around.
253
+ * @param {MdxJsxFlowElementHast | MdxJsxTextElementHast} node
254
+ * Current node.
255
+ * @param {string | undefined} key
256
+ * Key.
257
+ * @returns {Child | undefined}
258
+ * Child, optional.
259
+ */
260
+ function mdxJsxElement(state, node, key) {
261
+ const parentSchema = state.schema
262
+ let schema = parentSchema
263
+
264
+ if (node.name === 'svg' && parentSchema.space === 'html') {
265
+ schema = svg
266
+ state.schema = schema
267
+ }
268
+
269
+ state.ancestors.push(node)
270
+
271
+ const type =
272
+ node.name === null
273
+ ? state.Fragment
274
+ : findComponentFromName(state, node.name, true)
275
+ const props = createJsxElementProps(state, node)
276
+ const children = createChildren(state, node)
277
+
278
+ addNode(state, props, type, node)
279
+ addChildren(props, children)
280
+
281
+ // Restore.
282
+ state.ancestors.pop()
283
+ state.schema = parentSchema
284
+
285
+ return state.create(node, type, props, key)
286
+ }
287
+
288
+ /**
289
+ * Handle root.
290
+ *
291
+ * @param {State} state
292
+ * Info passed around.
293
+ * @param {Root} node
294
+ * Current node.
295
+ * @param {string | undefined} key
296
+ * Key.
297
+ * @returns {Child | undefined}
298
+ * Child, optional.
299
+ */
300
+ function root(state, node, key) {
301
+ /** @type {Props} */
302
+ const props = {}
303
+
304
+ addChildren(props, createChildren(state, node))
305
+
306
+ return state.create(node, state.Fragment, props, key)
307
+ }
308
+
309
+ /**
310
+ * Handle text.
311
+ *
312
+ * @param {State} _
313
+ * Info passed around.
314
+ * @param {Text} node
315
+ * Current node.
316
+ * @returns {Child | undefined}
317
+ * Child, optional.
318
+ */
319
+ function text(_, node) {
320
+ return node.value
321
+ }
322
+
323
+ /**
324
+ * Add `node` to props.
325
+ *
326
+ * @param {State} state
327
+ * Info passed around.
328
+ * @param {Props} props
329
+ * Props.
330
+ * @param {unknown} type
331
+ * Type.
332
+ * @param {Element | MdxJsxFlowElementHast | MdxJsxTextElementHast} node
333
+ * Node.
334
+ * @returns {undefined}
335
+ * Nothing.
336
+ */
337
+ function addNode(state, props, type, node) {
338
+ // If this is swapped out for a component:
339
+ if (typeof type !== 'string' && type !== state.Fragment && state.passNode) {
340
+ props.node = node
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Add children to props.
346
+ *
347
+ * @param {Props} props
348
+ * Props.
349
+ * @param {Array<Child>} children
350
+ * Children.
351
+ * @returns {undefined}
352
+ * Nothing.
353
+ */
354
+ function addChildren(props, children) {
355
+ if (children.length > 0) {
356
+ const value = children.length > 1 ? children : children[0]
357
+
358
+ if (value) {
359
+ props.children = value
360
+ }
361
+ }
362
+ }
363
+
364
+ /**
365
+ * @param {string | undefined} _
366
+ * Path to file.
367
+ * @param {Jsx} jsx
368
+ * Dynamic.
369
+ * @param {Jsx} jsxs
370
+ * Static.
371
+ * @returns {Create}
372
+ * Create a production element.
373
+ */
374
+ function productionCreate(_, jsx, jsxs) {
375
+ return create
376
+ /** @type {Create} */
377
+ function create(_, type, props, key) {
378
+ // Only an array when there are 2 or more children.
379
+ const isStaticChildren = Array.isArray(props.children)
380
+ const fn = isStaticChildren ? jsxs : jsx
381
+ return key ? fn(type, props, key) : fn(type, props)
382
+ }
383
+ }
384
+
385
+ /**
386
+ * @param {string | undefined} filePath
387
+ * Path to file.
388
+ * @param {JsxDev} jsxDEV
389
+ * Development.
390
+ * @returns {Create}
391
+ * Create a development element.
392
+ */
393
+ function developmentCreate(filePath, jsxDEV) {
394
+ return create
395
+ /** @type {Create} */
396
+ function create(node, type, props, key) {
397
+ // Only an array when there are 2 or more children.
398
+ const isStaticChildren = Array.isArray(props.children)
399
+ const point = pointStart(node)
400
+ return jsxDEV(
401
+ type,
402
+ props,
403
+ key,
404
+ isStaticChildren,
405
+ {
406
+ columnNumber: point ? point.column - 1 : undefined,
407
+ fileName: filePath,
408
+ lineNumber: point ? point.line : undefined
409
+ },
410
+ undefined
411
+ )
412
+ }
413
+ }
414
+
415
+ /**
416
+ * Create props from an element.
417
+ *
418
+ * @param {State} state
419
+ * Info passed around.
420
+ * @param {Element} node
421
+ * Current element.
422
+ * @returns {Props}
423
+ * Props.
424
+ */
425
+ function createElementProps(state, node) {
426
+ /** @type {Props} */
427
+ const props = {}
428
+ /** @type {string | undefined} */
429
+ let alignValue
430
+ /** @type {string} */
431
+ let prop
432
+
433
+ for (prop in node.properties) {
434
+ if (prop !== 'children' && own.call(node.properties, prop)) {
435
+ const result = createProperty(state, prop, node.properties[prop])
436
+
437
+ if (result) {
438
+ const [key, value] = result
439
+
440
+ if (
441
+ state.tableCellAlignToStyle &&
442
+ key === 'align' &&
443
+ typeof value === 'string' &&
444
+ tableCellElement.has(node.tagName)
445
+ ) {
446
+ alignValue = value
447
+ } else {
448
+ props[key] = value
449
+ }
450
+ }
451
+ }
452
+ }
453
+
454
+ if (alignValue) {
455
+ // Assume style is an object.
456
+ const style = /** @type {Style} */ (props.style || (props.style = {}))
457
+ style[state.stylePropertyNameCase === 'css' ? 'text-align' : 'textAlign'] =
458
+ alignValue
459
+ }
460
+
461
+ return props
462
+ }
463
+
464
+ /**
465
+ * Create props from a JSX element.
466
+ *
467
+ * @param {State} state
468
+ * Info passed around.
469
+ * @param {MdxJsxFlowElementHast | MdxJsxTextElementHast} node
470
+ * Current JSX element.
471
+ * @returns {Props}
472
+ * Props.
473
+ */
474
+ function createJsxElementProps(state, node) {
475
+ /** @type {Props} */
476
+ const props = {}
477
+
478
+ for (const attribute of node.attributes) {
479
+ if (attribute.type === 'mdxJsxExpressionAttribute') {
480
+ if (attribute.data && attribute.data.estree && state.evaluater) {
481
+ const program = attribute.data.estree
482
+ const expression = program.body[0]
483
+ assert(expression.type === 'ExpressionStatement')
484
+ const objectExpression = expression.expression
485
+ assert(objectExpression.type === 'ObjectExpression')
486
+ const property = objectExpression.properties[0]
487
+ assert(property.type === 'SpreadElement')
488
+
489
+ Object.assign(
490
+ props,
491
+ state.evaluater.evaluateExpression(property.argument)
492
+ )
493
+ } else {
494
+ crashEstree(state, node.position)
495
+ }
496
+ } else {
497
+ // For JSX, the author is responsible of passing in the correct values.
498
+ const name = attribute.name
499
+ /** @type {unknown} */
500
+ let value
501
+
502
+ if (attribute.value && typeof attribute.value === 'object') {
503
+ if (
504
+ attribute.value.data &&
505
+ attribute.value.data.estree &&
506
+ state.evaluater
507
+ ) {
508
+ const program = attribute.value.data.estree
509
+ const expression = program.body[0]
510
+ assert(expression.type === 'ExpressionStatement')
511
+ value = state.evaluater.evaluateExpression(expression.expression)
512
+ } else {
513
+ crashEstree(state, node.position)
514
+ }
515
+ } else {
516
+ value = attribute.value === null ? true : attribute.value
517
+ }
518
+
519
+ // Assume a prop.
520
+ props[name] = /** @type {Props[keyof Props]} */ (value)
521
+ }
522
+ }
523
+
524
+ return props
525
+ }
526
+
527
+ /**
528
+ * Create children.
529
+ *
530
+ * @param {State} state
531
+ * Info passed around.
532
+ * @param {Parents} node
533
+ * Current element.
534
+ * @returns {Array<Child>}
535
+ * Children.
536
+ */
537
+ function createChildren(state, node) {
538
+ /** @type {Array<Child>} */
539
+ const children = []
540
+ let index = -1
541
+ /** @type {Map<string, number>} */
542
+ // Note: test this when Solid doesn’t want to merge my upcoming PR.
543
+ /* c8 ignore next */
544
+ const countsByName = state.passKeys ? new Map() : emptyMap
545
+
546
+ while (++index < node.children.length) {
547
+ const child = node.children[index]
548
+ /** @type {string | undefined} */
549
+ let key
550
+
551
+ if (state.passKeys) {
552
+ const name =
553
+ child.type === 'element'
554
+ ? child.tagName
555
+ : child.type === 'mdxJsxFlowElement' ||
556
+ child.type === 'mdxJsxTextElement'
557
+ ? child.name
558
+ : undefined
559
+
560
+ if (name) {
561
+ const count = countsByName.get(name) || 0
562
+ key = name + '-' + count
563
+ countsByName.set(name, count + 1)
564
+ }
565
+ }
566
+
567
+ const result = one(state, child, key)
568
+ if (result !== undefined) children.push(result)
569
+ }
570
+
571
+ return children
572
+ }
573
+
574
+ /**
575
+ * Handle a property.
576
+ *
577
+ * @param {State} state
578
+ * Info passed around.
579
+ * @param {string} prop
580
+ * Key.
581
+ * @param {Array<number | string> | boolean | number | string | null | undefined} value
582
+ * hast property value.
583
+ * @returns {Field | undefined}
584
+ * Field for runtime, optional.
585
+ */
586
+ function createProperty(state, prop, value) {
587
+ const info = find(state.schema, prop)
588
+
589
+ // Ignore nullish and `NaN` values.
590
+ if (
591
+ value === null ||
592
+ value === undefined ||
593
+ (typeof value === 'number' && Number.isNaN(value))
594
+ ) {
595
+ return
596
+ }
597
+
598
+ if (Array.isArray(value)) {
599
+ // Accept `array`.
600
+ // Most props are space-separated.
601
+ value = info.commaSeparated ? commas(value) : spaces(value)
602
+ }
603
+
604
+ // React only accepts `style` as object.
605
+ if (info.property === 'style') {
606
+ let styleObject =
607
+ typeof value === 'object' ? value : parseStyle(state, String(value))
608
+
609
+ if (state.stylePropertyNameCase === 'css') {
610
+ styleObject = transformStylesToCssCasing(styleObject)
611
+ }
612
+
613
+ return ['style', styleObject]
614
+ }
615
+
616
+ return [
617
+ state.elementAttributeNameCase === 'react' && info.space
618
+ ? hastToReact[info.property] || info.property
619
+ : info.attribute,
620
+ value
621
+ ]
622
+ }
623
+
624
+ /**
625
+ * Parse a CSS declaration to an object.
626
+ *
627
+ * @param {State} state
628
+ * Info passed around.
629
+ * @param {string} value
630
+ * CSS declarations.
631
+ * @returns {Style}
632
+ * Properties.
633
+ * @throws
634
+ * Throws `VFileMessage` when CSS cannot be parsed.
635
+ */
636
+ function parseStyle(state, value) {
637
+ try {
638
+ return styleToJs(value, {reactCompat: true})
639
+ } catch (error) {
640
+ if (state.ignoreInvalidStyle) {
641
+ return {}
642
+ }
643
+
644
+ const cause = /** @type {Error} */ (error)
645
+ const message = new VFileMessage('Cannot parse `style` attribute', {
646
+ ancestors: state.ancestors,
647
+ cause,
648
+ ruleId: 'style',
649
+ source: 'hast-util-to-jsx-runtime'
650
+ })
651
+ message.file = state.filePath || undefined
652
+ message.url = docs + '#cannot-parse-style-attribute'
653
+
654
+ throw message
655
+ }
656
+ }
657
+
658
+ /**
659
+ * Create a JSX name from a string.
660
+ *
661
+ * @param {State} state
662
+ * To do.
663
+ * @param {string} name
664
+ * Name.
665
+ * @param {boolean} allowExpression
666
+ * Allow member expressions and identifiers.
667
+ * @returns {unknown}
668
+ * To do.
669
+ */
670
+ function findComponentFromName(state, name, allowExpression) {
671
+ /** @type {Identifier | Literal | MemberExpression} */
672
+ let result
673
+
674
+ if (!allowExpression) {
675
+ result = {type: 'Literal', value: name}
676
+ } else if (name.includes('.')) {
677
+ const identifiers = name.split('.')
678
+ let index = -1
679
+ /** @type {Identifier | Literal | MemberExpression | undefined} */
680
+ let node
681
+
682
+ while (++index < identifiers.length) {
683
+ /** @type {Identifier | Literal} */
684
+ const prop = isIdentifierName(identifiers[index])
685
+ ? {type: 'Identifier', name: identifiers[index]}
686
+ : {type: 'Literal', value: identifiers[index]}
687
+ node = node
688
+ ? {
689
+ type: 'MemberExpression',
690
+ object: node,
691
+ property: prop,
692
+ computed: Boolean(index && prop.type === 'Literal'),
693
+ optional: false
694
+ }
695
+ : prop
696
+ }
697
+
698
+ assert(node, 'always a result')
699
+ result = node
700
+ } else {
701
+ result =
702
+ isIdentifierName(name) && !/^[a-z]/.test(name)
703
+ ? {type: 'Identifier', name}
704
+ : {type: 'Literal', value: name}
705
+ }
706
+
707
+ // Only literals can be passed in `components` currently.
708
+ // No identifiers / member expressions.
709
+ if (result.type === 'Literal') {
710
+ const name = /** @type {string | number} */ (result.value)
711
+ return own.call(state.components, name) ? state.components[name] : name
712
+ }
713
+
714
+ // Assume component.
715
+ if (state.evaluater) {
716
+ return state.evaluater.evaluateExpression(result)
717
+ }
718
+
719
+ crashEstree(state)
720
+ }
721
+
722
+ /**
723
+ * @param {State} state
724
+ * @param {Position | undefined} [place]
725
+ * @returns {never}
726
+ */
727
+ function crashEstree(state, place) {
728
+ const message = new VFileMessage(
729
+ 'Cannot handle MDX estrees without `createEvaluater`',
730
+ {
731
+ ancestors: state.ancestors,
732
+ place,
733
+ ruleId: 'mdx-estree',
734
+ source: 'hast-util-to-jsx-runtime'
735
+ }
736
+ )
737
+ message.file = state.filePath || undefined
738
+ message.url = docs + '#cannot-handle-mdx-estrees-without-createevaluater'
739
+
740
+ throw message
741
+ }
742
+
743
+ /**
744
+ * Transform a DOM casing style object to a CSS casing style object.
745
+ *
746
+ * @param {Style} domCasing
747
+ * @returns {Style}
748
+ */
749
+ function transformStylesToCssCasing(domCasing) {
750
+ /** @type {Style} */
751
+ const cssCasing = {}
752
+ /** @type {string} */
753
+ let from
754
+
755
+ for (from in domCasing) {
756
+ if (own.call(domCasing, from)) {
757
+ cssCasing[transformStyleToCssCasing(from)] = domCasing[from]
758
+ }
759
+ }
760
+
761
+ return cssCasing
762
+ }
763
+
764
+ /**
765
+ * Transform a DOM casing style field to a CSS casing style field.
766
+ *
767
+ * @param {string} from
768
+ * @returns {string}
769
+ */
770
+ function transformStyleToCssCasing(from) {
771
+ let to = from.replace(cap, toDash)
772
+ // Handle `ms-xxx` -> `-ms-xxx`.
773
+ if (to.slice(0, 3) === 'ms-') to = '-' + to
774
+ return to
775
+ }
776
+
777
+ /**
778
+ * Make `$0` dash cased.
779
+ *
780
+ * @param {string} $0
781
+ * Capitalized ASCII leter.
782
+ * @returns {string}
783
+ * Dash and lower letter.
784
+ */
785
+ function toDash($0) {
786
+ return '-' + $0.toLowerCase()
787
+ }
node_modules/hast-util-to-jsx-runtime/lib/types.d.ts ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {Expression, Program} from 'estree'
2
+ import type {Element, Nodes, Parents} from 'hast'
3
+ import type {
4
+ MdxJsxFlowElementHast,
5
+ MdxJsxTextElementHast
6
+ } from 'mdast-util-mdx-jsx'
7
+ import type {Schema} from 'property-information'
8
+
9
+ /**
10
+ * Child.
11
+ */
12
+ export type Child = JsxElement | string | null | undefined
13
+
14
+ /**
15
+ * Possible components to use.
16
+ *
17
+ * Each key is a tag name typed in `JSX.IntrinsicElements`.
18
+ * Each value is either a different tag name, or a component accepting the
19
+ * corresponding props (and an optional `node` prop if `passNode` is on).
20
+ *
21
+ * You can access props at `JSX.IntrinsicElements`.
22
+ * For example, to find props for `a`, use `JSX.IntrinsicElements['a']`.
23
+ */
24
+ // Note: this type has to be in `.ts` or `.d.ts`, otherwise TSC hardcodes
25
+ // react into the `.d.ts` file.
26
+ export type Components = {
27
+ [TagName in keyof JsxIntrinsicElements]:
28
+ | Component<JsxIntrinsicElements[TagName] & ExtraProps>
29
+ | keyof JsxIntrinsicElements
30
+ }
31
+
32
+ /**
33
+ * Function or class component.
34
+ *
35
+ * You can access props at `JsxIntrinsicElements`.
36
+ * For example, to find props for `a`, use `JsxIntrinsicElements['a']`.
37
+ *
38
+ * @typeParam ComponentProps
39
+ * Props type.
40
+ */
41
+ type Component<ComponentProps> =
42
+ | ClassComponent<ComponentProps>
43
+ | FunctionComponent<ComponentProps>
44
+
45
+ /**
46
+ * Create an evaluator that turns ESTree ASTs from embedded MDX into values.
47
+ */
48
+ export type CreateEvaluater = () => Evaluater
49
+
50
+ /**
51
+ * Create something in development or production.
52
+ */
53
+ export type Create = (
54
+ node: Nodes,
55
+ type: unknown,
56
+ props: Props,
57
+ key: string | undefined
58
+ ) => JsxElement
59
+
60
+ /**
61
+ * Class component: given props, returns an instance.
62
+ *
63
+ * @typeParam ComponentProps
64
+ * Props type.
65
+ * @param props
66
+ * Props.
67
+ * @returns
68
+ * Instance.
69
+ */
70
+ type ClassComponent<ComponentProps> = new (
71
+ props: ComponentProps
72
+ ) => JsxElementClass
73
+
74
+ /**
75
+ * Casing to use for attribute names.
76
+ *
77
+ * HTML casing is for example `class`, `stroke-linecap`, `xml:lang`.
78
+ * React casing is for example `className`, `strokeLinecap`, `xmlLang`.
79
+ */
80
+ export type ElementAttributeNameCase = 'html' | 'react'
81
+
82
+ /**
83
+ * Turn an MDX expression into a value.
84
+ */
85
+ export type EvaluateExpression = (expression: Expression) => unknown
86
+ /**
87
+ * Turn an MDX program (export/import statements) into a value.
88
+ */
89
+ export type EvaluateProgram = (expression: Program) => unknown
90
+
91
+ /**
92
+ * Evaluator that turns ESTree ASTs from embedded MDX into values.
93
+ */
94
+ export interface Evaluater {
95
+ /**
96
+ * Evaluate an expression.
97
+ */
98
+ evaluateExpression: EvaluateExpression
99
+ /**
100
+ * Evaluate a program.
101
+ */
102
+ evaluateProgram: EvaluateProgram
103
+ }
104
+
105
+ /**
106
+ * Extra fields we pass.
107
+ */
108
+ export interface ExtraProps {
109
+ /**
110
+ * Node (hast),
111
+ * passed when `passNode` is on.
112
+ */
113
+ node?: Element | undefined
114
+ }
115
+
116
+ /**
117
+ * Property field.
118
+ */
119
+ export type Field = [string, Value]
120
+
121
+ /**
122
+ * Represent the children, typically a symbol.
123
+ */
124
+ export type Fragment = unknown
125
+
126
+ /**
127
+ * Basic functional component: given props, returns an element.
128
+ *
129
+ * @typeParam ComponentProps
130
+ * Props type.
131
+ * @param props
132
+ * Props.
133
+ * @returns
134
+ * Result.
135
+ */
136
+ type FunctionComponent<ComponentProps> = (
137
+ props: ComponentProps
138
+ ) => JsxElement | string | null | undefined
139
+
140
+ /**
141
+ * Conditional type for a class.
142
+ */
143
+ // @ts-ignore: conditionally defined;
144
+ // it used to be possible to detect that with `any extends X ? X : Y`
145
+ // but no longer.
146
+ export type JsxElementClass = JSX.ElementClass
147
+
148
+ /**
149
+ * Conditional type for a node object.
150
+ */
151
+ // @ts-ignore: conditionally defined;
152
+ // it used to be possible to detect that with `any extends X ? X : Y`
153
+ // but no longer.
154
+ export type JsxElement = JSX.Element
155
+
156
+ /**
157
+ * Conditional type for a record of tag names to corresponding props.
158
+ */
159
+ // @ts-ignore: conditionally defined;
160
+ // it used to be possible to detect that with `any extends X ? X : Y`
161
+ // but no longer.
162
+ export type JsxIntrinsicElements = JSX.IntrinsicElements
163
+
164
+ /**
165
+ * Create a development element.
166
+ */
167
+ export type JsxDev = (
168
+ // `any` because runtimes often have complex framework-specific types here.
169
+ // type-coverage:ignore-next-line
170
+ type: any,
171
+ props: Props,
172
+ key: string | undefined,
173
+ isStaticChildren: boolean,
174
+ source: Source,
175
+ self: undefined
176
+ ) => JsxElement
177
+
178
+ /**
179
+ * Create a production element.
180
+ */
181
+ export type Jsx = (
182
+ // `any` because runtimes often have complex framework-specific types here.
183
+ // type-coverage:ignore-next-line
184
+ type: any,
185
+ props: Props,
186
+ key?: string | undefined
187
+ ) => JsxElement
188
+
189
+ /**
190
+ * Configuration.
191
+ */
192
+ export interface OptionsBase {
193
+ /**
194
+ * Components to use (optional).
195
+ */
196
+ components?: Partial<Components> | null | undefined
197
+ /**
198
+ * Create an evaluator that turns ESTree ASTs into values (optional).
199
+ */
200
+ createEvaluater?: CreateEvaluater | null | undefined
201
+ /**
202
+ * Specify casing to use for attribute names (default: `'react'`).
203
+ */
204
+ elementAttributeNameCase?: ElementAttributeNameCase | null | undefined
205
+ /**
206
+ * File path to the original source file (optional).
207
+ *
208
+ * Passed in source info to `jsxDEV` when using the automatic runtime with
209
+ * `development: true`.
210
+ */
211
+ filePath?: string | null | undefined
212
+ /**
213
+ * Ignore invalid CSS in `style` props (default: `false`);
214
+ * the default behavior is to throw an error.
215
+ */
216
+ ignoreInvalidStyle?: boolean | null | undefined
217
+ /**
218
+ * Generate keys to optimize frameworks that support them (default: `true`).
219
+ *
220
+ * > 👉 **Note**: Solid currently fails if keys are passed.
221
+ */
222
+ passKeys?: boolean | null | undefined
223
+ /**
224
+ * Pass the hast element node to components (default: `false`).
225
+ */
226
+ passNode?: boolean | null | undefined
227
+ /**
228
+ * Whether `tree` is in the `'html'` or `'svg'` space (default: `'html'`).
229
+ *
230
+ * When an `<svg>` element is found in the HTML space, this package already
231
+ * automatically switches to and from the SVG space when entering and exiting
232
+ * it.
233
+ */
234
+ space?: Space | null | undefined
235
+ /**
236
+ * Specify casing to use for property names in `style` objects (default:
237
+ * `'dom'`).
238
+ */
239
+ stylePropertyNameCase?: StylePropertyNameCase | null | undefined
240
+ /**
241
+ * Turn obsolete `align` props on `td` and `th` into CSS `style` props
242
+ * (default: `true`).
243
+ */
244
+ tableCellAlignToStyle?: boolean | null | undefined
245
+ }
246
+
247
+ /**
248
+ * Configuration (development).
249
+ */
250
+ export interface OptionsDevelopment extends OptionsBase {
251
+ /**
252
+ * Fragment.
253
+ */
254
+ Fragment: Fragment
255
+ /**
256
+ * Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off).
257
+ */
258
+ development: true
259
+ /**
260
+ * Development JSX.
261
+ */
262
+ jsxDEV: JsxDev
263
+ /**
264
+ * Static JSX (optional).
265
+ */
266
+ jsxs?: Jsx | null | undefined
267
+ /**
268
+ * Dynamic JSX (optional).
269
+ */
270
+ jsx?: Jsx | null | undefined
271
+ }
272
+
273
+ /**
274
+ * Configuration (production).
275
+ */
276
+ export interface OptionsProduction extends OptionsBase {
277
+ /**
278
+ * Fragment.
279
+ */
280
+ Fragment: Fragment
281
+ /**
282
+ * Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off) (optional).
283
+ */
284
+ development?: false | null | undefined
285
+ /**
286
+ * Development JSX (optional).
287
+ */
288
+ jsxDEV?: JsxDev | null | undefined
289
+ /**
290
+ * Static JSX.
291
+ */
292
+ jsxs: Jsx
293
+ /**
294
+ * Dynamic JSX.
295
+ */
296
+ jsx: Jsx
297
+ }
298
+
299
+ /**
300
+ * Configuration (production or development).
301
+ */
302
+ export interface OptionsUnknown extends OptionsBase {
303
+ /**
304
+ * Fragment.
305
+ */
306
+ Fragment: Fragment
307
+ /**
308
+ * Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off).
309
+ */
310
+ development: boolean
311
+ /**
312
+ * Dynamic JSX (optional).
313
+ */
314
+ jsx?: Jsx | null | undefined
315
+ /**
316
+ * Development JSX (optional).
317
+ */
318
+ jsxDEV?: JsxDev | null | undefined
319
+ /**
320
+ * Static JSX (optional).
321
+ */
322
+ jsxs?: Jsx | null | undefined
323
+ }
324
+
325
+ export type Options = OptionsDevelopment | OptionsProduction | OptionsUnknown
326
+
327
+ /**
328
+ * Properties and children.
329
+ */
330
+ export interface Props {
331
+ [prop: string]:
332
+ | Array<Child>
333
+ | Child
334
+ | Element
335
+ | MdxJsxFlowElementHast
336
+ | MdxJsxTextElementHast
337
+ | Value
338
+ | undefined
339
+ children?: Array<Child> | Child
340
+ node?: Element | MdxJsxFlowElementHast | MdxJsxTextElementHast | undefined
341
+ }
342
+
343
+ /**
344
+ * Info about source.
345
+ */
346
+ export interface Source {
347
+ /**
348
+ * Column where thing starts (0-indexed).
349
+ */
350
+ columnNumber: number | undefined
351
+ /**
352
+ * Name of source file.
353
+ */
354
+ fileName: string | undefined
355
+ /**
356
+ * Line where thing starts (1-indexed).
357
+ */
358
+ lineNumber: number | undefined
359
+ }
360
+
361
+ /**
362
+ * Namespace.
363
+ *
364
+ * > 👉 **Note**: hast is not XML.
365
+ * > It supports SVG as embedded in HTML.
366
+ * > It does not support the features available in XML.
367
+ * > Passing SVG might break but fragments of modern SVG should be fine.
368
+ * > Use `xast` if you need to support SVG as XML.
369
+ */
370
+ export type Space = 'html' | 'svg'
371
+
372
+ /**
373
+ * Info passed around.
374
+ */
375
+ export interface State {
376
+ /**
377
+ * Fragment symbol.
378
+ */
379
+ Fragment: unknown
380
+ /**
381
+ * Stack of parents.
382
+ */
383
+ ancestors: Array<Parents>
384
+ /**
385
+ * Components to swap.
386
+ */
387
+ components: Partial<Components>
388
+ /**
389
+ * Create something in development or production.
390
+ */
391
+ create: Create
392
+ /**
393
+ * Casing to use for attribute names.
394
+ */
395
+ elementAttributeNameCase: ElementAttributeNameCase
396
+ /**
397
+ * Evaluator that turns ESTree ASTs into values.
398
+ */
399
+ evaluater: Evaluater | undefined
400
+ /**
401
+ * File path.
402
+ */
403
+ filePath: string | undefined
404
+ /**
405
+ * Ignore invalid CSS in `style` props.
406
+ */
407
+ ignoreInvalidStyle: boolean
408
+ /**
409
+ * Generate keys to optimize frameworks that support them.
410
+ */
411
+ passKeys: boolean
412
+ /**
413
+ * Pass `node` to components.
414
+ */
415
+ passNode: boolean
416
+ /**
417
+ * Current schema.
418
+ */
419
+ schema: Schema
420
+ /**
421
+ * Casing to use for property names in `style` objects.
422
+ */
423
+ stylePropertyNameCase: StylePropertyNameCase
424
+ /**
425
+ * Turn obsolete `align` props on `td` and `th` into CSS `style` props.
426
+ */
427
+ tableCellAlignToStyle: boolean
428
+ }
429
+
430
+ /**
431
+ * Casing to use for property names in `style` objects.
432
+ *
433
+ * CSS casing is for example `background-color` and `-webkit-line-clamp`.
434
+ * DOM casing is for example `backgroundColor` and `WebkitLineClamp`.
435
+ */
436
+ export type StylePropertyNameCase = 'css' | 'dom'
437
+
438
+ /**
439
+ * Style map.
440
+ */
441
+ type Style = Record<string, string>
442
+
443
+ /**
444
+ * Primitive property value and `Style` map.
445
+ */
446
+ type Value = Style | boolean | number | string
node_modules/hast-util-to-jsx-runtime/lib/types.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // TypeScript only.
2
+ export {}
node_modules/hast-util-to-jsx-runtime/license ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (The MIT License)
2
+
3
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/hast-util-to-jsx-runtime/package.json ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
3
+ "bugs": "https://github.com/syntax-tree/hast-util-to-jsx-runtime/issues",
4
+ "contributors": [
5
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
6
+ ],
7
+ "dependencies": {
8
+ "@types/estree": "^1.0.0",
9
+ "@types/hast": "^3.0.0",
10
+ "@types/unist": "^3.0.0",
11
+ "comma-separated-tokens": "^2.0.0",
12
+ "devlop": "^1.0.0",
13
+ "estree-util-is-identifier-name": "^3.0.0",
14
+ "hast-util-whitespace": "^3.0.0",
15
+ "mdast-util-mdx-expression": "^2.0.0",
16
+ "mdast-util-mdx-jsx": "^3.0.0",
17
+ "mdast-util-mdxjs-esm": "^2.0.0",
18
+ "property-information": "^7.0.0",
19
+ "space-separated-tokens": "^2.0.0",
20
+ "style-to-js": "^1.0.0",
21
+ "unist-util-position": "^5.0.0",
22
+ "vfile-message": "^4.0.0"
23
+ },
24
+ "description": "hast utility to transform to preact, react, solid, svelte, vue, etc",
25
+ "devDependencies": {
26
+ "@types/node": "^22.0.0",
27
+ "@types/react": "^19.0.0",
28
+ "@types/react-dom": "^19.0.0",
29
+ "c8": "^10.0.0",
30
+ "esbuild": "^0.25.0",
31
+ "estree-util-visit": "^2.0.0",
32
+ "hastscript": "^9.0.0",
33
+ "prettier": "^3.0.0",
34
+ "react": "^19.0.0",
35
+ "react-dom": "^19.0.0",
36
+ "remark-cli": "^12.0.0",
37
+ "remark-preset-wooorm": "^11.0.0",
38
+ "sval": "^0.6.0",
39
+ "type-coverage": "^2.0.0",
40
+ "typescript": "^5.0.0",
41
+ "xo": "^0.60.0"
42
+ },
43
+ "exports": "./index.js",
44
+ "files": [
45
+ "lib/",
46
+ "index.d.ts",
47
+ "index.js"
48
+ ],
49
+ "funding": {
50
+ "type": "opencollective",
51
+ "url": "https://opencollective.com/unified"
52
+ },
53
+ "keywords": [
54
+ "hast-util",
55
+ "hast",
56
+ "html",
57
+ "preact",
58
+ "react",
59
+ "solid",
60
+ "svelte",
61
+ "unist",
62
+ "utility",
63
+ "util",
64
+ "vue"
65
+ ],
66
+ "license": "MIT",
67
+ "name": "hast-util-to-jsx-runtime",
68
+ "prettier": {
69
+ "bracketSpacing": false,
70
+ "semi": false,
71
+ "singleQuote": true,
72
+ "tabWidth": 2,
73
+ "trailingComma": "none",
74
+ "useTabs": false
75
+ },
76
+ "remarkConfig": {
77
+ "plugins": [
78
+ "remark-preset-wooorm"
79
+ ]
80
+ },
81
+ "repository": "syntax-tree/hast-util-to-jsx-runtime",
82
+ "scripts": {
83
+ "build": "tsc --build --clean && tsc --build && type-coverage",
84
+ "format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
85
+ "generate": "esbuild --bundle --format=esm --minify --outfile=example/hast-util-to-jsx-runtime.min.js --target=es2020 .",
86
+ "prepack": "npm run build && npm run format",
87
+ "test-api": "node --conditions development test/index.js",
88
+ "test-coverage": "c8 --100 --reporter lcov -- npm run test-api",
89
+ "test": "npm run generate && npm run build && npm run format && npm run test-coverage"
90
+ },
91
+ "sideEffects": false,
92
+ "typeCoverage": {
93
+ "atLeast": 100,
94
+ "detail": true,
95
+ "ignoreCatch": true,
96
+ "ignoreFiles": [
97
+ "example/**/*.js"
98
+ ],
99
+ "strict": true
100
+ },
101
+ "type": "module",
102
+ "version": "2.3.6",
103
+ "xo": {
104
+ "overrides": [
105
+ {
106
+ "files": [
107
+ "**/*.d.ts"
108
+ ],
109
+ "rules": {
110
+ "@typescript-eslint/array-type": [
111
+ "error",
112
+ {
113
+ "default": "generic"
114
+ }
115
+ ],
116
+ "@typescript-eslint/ban-ts-comment": 0,
117
+ "@typescript-eslint/ban-types": [
118
+ "error",
119
+ {
120
+ "extendDefaults": true
121
+ }
122
+ ],
123
+ "@typescript-eslint/consistent-type-definitions": [
124
+ "error",
125
+ "interface"
126
+ ]
127
+ }
128
+ }
129
+ ],
130
+ "prettier": true,
131
+ "rules": {
132
+ "logical-assignment-operators": "off",
133
+ "unicorn/prefer-at": "off",
134
+ "unicorn/prefer-string-replace-all": "off",
135
+ "unicorn/prevent-abbreviations": "off"
136
+ }
137
+ }
138
+ }
node_modules/hast-util-to-jsx-runtime/readme.md ADDED
@@ -0,0 +1,886 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # hast-util-to-jsx-runtime
2
+
3
+ [![Build][badge-build-image]][badge-build-url]
4
+ [![Coverage][badge-coverage-image]][badge-coverage-url]
5
+ [![Downloads][badge-downloads-image]][badge-downloads-url]
6
+ [![Size][badge-size-image]][badge-size-url]
7
+
8
+ hast utility to transform a tree to
9
+ preact, react, solid, svelte, vue, etcetera,
10
+ with an automatic JSX runtime.
11
+
12
+ ## Contents
13
+
14
+ * [What is this?](#what-is-this)
15
+ * [When should I use this?](#when-should-i-use-this)
16
+ * [Install](#install)
17
+ * [Use](#use)
18
+ * [API](#api)
19
+ * [`toJsxRuntime(tree, options)`](#tojsxruntimetree-options)
20
+ * [`Components`](#components)
21
+ * [`CreateEvaluater`](#createevaluater)
22
+ * [`ElementAttributeNameCase`](#elementattributenamecase)
23
+ * [`EvaluateExpression`](#evaluateexpression)
24
+ * [`EvaluateProgram`](#evaluateprogram)
25
+ * [`Evaluater`](#evaluater)
26
+ * [`ExtraProps`](#extraprops)
27
+ * [`Fragment`](#fragment)
28
+ * [`Jsx`](#jsx)
29
+ * [`JsxDev`](#jsxdev)
30
+ * [`Options`](#options)
31
+ * [`Props`](#props)
32
+ * [`Source`](#source)
33
+ * [`Space`](#space)
34
+ * [`StylePropertyNameCase`](#stylepropertynamecase)
35
+ * [Errors](#errors)
36
+ * [Examples](#examples)
37
+ * [Example: Preact](#example-preact)
38
+ * [Example: Solid](#example-solid)
39
+ * [Example: Svelte](#example-svelte)
40
+ * [Example: Vue](#example-vue)
41
+ * [Syntax](#syntax)
42
+ * [Compatibility](#compatibility)
43
+ * [Security](#security)
44
+ * [Related](#related)
45
+ * [Contribute](#contribute)
46
+ * [License](#license)
47
+
48
+ ## What is this?
49
+
50
+ This package is a utility that takes a [hast][github-hast] tree and an
51
+ [automatic JSX runtime][reactjs-jsx-runtime] and turns the tree into anything
52
+ you wish.
53
+
54
+ ## When should I use this?
55
+
56
+ You can use this package when you have a hast syntax tree and want to use it
57
+ with whatever framework.
58
+
59
+ This package uses an automatic JSX runtime,
60
+ which is a sort of lingua franca for frameworks to support JSX.
61
+
62
+ Notably,
63
+ automatic runtimes have support for passing extra information in development,
64
+ and have guaranteed support for fragments.
65
+
66
+ ## Install
67
+
68
+ This package is [ESM only][github-gist-esm].
69
+ In Node.js (version 16+),
70
+ install with [npm][npmjs-install]:
71
+
72
+ ```sh
73
+ npm install hast-util-to-jsx-runtime
74
+ ```
75
+
76
+ In Deno with [`esm.sh`][esmsh]:
77
+
78
+ ```js
79
+ import {toJsxRuntime} from 'https://esm.sh/hast-util-to-jsx-runtime@2'
80
+ ```
81
+
82
+ In browsers with [`esm.sh`][esmsh]:
83
+
84
+ ```html
85
+ <script type="module">
86
+ import {toJsxRuntime} from 'https://esm.sh/hast-util-to-jsx-runtime@2?bundle'
87
+ </script>
88
+ ```
89
+
90
+ ## Use
91
+
92
+ ```js
93
+ import {h} from 'hastscript'
94
+ import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
95
+ import {Fragment, jsxs, jsx} from 'react/jsx-runtime'
96
+ import {renderToStaticMarkup} from 'react-dom/server'
97
+
98
+ const tree = h('h1', 'Hello, world!')
99
+
100
+ const doc = renderToStaticMarkup(toJsxRuntime(tree, {Fragment, jsxs, jsx}))
101
+
102
+ console.log(doc)
103
+ ```
104
+
105
+ Yields:
106
+
107
+ ```html
108
+ <h1>Hello, world!</h1>
109
+ ```
110
+
111
+ > **Note**:
112
+ > to add better type support,
113
+ > register a global JSX namespace:
114
+ >
115
+ > ```ts
116
+ > import type {JSX as Jsx} from 'react/jsx-runtime'
117
+ >
118
+ > declare global {
119
+ > namespace JSX {
120
+ > type ElementClass = Jsx.ElementClass
121
+ > type Element = Jsx.Element
122
+ > type IntrinsicElements = Jsx.IntrinsicElements
123
+ > }
124
+ > }
125
+ > ```
126
+
127
+ ## API
128
+
129
+ This package exports the identifier [`toJsxRuntime`][api-to-jsx-runtime].
130
+ It exports the [TypeScript][] types
131
+ [`Components`][api-components],
132
+ [`CreateEvaluater`][api-create-evaluater],
133
+ [`ElementAttributeNameCase`][api-element-attribute-name-case],
134
+ [`EvaluateExpression`][api-evaluate-expression],
135
+ [`EvaluateProgram`][api-evaluate-program],
136
+ [`Evaluater`][api-evaluater],
137
+ [`ExtraProps`][api-extra-props],
138
+ [`Fragment`][api-fragment],
139
+ [`Jsx`][api-jsx],
140
+ [`JsxDev`][api-jsx-dev],
141
+ [`Options`][api-options],
142
+ [`Props`][api-props],
143
+ [`Source`][api-source],
144
+ [`Space`][api-Space],
145
+ and
146
+ [`StylePropertyNameCase`][api-style-property-name-case].
147
+ There is no default export.
148
+
149
+ ### `toJsxRuntime(tree, options)`
150
+
151
+ Transform a hast tree to
152
+ preact, react, solid, svelte, vue, etcetera,
153
+ with an automatic JSX runtime.
154
+
155
+ ##### Parameters
156
+
157
+ * `tree`
158
+ ([`Node`][github-hast-nodes])
159
+ — tree to transform
160
+ * `options`
161
+ ([`Options`][api-options], required)
162
+ — configuration
163
+
164
+ ##### Returns
165
+
166
+ Result from your configured JSX runtime
167
+ (`JSX.Element` if defined,
168
+ otherwise `unknown` which you can cast yourself).
169
+
170
+ ### `Components`
171
+
172
+ Possible components to use (TypeScript type).
173
+
174
+ Each key is a tag name typed in `JSX.IntrinsicElements`,
175
+ if defined.
176
+ Each value is either a different tag name
177
+ or a component accepting the corresponding props
178
+ (and an optional `node` prop if `passNode` is on).
179
+
180
+ You can access props at `JSX.IntrinsicElements`.
181
+ For example,
182
+ to find props for `a`,
183
+ use `JSX.IntrinsicElements['a']`.
184
+
185
+ ###### Type
186
+
187
+ ```ts
188
+ import type {Element} from 'hast'
189
+
190
+ type ExtraProps = {node?: Element | undefined}
191
+
192
+ type Components = {
193
+ [TagName in keyof JSX.IntrinsicElements]:
194
+ | Component<JSX.IntrinsicElements[TagName] & ExtraProps>
195
+ | keyof JSX.IntrinsicElements
196
+ }
197
+
198
+ type Component<ComponentProps> =
199
+ // Class component:
200
+ | (new (props: ComponentProps) => JSX.ElementClass)
201
+ // Function component:
202
+ | ((props: ComponentProps) => JSX.Element | string | null | undefined)
203
+ ```
204
+
205
+ ### `CreateEvaluater`
206
+
207
+ Create an evaluator that turns ESTree ASTs from embedded MDX into values
208
+ (TypeScript type).
209
+
210
+ ###### Parameters
211
+
212
+ There are no parameters.
213
+
214
+ ###### Returns
215
+
216
+ Evaluater ([`Evaluater`][api-evaluater]).
217
+
218
+ ### `ElementAttributeNameCase`
219
+
220
+ Casing to use for attribute names (TypeScript type).
221
+
222
+ HTML casing is for example
223
+ `class`, `stroke-linecap`, `xml:lang`.
224
+ React casing is for example
225
+ `className`, `strokeLinecap`, `xmlLang`.
226
+
227
+ ###### Type
228
+
229
+ ```ts
230
+ type ElementAttributeNameCase = 'html' | 'react'
231
+ ```
232
+
233
+ ### `EvaluateExpression`
234
+
235
+ Turn an MDX expression into a value (TypeScript type).
236
+
237
+ ###### Parameters
238
+
239
+ * `expression` (`Expression` from `@types/estree`)
240
+ — estree expression
241
+
242
+ ###### Returns
243
+
244
+ Result of expression (`unknown`).
245
+
246
+ ### `EvaluateProgram`
247
+
248
+ Turn an MDX program (export/import statements) into a value (TypeScript type).
249
+
250
+ ###### Parameters
251
+
252
+ * `program` (`Program` from `@types/estree`)
253
+ — estree program
254
+
255
+ ###### Returns
256
+
257
+ Result of program (`unknown`);
258
+ should likely be `undefined` as ESM changes the scope but doesn’t yield
259
+ something.
260
+
261
+ ### `Evaluater`
262
+
263
+ Evaluator that turns ESTree ASTs from embedded MDX into values (TypeScript
264
+ type).
265
+
266
+ ###### Fields
267
+
268
+ * `evaluateExpression` ([`EvaluateExpression`][api-evaluate-expression])
269
+ — evaluate an expression
270
+ * `evaluateProgram` ([`EvaluateProgram`][api-evaluate-program])
271
+ — evaluate a program
272
+
273
+ ### `ExtraProps`
274
+
275
+ Extra fields we pass (TypeScript type).
276
+
277
+ ###### Type
278
+
279
+ ```ts
280
+ type ExtraProps = {node?: Element | undefined}
281
+ ```
282
+
283
+ ### `Fragment`
284
+
285
+ Represent the children,
286
+ typically a symbol (TypeScript type).
287
+
288
+ ###### Type
289
+
290
+ ```ts
291
+ type Fragment = unknown
292
+ ```
293
+
294
+ ### `Jsx`
295
+
296
+ Create a production element (TypeScript type).
297
+
298
+ ###### Parameters
299
+
300
+ * `type` (`unknown`)
301
+ — element type:
302
+ `Fragment` symbol,
303
+ tag name (`string`),
304
+ component
305
+ * `props` ([`Props`][api-props])
306
+ — element props,
307
+ `children`,
308
+ and maybe `node`
309
+ * `key` (`string` or `undefined`)
310
+ — dynamicly generated key to use
311
+
312
+ ###### Returns
313
+
314
+ Element from your framework
315
+ (`JSX.Element` if defined,
316
+ otherwise `unknown` which you can cast yourself).
317
+
318
+ ### `JsxDev`
319
+
320
+ Create a development element (TypeScript type).
321
+
322
+ ###### Parameters
323
+
324
+ * `type` (`unknown`)
325
+ — element type:
326
+ `Fragment` symbol,
327
+ tag name (`string`),
328
+ component
329
+ * `props` ([`Props`][api-props])
330
+ — element props,
331
+ `children`,
332
+ and maybe `node`
333
+ * `key` (`string` or `undefined`)
334
+ — dynamicly generated key to use
335
+ * `isStaticChildren` (`boolean`)
336
+ — whether two or more children are passed (in an array),
337
+ which is whether `jsxs` or `jsx` would be used
338
+ * `source` ([`Source`][api-source])
339
+ — info about source
340
+ * `self` (`undefined`)
341
+ — nothing (this is used by frameworks that have components,
342
+ we don’t)
343
+
344
+ ###### Returns
345
+
346
+ Element from your framework
347
+ (`JSX.Element` if defined,
348
+ otherwise `unknown` which you can cast yourself).
349
+
350
+ ### `Options`
351
+
352
+ Configuration (TypeScript type).
353
+
354
+ ###### Fields
355
+
356
+ * `Fragment` ([`Fragment`][api-fragment], required)
357
+ — fragment
358
+ * `jsxDEV` ([`JsxDev`][api-jsx-dev], required in development)
359
+ — development JSX
360
+ * `jsxs` ([`Jsx`][api-jsx], required in production)
361
+ — static JSX
362
+ * `jsx` ([`Jsx`][api-jsx], required in production)
363
+ — dynamic JSX
364
+ * `components` ([`Partial<Components>`][api-components], optional)
365
+ — components to use
366
+ * `createEvaluater` ([`CreateEvaluater`][api-create-evaluater], optional)
367
+ — create an evaluator that turns ESTree ASTs into values
368
+ * `development` (`boolean`, default: `false`)
369
+ — whether to use `jsxDEV` when on or `jsx` and `jsxs` when off
370
+ * `elementAttributeNameCase`
371
+ ([`ElementAttributeNameCase`][api-element-attribute-name-case],
372
+ default: `'react'`)
373
+ — specify casing to use for attribute names
374
+ * `filePath` (`string`, optional)
375
+ — file path to the original source file,
376
+ passed in source info to `jsxDEV` when using the automatic runtime with
377
+ `development: true`
378
+ * `passNode` (`boolean`, default: `false`)
379
+ — pass the hast element node to components
380
+ * `space` ([`Space`][api-space], default: `'html'`)
381
+ — whether `tree` is in the `'html'` or `'svg'` space, when an `<svg>`
382
+ element is found in the HTML space,
383
+ this package already automatically switches to and from the SVG space when
384
+ entering and exiting it
385
+ * `stylePropertyNameCase`
386
+ ([`StylePropertyNameCase`][api-style-property-name-case],
387
+ default: `'dom'`)
388
+ — specify casing to use for property names in `style` objects
389
+ * `tableCellAlignToStyle`
390
+ (`boolean`, default: `true`)
391
+ — turn obsolete `align` props on `td` and `th` into CSS `style` props
392
+
393
+ ### `Props`
394
+
395
+ Properties and children (TypeScript type).
396
+
397
+ ###### Type
398
+
399
+ ```ts
400
+ import type {Element} from 'hast'
401
+
402
+ type Props = {
403
+ [prop: string]:
404
+ | Array<JSX.Element | string | null | undefined> // For `children`.
405
+ | Record<string, string> // For `style`.
406
+ | Element // For `node`.
407
+ | boolean
408
+ | number
409
+ | string
410
+ | undefined
411
+ children: Array<JSX.Element | string | null | undefined> | undefined
412
+ node?: Element | undefined
413
+ }
414
+ ```
415
+
416
+ ### `Source`
417
+
418
+ Info about source (TypeScript type).
419
+
420
+ ###### Fields
421
+
422
+ * `columnNumber` (`number` or `undefined`)
423
+ — column where thing starts (0-indexed)
424
+ * `fileName` (`string` or `undefined`)
425
+ — name of source file
426
+ * `lineNumber` (`number` or `undefined`)
427
+ — line where thing starts (1-indexed)
428
+
429
+ ### `Space`
430
+
431
+ Namespace (TypeScript type).
432
+
433
+ > 👉 **Note**:
434
+ > hast is not XML;
435
+ > it supports SVG as embedded in HTML;
436
+ > it does not support the features available in XML;
437
+ > passing SVG might break but fragments of modern SVG should be fine;
438
+ > use `xast` if you need to support SVG as XML.
439
+
440
+ ###### Type
441
+
442
+ ```ts
443
+ type Space = 'html' | 'svg'
444
+ ```
445
+
446
+ ### `StylePropertyNameCase`
447
+
448
+ Casing to use for property names in `style` objects (TypeScript type).
449
+
450
+ CSS casing is for example `background-color` and `-webkit-line-clamp`.
451
+ DOM casing is for example `backgroundColor` and `WebkitLineClamp`.
452
+
453
+ ###### Type
454
+
455
+ ```ts
456
+ type StylePropertyNameCase = 'css' | 'dom'
457
+ ```
458
+
459
+ ## Errors
460
+
461
+ The following errors are thrown:
462
+
463
+ ###### ``Expected `Fragment` in options``
464
+
465
+ This error is thrown when either `options` is not passed at all or
466
+ when `options.Fragment` is `undefined`.
467
+
468
+ The automatic JSX runtime needs a symbol for a fragment to work.
469
+
470
+ To solve the error,
471
+ make sure you are passing the correct fragment symbol from your framework.
472
+
473
+ ###### `` Expected `jsxDEV` in options when `development: true` ``
474
+
475
+ This error is thrown when `options.development` is turned on (`true`),
476
+ but when `options.jsxDEV` is not a function.
477
+
478
+ The automatic JSX runtime,
479
+ in development,
480
+ needs this function.
481
+
482
+ To solve the error,
483
+ make sure you are importing the correct runtime functions
484
+ (for example, `'react/jsx-dev-runtime'`),
485
+ and pass `jsxDEV`.
486
+
487
+ ###### ``Expected `jsx` in production options``
488
+
489
+ ###### ``Expected `jsxs` in production options``
490
+
491
+ These errors are thrown when `options.development` is *not* turned on
492
+ (`false` or not defined),
493
+ and when `options.jsx` or `options.jsxs` are not functions.
494
+
495
+ The automatic JSX runtime,
496
+ in production,
497
+ needs these functions.
498
+
499
+ To solve the error,
500
+ make sure you are importing the correct runtime functions
501
+ (for example, `'react/jsx-runtime'`),
502
+ and pass `jsx` and `jsxs`.
503
+
504
+ ###### `` Cannot handle MDX estrees without `createEvaluater` ``
505
+
506
+ This error is thrown when MDX nodes are passed that represent JavaScript
507
+ programs or expressions.
508
+
509
+ Supporting JavaScript can be unsafe and requires a different project.
510
+ To support JavaScript,
511
+ pass a `createEvaluater` function in `options`.
512
+
513
+ ###### ``Cannot parse `style` attribute``
514
+
515
+ This error is thrown when a `style` attribute is found on an element,
516
+ which cannot be parsed as CSS.
517
+
518
+ Most frameworks don’t accept `style` as a string,
519
+ so we need to parse it as CSS,
520
+ and pass it as an object.
521
+ But when broken CSS is used,
522
+ such as `style="color:red; /*"`,
523
+ we crash.
524
+
525
+ To solve the error,
526
+ make sure authors write valid CSS.
527
+ Alternatively,
528
+ pass `options.ignoreInvalidStyle: true` to swallow these errors.
529
+
530
+ ## Examples
531
+
532
+ ### Example: Preact
533
+
534
+ > 👉 **Note**:
535
+ > you must set `elementAttributeNameCase: 'html'` for preact.
536
+
537
+ In Node.js,
538
+ do:
539
+
540
+ ```js
541
+ import {h} from 'hastscript'
542
+ import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
543
+ import {Fragment, jsx, jsxs} from 'preact/jsx-runtime'
544
+ import {render} from 'preact-render-to-string'
545
+
546
+ const result = render(
547
+ toJsxRuntime(h('h1', 'hi!'), {
548
+ Fragment,
549
+ jsx,
550
+ jsxs,
551
+ elementAttributeNameCase: 'html'
552
+ })
553
+ )
554
+
555
+ console.log(result)
556
+ ```
557
+
558
+ Yields:
559
+
560
+ ```html
561
+ <h1>hi!</h1>
562
+ ```
563
+
564
+ In a browser,
565
+ do:
566
+
567
+ ```js
568
+ import {h} from 'https://esm.sh/hastscript@9'
569
+ import {toJsxRuntime} from 'https://esm.sh/hast-util-to-jsx-runtime@2'
570
+ import {Fragment, jsx, jsxs} from 'https://esm.sh/preact@10/jsx-runtime'
571
+ import {render} from 'https://esm.sh/preact@10'
572
+
573
+ render(
574
+ toJsxRuntime(h('h1', 'hi!'), {
575
+ Fragment,
576
+ jsx,
577
+ jsxs,
578
+ elementAttributeNameCase: 'html'
579
+ }),
580
+ document.getElementById('root')
581
+ )
582
+ ```
583
+
584
+ To add better type support,
585
+ register a global JSX namespace:
586
+
587
+ ```ts
588
+ import type {JSX as Jsx} from 'preact/jsx-runtime'
589
+
590
+ declare global {
591
+ namespace JSX {
592
+ type ElementClass = Jsx.ElementClass
593
+ type Element = Jsx.Element
594
+ type IntrinsicElements = Jsx.IntrinsicElements
595
+ }
596
+ }
597
+ ```
598
+
599
+ ### Example: Solid
600
+
601
+ > 👉 **Note**:
602
+ > you must set `elementAttributeNameCase: 'html'` and
603
+ > `stylePropertyNameCase: 'css'` for Solid.
604
+
605
+ In Node.js,
606
+ do:
607
+
608
+ ```js
609
+ import {h} from 'hastscript'
610
+ import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
611
+ import {Fragment, jsx, jsxs} from 'solid-jsx/jsx-runtime'
612
+
613
+ console.log(
614
+ toJsxRuntime(h('h1', 'hi!'), {
615
+ Fragment,
616
+ jsx,
617
+ jsxs,
618
+ elementAttributeNameCase: 'html',
619
+ stylePropertyNameCase: 'css'
620
+ }).t
621
+ )
622
+ ```
623
+
624
+ Yields:
625
+
626
+ ```html
627
+ <h1 >hi!</h1>
628
+ ```
629
+
630
+ In a browser,
631
+ do:
632
+
633
+ ```js
634
+ import {h} from 'https://esm.sh/hastscript@9'
635
+ import {toJsxRuntime} from 'https://esm.sh/hast-util-to-jsx-runtime@2'
636
+ import {Fragment, jsx, jsxs} from 'https://esm.sh/solid-js@1/h/jsx-runtime'
637
+ import {render} from 'https://esm.sh/solid-js@1/web'
638
+
639
+ render(Component, document.getElementById('root'))
640
+
641
+ function Component() {
642
+ return toJsxRuntime(h('h1', 'hi!'), {
643
+ Fragment,
644
+ jsx,
645
+ jsxs,
646
+ elementAttributeNameCase: 'html',
647
+ stylePropertyNameCase: 'css'
648
+ })
649
+ }
650
+ ```
651
+
652
+ To add better type support,
653
+ register a global JSX namespace:
654
+
655
+ ```ts
656
+ import type {JSX as Jsx} from 'solid-js/jsx-runtime'
657
+
658
+ declare global {
659
+ namespace JSX {
660
+ type ElementClass = Jsx.ElementClass
661
+ type Element = Jsx.Element
662
+ type IntrinsicElements = Jsx.IntrinsicElements
663
+ }
664
+ }
665
+ ```
666
+
667
+ ### Example: Svelte
668
+
669
+ <!-- To do: improve svelte when it fixes a bunch of bugs. -->
670
+
671
+ I have no clue how to render a Svelte component in Node,
672
+ but you can get that component with:
673
+
674
+ ```js
675
+ import {h} from 'hastscript'
676
+ import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
677
+ import {Fragment, jsx, jsxs} from 'svelte-jsx'
678
+
679
+ const svelteComponent = toJsxRuntime(h('h1', 'hi!'), {Fragment, jsx, jsxs})
680
+
681
+ console.log(svelteComponent)
682
+ ```
683
+
684
+ Yields:
685
+
686
+ ```text
687
+ [class Component extends SvelteComponent]
688
+ ```
689
+
690
+ Types for Svelte are broken.
691
+ Raise it with Svelte.
692
+
693
+ ### Example: Vue
694
+
695
+ > 👉 **Note**:
696
+ > you must set `elementAttributeNameCase: 'html'` for Vue.
697
+
698
+ In Node.js,
699
+ do:
700
+
701
+ ```js
702
+ import serverRenderer from '@vue/server-renderer'
703
+ import {h} from 'hastscript'
704
+ import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
705
+ import {Fragment, jsx, jsxs} from 'vue/jsx-runtime' // Available since `vue@3.3`.
706
+
707
+ console.log(
708
+ await serverRenderer.renderToString(
709
+ toJsxRuntime(h('h1', 'hi!'), {
710
+ Fragment,
711
+ jsx,
712
+ jsxs,
713
+ elementAttributeNameCase: 'html'
714
+ })
715
+ )
716
+ )
717
+ ```
718
+
719
+ Yields:
720
+
721
+ ```html
722
+ <h1>hi!</h1>
723
+ ```
724
+
725
+ In a browser,
726
+ do:
727
+
728
+ ```js
729
+ import {h} from 'https://esm.sh/hastscript@9'
730
+ import {toJsxRuntime} from 'https://esm.sh/hast-util-to-jsx-runtime@2'
731
+ import {createApp} from 'https://esm.sh/vue@3'
732
+ import {Fragment, jsx, jsxs} from 'https://esm.sh/vue@3/jsx-runtime'
733
+
734
+ createApp(Component).mount('#root')
735
+
736
+ function Component() {
737
+ return toJsxRuntime(h('h1', 'hi!'), {
738
+ Fragment,
739
+ jsx,
740
+ jsxs,
741
+ elementAttributeNameCase: 'html'
742
+ })
743
+ }
744
+ ```
745
+
746
+ To add better type support,
747
+ register a global JSX namespace:
748
+
749
+ ```ts
750
+ import type {JSX as Jsx} from 'vue/jsx-runtime'
751
+
752
+ declare global {
753
+ namespace JSX {
754
+ type ElementClass = Jsx.ElementClass
755
+ type Element = Jsx.Element
756
+ type IntrinsicElements = Jsx.IntrinsicElements
757
+ }
758
+ }
759
+ ```
760
+
761
+ ## Syntax
762
+
763
+ HTML is parsed according to WHATWG HTML (the living standard),
764
+ which is also followed by browsers such as Chrome,
765
+ Firefox,
766
+ and Safari.
767
+
768
+ ## Compatibility
769
+
770
+ Projects maintained by the unified collective are compatible with maintained
771
+ versions of Node.js.
772
+
773
+ When we cut a new major release,
774
+ we drop support for unmaintained versions of Node.
775
+ This means we try to keep the current release line,
776
+ `hast-util-to-jsx-runtime@2`,
777
+ compatible with Node.js 16.
778
+
779
+ ## Security
780
+
781
+ Be careful with user input in your hast tree.
782
+ Use [`hast-util-santize`][github-hast-util-sanitize] to make hast trees safe.
783
+
784
+ ## Related
785
+
786
+ * [`hastscript`](https://github.com/syntax-tree/hastscript)
787
+ — build hast trees
788
+ * [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)
789
+ — serialize hast as HTML
790
+ * [`hast-util-sanitize`][github-hast-util-sanitize]
791
+ — sanitize hast
792
+
793
+ ## Contribute
794
+
795
+ See [`contributing.md`][health-contributing]
796
+ in
797
+ [`syntax-tree/.github`][health]
798
+ for ways to get started.
799
+ See [`support.md`][health-support] for ways to get help.
800
+
801
+ This project has a [code of conduct][health-coc].
802
+ By interacting with this repository,
803
+ organization,
804
+ or community you agree to abide by its terms.
805
+
806
+ ## License
807
+
808
+ [MIT][file-license] © [Titus Wormer][wooorm]
809
+
810
+ <!-- Definitions -->
811
+
812
+ [api-components]: #components
813
+
814
+ [api-create-evaluater]: #createevaluater
815
+
816
+ [api-element-attribute-name-case]: #elementattributenamecase
817
+
818
+ [api-evaluate-expression]: #evaluateexpression
819
+
820
+ [api-evaluate-program]: #evaluateprogram
821
+
822
+ [api-evaluater]: #evaluater
823
+
824
+ [api-extra-props]: #extraprops
825
+
826
+ [api-fragment]: #fragment
827
+
828
+ [api-jsx]: #jsx
829
+
830
+ [api-jsx-dev]: #jsxdev
831
+
832
+ [api-options]: #options
833
+
834
+ [api-props]: #props
835
+
836
+ [api-source]: #source
837
+
838
+ [api-space]: #space
839
+
840
+ [api-style-property-name-case]: #stylepropertynamecase
841
+
842
+ [api-to-jsx-runtime]: #tojsxruntimetree-options
843
+
844
+ [badge-build-image]: https://github.com/syntax-tree/hast-util-to-jsx-runtime/workflows/main/badge.svg
845
+
846
+ [badge-build-url]: https://github.com/syntax-tree/hast-util-to-jsx-runtime/actions
847
+
848
+ [badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-jsx-runtime.svg
849
+
850
+ [badge-coverage-url]: https://codecov.io/github/syntax-tree/hast-util-to-jsx-runtime
851
+
852
+ [badge-downloads-image]: https://img.shields.io/npm/dm/hast-util-to-jsx-runtime.svg
853
+
854
+ [badge-downloads-url]: https://www.npmjs.com/package/hast-util-to-jsx-runtime
855
+
856
+ [badge-size-image]: https://img.shields.io/bundlejs/size/hast-util-to-jsx-runtime
857
+
858
+ [badge-size-url]: https://bundlejs.com/?q=hast-util-to-jsx-runtime
859
+
860
+ [esmsh]: https://esm.sh
861
+
862
+ [file-license]: license
863
+
864
+ [github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
865
+
866
+ [github-hast]: https://github.com/syntax-tree/hast
867
+
868
+ [github-hast-nodes]: https://github.com/syntax-tree/hast#nodes
869
+
870
+ [github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
871
+
872
+ [health]: https://github.com/syntax-tree/.github
873
+
874
+ [health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
875
+
876
+ [health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
877
+
878
+ [health-support]: https://github.com/syntax-tree/.github/blob/main/support.md
879
+
880
+ [npmjs-install]: https://docs.npmjs.com/cli/install
881
+
882
+ [reactjs-jsx-runtime]: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
883
+
884
+ [typescript]: https://www.typescriptlang.org
885
+
886
+ [wooorm]: https://wooorm.com
node_modules/hast-util-whitespace/index.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export { whitespace } from "./lib/index.js";
node_modules/hast-util-whitespace/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ export {whitespace} from './lib/index.js'
node_modules/hast-util-whitespace/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Check if the given value is *inter-element whitespace*.
3
+ *
4
+ * @param {Nodes | string} thing
5
+ * Thing to check (`Node` or `string`).
6
+ * @returns {boolean}
7
+ * Whether the `value` is inter-element whitespace (`boolean`): consisting of
8
+ * zero or more of space, tab (`\t`), line feed (`\n`), carriage return
9
+ * (`\r`), or form feed (`\f`); if a node is passed it must be a `Text` node,
10
+ * whose `value` field is checked.
11
+ */
12
+ export function whitespace(thing: Nodes | string): boolean;
13
+ export type Nodes = import('hast').Nodes;
node_modules/hast-util-whitespace/lib/index.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @typedef {import('hast').Nodes} Nodes
3
+ */
4
+
5
+ // HTML whitespace expression.
6
+ // See <https://infra.spec.whatwg.org/#ascii-whitespace>.
7
+ const re = /[ \t\n\f\r]/g
8
+
9
+ /**
10
+ * Check if the given value is *inter-element whitespace*.
11
+ *
12
+ * @param {Nodes | string} thing
13
+ * Thing to check (`Node` or `string`).
14
+ * @returns {boolean}
15
+ * Whether the `value` is inter-element whitespace (`boolean`): consisting of
16
+ * zero or more of space, tab (`\t`), line feed (`\n`), carriage return
17
+ * (`\r`), or form feed (`\f`); if a node is passed it must be a `Text` node,
18
+ * whose `value` field is checked.
19
+ */
20
+ export function whitespace(thing) {
21
+ return typeof thing === 'object'
22
+ ? thing.type === 'text'
23
+ ? empty(thing.value)
24
+ : false
25
+ : empty(thing)
26
+ }
27
+
28
+ /**
29
+ * @param {string} value
30
+ * @returns {boolean}
31
+ */
32
+ function empty(value) {
33
+ return value.replace(re, '') === ''
34
+ }
node_modules/hast-util-whitespace/license ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/hast-util-whitespace/package.json ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "hast-util-whitespace",
3
+ "version": "3.0.0",
4
+ "description": "hast utility to check if a node is inter-element whitespace",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "unist",
8
+ "hast",
9
+ "hast-util",
10
+ "util",
11
+ "utility",
12
+ "html",
13
+ "inter",
14
+ "element",
15
+ "inter-element",
16
+ "white-space",
17
+ "whitespace"
18
+ ],
19
+ "repository": "syntax-tree/hast-util-whitespace",
20
+ "bugs": "https://github.com/syntax-tree/hast-util-whitespace/issues",
21
+ "funding": {
22
+ "type": "opencollective",
23
+ "url": "https://opencollective.com/unified"
24
+ },
25
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
26
+ "contributors": [
27
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
28
+ ],
29
+ "sideEffects": false,
30
+ "type": "module",
31
+ "exports": "./index.js",
32
+ "files": [
33
+ "lib/",
34
+ "index.d.ts",
35
+ "index.js"
36
+ ],
37
+ "dependencies": {
38
+ "@types/hast": "^3.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^20.0.0",
42
+ "c8": "^8.0.0",
43
+ "prettier": "^3.0.0",
44
+ "remark-cli": "^11.0.0",
45
+ "remark-preset-wooorm": "^9.0.0",
46
+ "type-coverage": "^2.0.0",
47
+ "typescript": "^5.0.0",
48
+ "xo": "^0.55.0"
49
+ },
50
+ "scripts": {
51
+ "prepack": "npm run build && npm run format",
52
+ "build": "tsc --build --clean && tsc --build && type-coverage",
53
+ "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
54
+ "test-api": "node --conditions development test.js",
55
+ "test-coverage": "c8 --100 --reporter lcov npm run test-api",
56
+ "test": "npm run build && npm run format && npm run test-coverage"
57
+ },
58
+ "prettier": {
59
+ "bracketSpacing": false,
60
+ "semi": false,
61
+ "singleQuote": true,
62
+ "tabWidth": 2,
63
+ "trailingComma": "none",
64
+ "useTabs": false
65
+ },
66
+ "remarkConfig": {
67
+ "plugins": [
68
+ "remark-preset-wooorm"
69
+ ]
70
+ },
71
+ "typeCoverage": {
72
+ "atLeast": 100,
73
+ "detail": true,
74
+ "ignoreCatch": true,
75
+ "strict": true
76
+ },
77
+ "xo": {
78
+ "prettier": true,
79
+ "rules": {
80
+ "unicorn/prefer-string-replace-all": "off"
81
+ }
82
+ }
83
+ }
node_modules/hast-util-whitespace/readme.md ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # hast-util-whitespace
2
+
3
+ [![Build][build-badge]][build]
4
+ [![Coverage][coverage-badge]][coverage]
5
+ [![Downloads][downloads-badge]][downloads]
6
+ [![Size][size-badge]][size]
7
+ [![Sponsors][sponsors-badge]][collective]
8
+ [![Backers][backers-badge]][collective]
9
+ [![Chat][chat-badge]][chat]
10
+
11
+ [hast][] utility to check if a node is [*inter-element whitespace*][spec].
12
+
13
+ ## Contents
14
+
15
+ * [What is this?](#what-is-this)
16
+ * [When should I use this?](#when-should-i-use-this)
17
+ * [Install](#install)
18
+ * [Use](#use)
19
+ * [API](#api)
20
+ * [`whitespace(thing)`](#whitespacething)
21
+ * [Types](#types)
22
+ * [Compatibility](#compatibility)
23
+ * [Security](#security)
24
+ * [Related](#related)
25
+ * [Contribute](#contribute)
26
+ * [License](#license)
27
+
28
+ ## What is this?
29
+
30
+ This package is a small utility that checks if a node is whitespace according to
31
+ HTML.
32
+
33
+ ## When should I use this?
34
+
35
+ This utility is super niche, if you’re here you probably know what you’re
36
+ looking for!
37
+
38
+ ## Install
39
+
40
+ This package is [ESM only][esm].
41
+ In Node.js (version 16+), install with [npm][]:
42
+
43
+ ```sh
44
+ npm install hast-util-whitespace
45
+ ```
46
+
47
+ In Deno with [`esm.sh`][esmsh]:
48
+
49
+ ```js
50
+ import {whitespace} from 'https://esm.sh/hast-util-whitespace@3'
51
+ ```
52
+
53
+ In browsers with [`esm.sh`][esmsh]:
54
+
55
+ ```html
56
+ <script type="module">
57
+ import {whitespace} from 'https://esm.sh/hast-util-whitespace@3?bundle'
58
+ </script>
59
+ ```
60
+
61
+ ## Use
62
+
63
+ ```js
64
+ import {whitespace} from 'hast-util-whitespace'
65
+
66
+ whitespace({
67
+ type: 'element',
68
+ tagName: 'div',
69
+ properties: {},
70
+ children: []
71
+ }) // => false
72
+
73
+ whitespace({
74
+ type: 'text',
75
+ value: '\t \n'
76
+ }) // => true
77
+
78
+ whitespace({
79
+ type: 'text',
80
+ value: ' text\f'
81
+ }) // => false
82
+ ```
83
+
84
+ ## API
85
+
86
+ This package exports the identifier [`whitespace`][api-whitespace].
87
+ There is no default export.
88
+
89
+ ### `whitespace(thing)`
90
+
91
+ Check if the given value is [*inter-element whitespace*][spec].
92
+
93
+ ###### Parameters
94
+
95
+ * `thing` ([`Node`][node] or `string`, optional)
96
+ — thing to check
97
+
98
+ ###### Returns
99
+
100
+ Whether the `value` is inter-element whitespace (`boolean`): consisting of zero
101
+ or more of space, tab (`\t`), line feed (`\n`), carriage return (`\r`), or form
102
+ feed (`\f`).
103
+ If a node is passed it must be a [`Text`][text] node, whose `value` field is
104
+ checked.
105
+
106
+ ## Types
107
+
108
+ This package is fully typed with [TypeScript][].
109
+ It exports no additional types.
110
+
111
+ ## Compatibility
112
+
113
+ Projects maintained by the unified collective are compatible with maintained
114
+ versions of Node.js.
115
+
116
+ When we cut a new major release, we drop support for unmaintained versions of
117
+ Node.
118
+ This means we try to keep the current release line, `hast-util-whitespace@^3`,
119
+ compatible with Node.js 16.
120
+
121
+ ## Security
122
+
123
+ `hast-util-whitespace` does not change the syntax tree so there are no openings
124
+ for [cross-site scripting (XSS)][xss] attacks.
125
+
126
+ ## Related
127
+
128
+ * [`hast-util-is-element`](https://github.com/syntax-tree/hast-util-is-element)
129
+ — check if a node is a (certain) element
130
+ * [`hast-util-has-property`](https://github.com/syntax-tree/hast-util-has-property)
131
+ — check if a node has a property
132
+ * [`hast-util-transparent`](https://github.com/syntax-tree/hast-util-transparent)
133
+ — check if a node is a transparent element
134
+ * [`hast-util-heading`](https://github.com/syntax-tree/hast-util-heading)
135
+ — check if a node is a heading element
136
+ * [`hast-util-labelable`](https://github.com/syntax-tree/hast-util-labelable)
137
+ — check whether a node is labelable
138
+ * [`hast-util-phrasing`](https://github.com/syntax-tree/hast-util-phrasing)
139
+ — check if a node is phrasing content
140
+ * [`hast-util-embedded`](https://github.com/syntax-tree/hast-util-embedded)
141
+ — check if a node is an embedded element
142
+ * [`hast-util-sectioning`](https://github.com/syntax-tree/hast-util-sectioning)
143
+ — check if a node is a sectioning element
144
+ * [`hast-util-interactive`](https://github.com/syntax-tree/hast-util-interactive)
145
+ — check if a node is interactive
146
+ * [`hast-util-script-supporting`](https://github.com/syntax-tree/hast-util-script-supporting)
147
+ — check if a node is a script-supporting element
148
+ * [`hast-util-is-body-ok-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-body-ok-link)
149
+ — check if a node is “Body OK” link element
150
+ * [`hast-util-is-conditional-comment`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-conditional-comment)
151
+ — check if a node is a conditional comment
152
+ * [`hast-util-is-css-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-link)
153
+ — check if a node is a CSS link element
154
+ * [`hast-util-is-css-style`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-style)
155
+ — check if a node is a CSS style element
156
+ * [`hast-util-is-javascript`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-javascript)
157
+ — check if a node is a JavaScript script element
158
+
159
+ ## Contribute
160
+
161
+ See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
162
+ ways to get started.
163
+ See [`support.md`][support] for ways to get help.
164
+
165
+ This project has a [code of conduct][coc].
166
+ By interacting with this repository, organization, or community you agree to
167
+ abide by its terms.
168
+
169
+ ## License
170
+
171
+ [MIT][license] © [Titus Wormer][author]
172
+
173
+ <!-- Definition -->
174
+
175
+ [build-badge]: https://github.com/syntax-tree/hast-util-whitespace/workflows/main/badge.svg
176
+
177
+ [build]: https://github.com/syntax-tree/hast-util-whitespace/actions
178
+
179
+ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-whitespace.svg
180
+
181
+ [coverage]: https://codecov.io/github/syntax-tree/hast-util-whitespace
182
+
183
+ [downloads-badge]: https://img.shields.io/npm/dm/hast-util-whitespace.svg
184
+
185
+ [downloads]: https://www.npmjs.com/package/hast-util-whitespace
186
+
187
+ [size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-whitespace
188
+
189
+ [size]: https://bundlejs.com/?q=hast-util-whitespace
190
+
191
+ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
192
+
193
+ [backers-badge]: https://opencollective.com/unified/backers/badge.svg
194
+
195
+ [collective]: https://opencollective.com/unified
196
+
197
+ [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
198
+
199
+ [chat]: https://github.com/syntax-tree/unist/discussions
200
+
201
+ [npm]: https://docs.npmjs.com/cli/install
202
+
203
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
204
+
205
+ [esmsh]: https://esm.sh
206
+
207
+ [typescript]: https://www.typescriptlang.org
208
+
209
+ [license]: license
210
+
211
+ [author]: https://wooorm.com
212
+
213
+ [health]: https://github.com/syntax-tree/.github
214
+
215
+ [contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
216
+
217
+ [support]: https://github.com/syntax-tree/.github/blob/main/support.md
218
+
219
+ [coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
220
+
221
+ [hast]: https://github.com/syntax-tree/hast
222
+
223
+ [spec]: https://html.spec.whatwg.org/multipage/dom.html#inter-element-whitespace
224
+
225
+ [node]: https://github.com/syntax-tree/hast#nodes
226
+
227
+ [text]: https://github.com/syntax-tree/hast#text
228
+
229
+ [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
230
+
231
+ [api-whitespace]: #whitespacething
node_modules/headers-polyfill/LICENSE ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2020–present Artem Zakharchenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/headers-polyfill/README.md ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [![Published version](https://img.shields.io/npm/v/headers-polyfill.svg)](https://www.npmjs.com/package/headers-polyfill)
2
+
3
+ # `headers-polyfill`
4
+
5
+ A `Headers` class polyfill and transformation library.
6
+
7
+ ## Motivation
8
+
9
+ Various request issuing libraries utilize a different format of headers. This library chooses the [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) instance as the middle-ground between server and client, and provides functions to convert that instance to primitives and vice-versa.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install headers-polyfill
15
+ ```
16
+
17
+ ## Polyfill
18
+
19
+ This package exports the `Headers` class that polyfills the native [`window.Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) implementation. This allows you to construct and manage headers using the same API in non-browser environments.
20
+
21
+ ```js
22
+ import { Headers } from 'headers-polyfill'
23
+
24
+ const headers = new Headers({
25
+ Accept: '*/*',
26
+ 'Content-Type': 'application/json',
27
+ })
28
+
29
+ headers.get('accept') // "*/*"
30
+ ```
31
+
32
+ ## Methods
33
+
34
+ The `Headers` polyfill instance supports the same methods as the standard `Headers` instance:
35
+
36
+ - [`.has()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/has)
37
+ - [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/get)
38
+ - [`.set()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/set)
39
+ - [`.append()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/append)
40
+ - [`.delete()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete)
41
+ - [`.forEach()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach)
42
+ - [`.getSetCookie()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie)
43
+
44
+ As well as the iterator methods:
45
+
46
+ - [`.keys()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys)
47
+ - [`.values()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/values)
48
+ - [`.entries()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries)
49
+
50
+ ## Transformations
51
+
52
+ ### `getRawHeaders()`
53
+
54
+ Returns an object consisting of the header name/value pairs but preserving raw header names.
55
+
56
+ ```js
57
+ const headers = new Headers({
58
+ Accept: '*/*',
59
+ 'Content-Type': 'application/json',
60
+ })
61
+
62
+ headers.raw()
63
+ // { "Accept": "*/*", "Content-Type": "application/json" }
64
+ ```
65
+
66
+ ### Headers ⭢ N
67
+
68
+ - `headersToString: (h: Headers): string`
69
+
70
+ ```js
71
+ import { headersToString } from 'headers-polyfill'
72
+
73
+ headersToString(
74
+ new Headers({
75
+ connection: 'keep-alive',
76
+ 'content-type': ['text/plain', 'image/png'],
77
+ })
78
+ )
79
+ // connetion: keep-alive
80
+ // content-type: text/plain, image/png
81
+ ```
82
+
83
+ - `headersToList: (h: Headers): Array<[string, string | string[]]>`
84
+
85
+ ```js
86
+ import { headersToList } from 'headers-polyfill'
87
+
88
+ headersToList(
89
+ new Headers({
90
+ connection: 'keep-alive',
91
+ 'content-type': ['text/plain', 'image/png'],
92
+ })
93
+ )
94
+ // [['connection', 'keep-alive'], ['content-type', ['text/plain', 'image/png']]]
95
+ ```
96
+
97
+ - `headersToObject: (h: Headers): Record<string, string | string[]>`
98
+
99
+ ```js
100
+ import { headersToObject } from 'headers-polyfill'
101
+
102
+ headersToObject(
103
+ new Headers({
104
+ connection: 'keep-alive',
105
+ 'content-type': ['text/plain', 'image/png'],
106
+ })
107
+ )
108
+ // { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
109
+ ```
110
+
111
+ ### N ⭢ Headers
112
+
113
+ - `stringToHeaders: (s: string): Headers`
114
+
115
+ ```js
116
+ import { stringToHeaders } from 'headers-polyfill'
117
+
118
+
119
+ const stringToHeaders(`
120
+ connection: keep-alive
121
+ content-type: text/plain, image/png
122
+ `)
123
+ // Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
124
+ ```
125
+
126
+ - `listToHeaders: (l: Array<[string, string | string[]]>): Headers`
127
+
128
+ ```js
129
+ import { listToHeaders } from 'headers-polyfill'
130
+
131
+ listToHeaders([
132
+ ['connection', 'keep-alive'],
133
+ ['content-type', ['text/plain', 'image/png']],
134
+ ])
135
+ // Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
136
+ ```
137
+
138
+ - `objectToHeaders: (o: Record<string, string | string[] | undefined>): Headers`
139
+
140
+ ```js
141
+ import { objectToHeaders } from 'headers-polyfill'
142
+
143
+ objectToHeaders({
144
+ connection: 'keep-alive',
145
+ 'content-type': ['text/plain', 'image/png'],
146
+ })
147
+ // Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Utilities
153
+
154
+ - `reduceHeadersObject: <R>(o: Record<string, string | string[]>, reducer: (acc: R, name: string, value: string | string[]) => R) => R`
155
+
156
+ ```js
157
+ import { reduceHeadersObject } from 'headers-polyfill'
158
+
159
+ reduceHeadersObject <
160
+ HeadersObject >
161
+ ({
162
+ Accept: '*/*',
163
+ 'Content-Type': ['application/json', 'text/plain'],
164
+ },
165
+ (headers, name, value) => {
166
+ headers[name.toLowerCase()] = value
167
+ return headers
168
+ },
169
+ {})
170
+ // { 'accept': '*/*', 'content-type': ['application/json', 'text/plain'] }
171
+ ```
172
+
173
+ - `appendHeader: (o: Record<string, string | string[]>, n: string, v: string | string[]): Record<string, string | string[]>`
174
+
175
+ ```js
176
+ import { appendHeader } from 'headers-polyfill'
177
+
178
+ appendHeader(
179
+ { 'content-type': 'application/json' },
180
+ 'content-type',
181
+ 'text/plain'
182
+ )
183
+ // { 'content-type': ['application/json', 'text/plain']}
184
+ ```
185
+
186
+ - `flattenHeadersList: (l: Array<[string, string | string[]]>): Array<string, string>`
187
+
188
+ ```js
189
+ import { flattenHeadersList } from 'headers-polyfill'
190
+
191
+ flattenHeadersList([['content-type', ['text/plain', 'image/png']]])
192
+ // ['content-type', 'text/plain, image/png']
193
+ ```
194
+
195
+ - `flattenHeadersObject: (o: Record<string, string | string[]>): Record<string, string>`
196
+
197
+ ```js
198
+ import { flattenHeadersObject } from 'headers-polyfill'
199
+
200
+ flattenHeadersObject({
201
+ 'content-type': ['text/plain', 'image/png'],
202
+ })
203
+ // { 'content-type': 'text/plain, image/png' }
204
+ ```
node_modules/headers-polyfill/lib/index.cjs ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let set_cookie_parser = require("set-cookie-parser");
3
+ //#region src/utils/normalizeHeaderName.ts
4
+ const HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
5
+ function normalizeHeaderName(name) {
6
+ if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === "") throw new TypeError("Invalid character in header field name");
7
+ return name.trim().toLowerCase();
8
+ }
9
+ //#endregion
10
+ //#region src/utils/normalizeHeaderValue.ts
11
+ const charCodesToRemove = [
12
+ String.fromCharCode(10),
13
+ String.fromCharCode(13),
14
+ String.fromCharCode(9),
15
+ String.fromCharCode(32)
16
+ ];
17
+ const HEADER_VALUE_REMOVE_REGEXP = new RegExp(`(^[${charCodesToRemove.join("")}]|$[${charCodesToRemove.join("")}])`, "g");
18
+ /**
19
+ * Normalize the given header value.
20
+ * @see https://fetch.spec.whatwg.org/#concept-header-value-normalize
21
+ */
22
+ function normalizeHeaderValue(value) {
23
+ return value.replace(HEADER_VALUE_REMOVE_REGEXP, "");
24
+ }
25
+ //#endregion
26
+ //#region src/utils/isValidHeaderName.ts
27
+ /**
28
+ * Validate the given header name.
29
+ * @see https://fetch.spec.whatwg.org/#header-name
30
+ */
31
+ function isValidHeaderName(value) {
32
+ if (typeof value !== "string") return false;
33
+ if (value.length === 0) return false;
34
+ for (let i = 0; i < value.length; i++) {
35
+ const character = value.charCodeAt(i);
36
+ if (character > 127 || !isToken(character)) return false;
37
+ }
38
+ return true;
39
+ }
40
+ function isToken(value) {
41
+ return ![
42
+ 127,
43
+ 32,
44
+ "(",
45
+ ")",
46
+ "<",
47
+ ">",
48
+ "@",
49
+ ",",
50
+ ";",
51
+ ":",
52
+ "\\",
53
+ "\"",
54
+ "/",
55
+ "[",
56
+ "]",
57
+ "?",
58
+ "=",
59
+ "{",
60
+ "}"
61
+ ].includes(value);
62
+ }
63
+ //#endregion
64
+ //#region src/utils/isValidHeaderValue.ts
65
+ /**
66
+ * Validate the given header value.
67
+ * @see https://fetch.spec.whatwg.org/#header-value
68
+ */
69
+ function isValidHeaderValue(value) {
70
+ if (typeof value !== "string") return false;
71
+ if (value.trim() !== value) return false;
72
+ for (let i = 0; i < value.length; i++) {
73
+ const character = value.charCodeAt(i);
74
+ if (character === 0 || character === 10 || character === 13) return false;
75
+ }
76
+ return true;
77
+ }
78
+ //#endregion
79
+ //#region src/Headers.ts
80
+ let _Symbol$toStringTag;
81
+ const NORMALIZED_HEADERS = Symbol("normalizedHeaders");
82
+ const RAW_HEADER_NAMES = Symbol("rawHeaderNames");
83
+ const HEADER_VALUE_DELIMITER = ", ";
84
+ var Headers = class Headers {
85
+ constructor(init) {
86
+ this[NORMALIZED_HEADERS] = {};
87
+ this[RAW_HEADER_NAMES] = /* @__PURE__ */ new Map();
88
+ this[_Symbol$toStringTag] = "Headers";
89
+ /**
90
+ * @note Cannot necessarily check if the `init` is an instance of the
91
+ * `Headers` because that class may not be defined in Node or jsdom.
92
+ */
93
+ if (["Headers", "HeadersPolyfill"].includes(init?.constructor?.name) || init instanceof Headers || typeof globalThis.Headers !== "undefined" && init instanceof globalThis.Headers) init.forEach((value, name) => {
94
+ this.append(name, value);
95
+ }, this);
96
+ else if (Array.isArray(init)) init.forEach(([name, value]) => {
97
+ this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
98
+ });
99
+ else if (init) Object.getOwnPropertyNames(init).forEach((name) => {
100
+ const value = init[name];
101
+ this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
102
+ });
103
+ }
104
+ [(_Symbol$toStringTag = Symbol.toStringTag, Symbol.iterator)]() {
105
+ return this.entries();
106
+ }
107
+ *keys() {
108
+ for (const [name] of this.entries()) yield name;
109
+ }
110
+ *values() {
111
+ for (const [, value] of this.entries()) yield value;
112
+ }
113
+ *entries() {
114
+ let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort((a, b) => a.localeCompare(b));
115
+ for (const name of sortedKeys) if (name === "set-cookie") for (const value of this.getSetCookie()) yield [name, value];
116
+ else yield [name, this.get(name)];
117
+ }
118
+ /**
119
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
120
+ */
121
+ has(name) {
122
+ if (!isValidHeaderName(name)) throw new TypeError(`Invalid header name "${name}"`);
123
+ return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
124
+ }
125
+ /**
126
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
127
+ */
128
+ get(name) {
129
+ if (!isValidHeaderName(name)) throw TypeError(`Invalid header name "${name}"`);
130
+ return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null;
131
+ }
132
+ /**
133
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
134
+ */
135
+ set(name, value) {
136
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) return;
137
+ const normalizedName = normalizeHeaderName(name);
138
+ const normalizedValue = normalizeHeaderValue(value);
139
+ this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(normalizedValue);
140
+ this[RAW_HEADER_NAMES].set(normalizedName, name);
141
+ }
142
+ /**
143
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
144
+ */
145
+ append(name, value) {
146
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) return;
147
+ const normalizedName = normalizeHeaderName(name);
148
+ const normalizedValue = normalizeHeaderValue(value);
149
+ let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${normalizedValue}` : normalizedValue;
150
+ this.set(name, resolvedValue);
151
+ }
152
+ /**
153
+ * Deletes a header from the `Headers` object.
154
+ */
155
+ delete(name) {
156
+ if (!isValidHeaderName(name)) return;
157
+ if (!this.has(name)) return;
158
+ const normalizedName = normalizeHeaderName(name);
159
+ delete this[NORMALIZED_HEADERS][normalizedName];
160
+ this[RAW_HEADER_NAMES].delete(normalizedName);
161
+ }
162
+ /**
163
+ * Traverses the `Headers` object,
164
+ * calling the given callback for each header.
165
+ */
166
+ forEach(callback, thisArg) {
167
+ for (const [name, value] of this.entries()) callback.call(thisArg, value, name, this);
168
+ }
169
+ /**
170
+ * Returns an array containing the values
171
+ * of all Set-Cookie headers associated
172
+ * with a response
173
+ */
174
+ getSetCookie() {
175
+ const setCookieHeader = this.get("set-cookie");
176
+ if (setCookieHeader === null) return [];
177
+ if (setCookieHeader === "") return [""];
178
+ return (0, set_cookie_parser.splitCookiesString)(setCookieHeader);
179
+ }
180
+ };
181
+ //#endregion
182
+ //#region src/getRawHeaders.ts
183
+ /**
184
+ * Returns the object of all raw headers.
185
+ */
186
+ function getRawHeaders(headers) {
187
+ const rawHeaders = {};
188
+ for (const [name, value] of headers.entries()) rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
189
+ return rawHeaders;
190
+ }
191
+ //#endregion
192
+ //#region src/transformers/headersToList.ts
193
+ function headersToList(headers) {
194
+ const headersList = [];
195
+ headers.forEach((value, name) => {
196
+ const resolvedValue = value.includes(",") ? value.split(",").map((value) => value.trim()) : value;
197
+ headersList.push([name, resolvedValue]);
198
+ });
199
+ return headersList;
200
+ }
201
+ //#endregion
202
+ //#region src/transformers/headersToString.ts
203
+ /**
204
+ * Converts a given `Headers` instance to its string representation.
205
+ */
206
+ function headersToString(headers) {
207
+ return headersToList(headers).map(([name, value]) => {
208
+ return `${name}: ${[].concat(value).join(", ")}`;
209
+ }).join("\r\n");
210
+ }
211
+ //#endregion
212
+ //#region src/transformers/headersToObject.ts
213
+ const singleValueHeaders = ["user-agent"];
214
+ /**
215
+ * Converts a given `Headers` instance into a plain object.
216
+ * Respects headers with multiple values.
217
+ */
218
+ function headersToObject(headers) {
219
+ const headersObject = {};
220
+ headers.forEach((value, name) => {
221
+ headersObject[name] = !singleValueHeaders.includes(name.toLowerCase()) && value.includes(",") ? value.split(",").map((s) => s.trim()) : value;
222
+ });
223
+ return headersObject;
224
+ }
225
+ //#endregion
226
+ //#region src/transformers/stringToHeaders.ts
227
+ /**
228
+ * Converts a string representation of headers (i.e. from XMLHttpRequest)
229
+ * to a new `Headers` instance.
230
+ */
231
+ function stringToHeaders(str) {
232
+ return str.trim().split(/[\r\n]+/).reduce((headers, line) => {
233
+ if (line.trim() === "") return headers;
234
+ const parts = line.split(": ");
235
+ const name = parts.shift();
236
+ const value = parts.join(": ");
237
+ headers.append(name, value);
238
+ return headers;
239
+ }, new Headers());
240
+ }
241
+ //#endregion
242
+ //#region src/transformers/listToHeaders.ts
243
+ function listToHeaders(list) {
244
+ const headers = new Headers();
245
+ list.forEach(([name, value]) => {
246
+ [].concat(value).forEach((value) => {
247
+ headers.append(name, value);
248
+ });
249
+ });
250
+ return headers;
251
+ }
252
+ //#endregion
253
+ //#region src/transformers/reduceHeadersObject.ts
254
+ /**
255
+ * Reduces given headers object instnace.
256
+ */
257
+ function reduceHeadersObject(headers, reducer, initialState) {
258
+ return Object.keys(headers).reduce((nextHeaders, name) => {
259
+ return reducer(nextHeaders, name, headers[name]);
260
+ }, initialState);
261
+ }
262
+ //#endregion
263
+ //#region src/transformers/objectToHeaders.ts
264
+ /**
265
+ * Converts a given headers object to a new `Headers` instance.
266
+ */
267
+ function objectToHeaders(headersObject) {
268
+ return reduceHeadersObject(headersObject, (headers, name, value) => {
269
+ [].concat(value).filter(Boolean).forEach((value) => {
270
+ headers.append(name, value);
271
+ });
272
+ return headers;
273
+ }, new Headers());
274
+ }
275
+ //#endregion
276
+ //#region src/transformers/flattenHeadersList.ts
277
+ function flattenHeadersList(list) {
278
+ return list.map(([name, values]) => {
279
+ return [name, [].concat(values).join(", ")];
280
+ });
281
+ }
282
+ //#endregion
283
+ //#region src/transformers/flattenHeadersObject.ts
284
+ function flattenHeadersObject(headersObject) {
285
+ return reduceHeadersObject(headersObject, (headers, name, value) => {
286
+ headers[name] = [].concat(value).join(", ");
287
+ return headers;
288
+ }, {});
289
+ }
290
+ //#endregion
291
+ exports.Headers = Headers;
292
+ exports.flattenHeadersList = flattenHeadersList;
293
+ exports.flattenHeadersObject = flattenHeadersObject;
294
+ exports.getRawHeaders = getRawHeaders;
295
+ exports.headersToList = headersToList;
296
+ exports.headersToObject = headersToObject;
297
+ exports.headersToString = headersToString;
298
+ exports.listToHeaders = listToHeaders;
299
+ exports.objectToHeaders = objectToHeaders;
300
+ exports.reduceHeadersObject = reduceHeadersObject;
301
+ exports.stringToHeaders = stringToHeaders;
302
+
303
+ //# sourceMappingURL=index.cjs.map
node_modules/headers-polyfill/lib/index.cjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/utils/normalizeHeaderName.ts","../src/utils/normalizeHeaderValue.ts","../src/utils/isValidHeaderName.ts","../src/utils/isValidHeaderValue.ts","../src/Headers.ts","../src/getRawHeaders.ts","../src/transformers/headersToList.ts","../src/transformers/headersToString.ts","../src/transformers/headersToObject.ts","../src/transformers/stringToHeaders.ts","../src/transformers/listToHeaders.ts","../src/transformers/reduceHeadersObject.ts","../src/transformers/objectToHeaders.ts","../src/transformers/flattenHeadersList.ts","../src/transformers/flattenHeadersObject.ts"],"sourcesContent":["const HEADERS_INVALID_CHARACTERS = /[^a-z0-9\\-#$%&'*+.^_`|~]/i\n\nexport function normalizeHeaderName(name: string): string {\n if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === '') {\n throw new TypeError('Invalid character in header field name')\n }\n\n return name.trim().toLowerCase()\n}\n","const charCodesToRemove = [\n String.fromCharCode(0x0a),\n String.fromCharCode(0x0d),\n String.fromCharCode(0x09),\n String.fromCharCode(0x20),\n]\n\nconst HEADER_VALUE_REMOVE_REGEXP = new RegExp(\n `(^[${charCodesToRemove.join('')}]|$[${charCodesToRemove.join('')}])`,\n 'g'\n)\n\n/**\n * Normalize the given header value.\n * @see https://fetch.spec.whatwg.org/#concept-header-value-normalize\n */\nexport function normalizeHeaderValue(value: string): string {\n const nextValue = value.replace(HEADER_VALUE_REMOVE_REGEXP, '')\n return nextValue\n}\n","/**\n * Validate the given header name.\n * @see https://fetch.spec.whatwg.org/#header-name\n */\nexport function isValidHeaderName(value: unknown) {\n if (typeof value !== 'string') {\n return false\n }\n\n if (value.length === 0) {\n return false\n }\n\n for (let i = 0; i < value.length; i++) {\n const character = value.charCodeAt(i)\n\n if (character > 0x7f || !isToken(character)) {\n return false\n }\n }\n\n return true\n}\n\nfunction isToken(value: string | number): boolean {\n return ![\n 0x7f,\n 0x20,\n '(',\n ')',\n '<',\n '>',\n '@',\n ',',\n ';',\n ':',\n '\\\\',\n '\"',\n '/',\n '[',\n ']',\n '?',\n '=',\n '{',\n '}',\n ].includes(value)\n}\n","/**\n * Validate the given header value.\n * @see https://fetch.spec.whatwg.org/#header-value\n */\nexport function isValidHeaderValue(value: unknown): boolean {\n if (typeof value !== 'string') {\n return false\n }\n\n if (value.trim() !== value) {\n return false\n }\n\n for (let i = 0; i < value.length; i++) {\n const character = value.charCodeAt(i)\n\n if (\n // NUL.\n character === 0x00 ||\n // HTTP newline bytes.\n character === 0x0a ||\n character === 0x0d\n ) {\n return false\n }\n }\n\n return true\n}\n","import { splitCookiesString } from 'set-cookie-parser'\nimport { HeadersList, HeadersObject } from './glossary'\nimport { normalizeHeaderName } from './utils/normalizeHeaderName'\nimport { normalizeHeaderValue } from './utils/normalizeHeaderValue'\nimport { isValidHeaderName } from './utils/isValidHeaderName'\nimport { isValidHeaderValue } from './utils/isValidHeaderValue'\n\nexport const NORMALIZED_HEADERS: unique symbol = Symbol('normalizedHeaders')\n\nexport const RAW_HEADER_NAMES: unique symbol = Symbol('rawHeaderNames')\n\nconst HEADER_VALUE_DELIMITER = ', ' as const\n\nexport class Headers {\n // Normalized header {\"name\":\"a, b\"} storage.\n private [NORMALIZED_HEADERS]: Record<string, string> = {}\n\n // Keeps the mapping between the raw header name\n // and the normalized header name to ease the lookup.\n private [RAW_HEADER_NAMES]: Map<string, string> = new Map()\n\n constructor(init?: HeadersInit | HeadersObject | HeadersList) {\n /**\n * @note Cannot necessarily check if the `init` is an instance of the\n * `Headers` because that class may not be defined in Node or jsdom.\n */\n if (\n ['Headers', 'HeadersPolyfill'].includes(init?.constructor?.name) ||\n init instanceof Headers ||\n (typeof globalThis.Headers !== 'undefined' &&\n init instanceof globalThis.Headers)\n ) {\n const initialHeaders = init as Headers\n initialHeaders.forEach((value, name) => {\n this.append(name, value)\n }, this)\n } else if (Array.isArray(init)) {\n init.forEach(([name, value]) => {\n this.append(\n name,\n Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value\n )\n })\n } else if (init) {\n Object.getOwnPropertyNames(init).forEach((name) => {\n const value = init[name]\n this.append(\n name,\n Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value\n )\n })\n }\n }\n\n [Symbol.toStringTag] = 'Headers';\n\n [Symbol.iterator]() {\n return this.entries()\n }\n\n *keys(): Generator<string> {\n for (const [name] of this.entries()) {\n yield name\n }\n }\n\n *values(): Generator<string> {\n for (const [, value] of this.entries()) {\n yield value\n }\n }\n\n *entries(): Generator<[string, string]> {\n // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine\n let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort((a, b) =>\n a.localeCompare(b)\n )\n for (const name of sortedKeys) {\n if (name === 'set-cookie') {\n for (const value of this.getSetCookie()) {\n yield [name, value]\n }\n } else {\n yield [name, this.get(name)]\n }\n }\n }\n\n /**\n * Returns a boolean stating whether a `Headers` object contains a certain header.\n */\n has(name: string): boolean {\n if (!isValidHeaderName(name)) {\n throw new TypeError(`Invalid header name \"${name}\"`)\n }\n\n return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name))\n }\n\n /**\n * Returns a `ByteString` sequence of all the values of a header with a given name.\n */\n get(name: string): string | null {\n if (!isValidHeaderName(name)) {\n throw TypeError(`Invalid header name \"${name}\"`)\n }\n\n return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null\n }\n\n /**\n * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.\n */\n set(name: string, value: string): void {\n if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n const normalizedValue = normalizeHeaderValue(value)\n\n this[NORMALIZED_HEADERS][normalizedName] =\n normalizeHeaderValue(normalizedValue)\n this[RAW_HEADER_NAMES].set(normalizedName, name)\n }\n\n /**\n * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.\n */\n append(name: string, value: string): void {\n if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n const normalizedValue = normalizeHeaderValue(value)\n\n let resolvedValue = this.has(normalizedName)\n ? `${this.get(normalizedName)}, ${normalizedValue}`\n : normalizedValue\n\n this.set(name, resolvedValue)\n }\n\n /**\n * Deletes a header from the `Headers` object.\n */\n delete(name: string): void {\n if (!isValidHeaderName(name)) {\n return\n }\n\n if (!this.has(name)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n delete this[NORMALIZED_HEADERS][normalizedName]\n this[RAW_HEADER_NAMES].delete(normalizedName)\n }\n\n /**\n * Traverses the `Headers` object,\n * calling the given callback for each header.\n */\n forEach<ThisArg = this>(\n callback: (\n this: ThisArg,\n value: string,\n name: string,\n parent: this\n ) => void,\n thisArg?: ThisArg\n ) {\n for (const [name, value] of this.entries()) {\n callback.call(thisArg, value, name, this)\n }\n }\n\n /**\n * Returns an array containing the values\n * of all Set-Cookie headers associated\n * with a response\n */\n getSetCookie(): string[] {\n const setCookieHeader = this.get('set-cookie')\n\n if (setCookieHeader === null) {\n return []\n }\n\n if (setCookieHeader === '') {\n return ['']\n }\n\n return splitCookiesString(setCookieHeader)\n }\n}\n","import { RAW_HEADER_NAMES } from './Headers'\n\n/**\n * Returns the object of all raw headers.\n */\nexport function getRawHeaders(headers: Headers) {\n const rawHeaders: Record<string, string> = {}\n\n for (const [name, value] of headers.entries()) {\n rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value\n }\n\n return rawHeaders\n}\n","import { HeadersList } from '../glossary'\n\nexport function headersToList(headers: Headers): HeadersList {\n const headersList: HeadersList = []\n\n headers.forEach((value, name) => {\n const resolvedValue = value.includes(',')\n ? value.split(',').map((value) => value.trim())\n : value\n\n headersList.push([name, resolvedValue])\n })\n\n return headersList\n}\n","import { headersToList } from './headersToList'\n\n/**\n * Converts a given `Headers` instance to its string representation.\n */\nexport function headersToString(headers: Headers): string {\n const list = headersToList(headers)\n const lines = list.map(([name, value]) => {\n const values = ([] as string[]).concat(value)\n return `${name}: ${values.join(', ')}`\n })\n\n return lines.join('\\r\\n')\n}\n","import { HeadersObject } from '../glossary'\n\n// List of headers that cannot have multiple values,\n// while potentially having a comma in their single value.\nconst singleValueHeaders = ['user-agent']\n\n/**\n * Converts a given `Headers` instance into a plain object.\n * Respects headers with multiple values.\n */\nexport function headersToObject(headers: Headers): HeadersObject {\n const headersObject: HeadersObject = {}\n\n headers.forEach((value, name) => {\n const isMultiValue =\n !singleValueHeaders.includes(name.toLowerCase()) && value.includes(',')\n headersObject[name] = isMultiValue\n ? value.split(',').map((s) => s.trim())\n : value\n })\n\n return headersObject\n}\n","import { Headers } from '../Headers'\n\n/**\n * Converts a string representation of headers (i.e. from XMLHttpRequest)\n * to a new `Headers` instance.\n */\nexport function stringToHeaders(str: string): Headers {\n const lines = str.trim().split(/[\\r\\n]+/)\n\n return lines.reduce((headers, line) => {\n if (line.trim() === '') {\n return headers\n }\n\n const parts = line.split(': ')\n const name = parts.shift()\n const value = parts.join(': ')\n headers.append(name, value)\n\n return headers\n }, new Headers())\n}\n","import { Headers } from '../Headers'\nimport { HeadersList } from '../glossary'\n\nexport function listToHeaders(list: HeadersList): Headers {\n const headers = new Headers()\n\n list.forEach(([name, value]) => {\n const values = ([] as string[]).concat(value)\n\n values.forEach((value) => {\n headers.append(name, value)\n })\n })\n\n return headers\n}\n","import { HeadersObject } from '../glossary'\n\n/**\n * Reduces given headers object instnace.\n */\nexport function reduceHeadersObject<R>(\n headers: HeadersObject,\n reducer: (headers: R, name: string, value: string | string[]) => R,\n initialState: R\n): R {\n return Object.keys(headers).reduce<R>((nextHeaders, name) => {\n return reducer(nextHeaders, name, headers[name])\n }, initialState)\n}\n","import { Headers } from '../Headers'\nimport { reduceHeadersObject } from './reduceHeadersObject'\n\n/**\n * Converts a given headers object to a new `Headers` instance.\n */\nexport function objectToHeaders(\n headersObject: Record<string, string | string[] | undefined>\n): Headers {\n return reduceHeadersObject(\n headersObject,\n (headers, name, value) => {\n const values = ([] as string[]).concat(value).filter(Boolean)\n\n values.forEach((value) => {\n headers.append(name, value)\n })\n\n return headers\n },\n new Headers()\n )\n}\n","import { HeadersList, FlatHeadersList } from '../glossary'\n\nexport function flattenHeadersList(list: HeadersList): FlatHeadersList {\n return list.map(([name, values]) => {\n return [name, ([] as string[]).concat(values).join(', ')]\n })\n}\n","import { HeadersObject, FlatHeadersObject } from '../glossary'\nimport { reduceHeadersObject } from './reduceHeadersObject'\n\nexport function flattenHeadersObject(\n headersObject: HeadersObject\n): FlatHeadersObject {\n return reduceHeadersObject<FlatHeadersObject>(\n headersObject,\n (headers, name, value) => {\n headers[name] = ([] as string[]).concat(value).join(', ')\n return headers\n },\n {}\n )\n}\n"],"mappings":"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"}
node_modules/headers-polyfill/lib/index.d.cts ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#region src/glossary.d.ts
2
+ type HeadersList = Array<[string, string | string[]]>;
3
+ type FlatHeadersList = [string, string][];
4
+ type HeadersObject = Record<string, string | string[]>;
5
+ type FlatHeadersObject = Record<string, string>;
6
+ //#endregion
7
+ //#region src/Headers.d.ts
8
+ declare const NORMALIZED_HEADERS: unique symbol;
9
+ declare const RAW_HEADER_NAMES: unique symbol;
10
+ declare class Headers$1 {
11
+ private [NORMALIZED_HEADERS];
12
+ private [RAW_HEADER_NAMES];
13
+ constructor(init?: HeadersInit | HeadersObject | HeadersList);
14
+ [Symbol.toStringTag]: string;
15
+ [Symbol.iterator](): Generator<[string, string], any, any>;
16
+ keys(): Generator<string>;
17
+ values(): Generator<string>;
18
+ entries(): Generator<[string, string]>;
19
+ /**
20
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
21
+ */
22
+ has(name: string): boolean;
23
+ /**
24
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
25
+ */
26
+ get(name: string): string | null;
27
+ /**
28
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
29
+ */
30
+ set(name: string, value: string): void;
31
+ /**
32
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
33
+ */
34
+ append(name: string, value: string): void;
35
+ /**
36
+ * Deletes a header from the `Headers` object.
37
+ */
38
+ delete(name: string): void;
39
+ /**
40
+ * Traverses the `Headers` object,
41
+ * calling the given callback for each header.
42
+ */
43
+ forEach<ThisArg = this>(callback: (this: ThisArg, value: string, name: string, parent: this) => void, thisArg?: ThisArg): void;
44
+ /**
45
+ * Returns an array containing the values
46
+ * of all Set-Cookie headers associated
47
+ * with a response
48
+ */
49
+ getSetCookie(): string[];
50
+ }
51
+ //#endregion
52
+ //#region src/getRawHeaders.d.ts
53
+ /**
54
+ * Returns the object of all raw headers.
55
+ */
56
+ declare function getRawHeaders(headers: Headers): Record<string, string>;
57
+ //#endregion
58
+ //#region src/transformers/headersToString.d.ts
59
+ /**
60
+ * Converts a given `Headers` instance to its string representation.
61
+ */
62
+ declare function headersToString(headers: Headers): string;
63
+ //#endregion
64
+ //#region src/transformers/headersToList.d.ts
65
+ declare function headersToList(headers: Headers): HeadersList;
66
+ //#endregion
67
+ //#region src/transformers/headersToObject.d.ts
68
+ /**
69
+ * Converts a given `Headers` instance into a plain object.
70
+ * Respects headers with multiple values.
71
+ */
72
+ declare function headersToObject(headers: Headers): HeadersObject;
73
+ //#endregion
74
+ //#region src/transformers/stringToHeaders.d.ts
75
+ /**
76
+ * Converts a string representation of headers (i.e. from XMLHttpRequest)
77
+ * to a new `Headers` instance.
78
+ */
79
+ declare function stringToHeaders(str: string): Headers$1;
80
+ //#endregion
81
+ //#region src/transformers/listToHeaders.d.ts
82
+ declare function listToHeaders(list: HeadersList): Headers$1;
83
+ //#endregion
84
+ //#region src/transformers/objectToHeaders.d.ts
85
+ /**
86
+ * Converts a given headers object to a new `Headers` instance.
87
+ */
88
+ declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): Headers$1;
89
+ //#endregion
90
+ //#region src/transformers/reduceHeadersObject.d.ts
91
+ /**
92
+ * Reduces given headers object instnace.
93
+ */
94
+ declare function reduceHeadersObject<R>(headers: HeadersObject, reducer: (headers: R, name: string, value: string | string[]) => R, initialState: R): R;
95
+ //#endregion
96
+ //#region src/transformers/flattenHeadersList.d.ts
97
+ declare function flattenHeadersList(list: HeadersList): FlatHeadersList;
98
+ //#endregion
99
+ //#region src/transformers/flattenHeadersObject.d.ts
100
+ declare function flattenHeadersObject(headersObject: HeadersObject): FlatHeadersObject;
101
+ //#endregion
102
+ export { type FlatHeadersList, type FlatHeadersObject, Headers$1 as Headers, type HeadersList, type HeadersObject, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
103
+ //# sourceMappingURL=index.d.cts.map
node_modules/headers-polyfill/lib/index.d.mts ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#region src/glossary.d.ts
2
+ type HeadersList = Array<[string, string | string[]]>;
3
+ type FlatHeadersList = [string, string][];
4
+ type HeadersObject = Record<string, string | string[]>;
5
+ type FlatHeadersObject = Record<string, string>;
6
+ //#endregion
7
+ //#region src/Headers.d.ts
8
+ declare const NORMALIZED_HEADERS: unique symbol;
9
+ declare const RAW_HEADER_NAMES: unique symbol;
10
+ declare class Headers$1 {
11
+ private [NORMALIZED_HEADERS];
12
+ private [RAW_HEADER_NAMES];
13
+ constructor(init?: HeadersInit | HeadersObject | HeadersList);
14
+ [Symbol.toStringTag]: string;
15
+ [Symbol.iterator](): Generator<[string, string], any, any>;
16
+ keys(): Generator<string>;
17
+ values(): Generator<string>;
18
+ entries(): Generator<[string, string]>;
19
+ /**
20
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
21
+ */
22
+ has(name: string): boolean;
23
+ /**
24
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
25
+ */
26
+ get(name: string): string | null;
27
+ /**
28
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
29
+ */
30
+ set(name: string, value: string): void;
31
+ /**
32
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
33
+ */
34
+ append(name: string, value: string): void;
35
+ /**
36
+ * Deletes a header from the `Headers` object.
37
+ */
38
+ delete(name: string): void;
39
+ /**
40
+ * Traverses the `Headers` object,
41
+ * calling the given callback for each header.
42
+ */
43
+ forEach<ThisArg = this>(callback: (this: ThisArg, value: string, name: string, parent: this) => void, thisArg?: ThisArg): void;
44
+ /**
45
+ * Returns an array containing the values
46
+ * of all Set-Cookie headers associated
47
+ * with a response
48
+ */
49
+ getSetCookie(): string[];
50
+ }
51
+ //#endregion
52
+ //#region src/getRawHeaders.d.ts
53
+ /**
54
+ * Returns the object of all raw headers.
55
+ */
56
+ declare function getRawHeaders(headers: Headers): Record<string, string>;
57
+ //#endregion
58
+ //#region src/transformers/headersToString.d.ts
59
+ /**
60
+ * Converts a given `Headers` instance to its string representation.
61
+ */
62
+ declare function headersToString(headers: Headers): string;
63
+ //#endregion
64
+ //#region src/transformers/headersToList.d.ts
65
+ declare function headersToList(headers: Headers): HeadersList;
66
+ //#endregion
67
+ //#region src/transformers/headersToObject.d.ts
68
+ /**
69
+ * Converts a given `Headers` instance into a plain object.
70
+ * Respects headers with multiple values.
71
+ */
72
+ declare function headersToObject(headers: Headers): HeadersObject;
73
+ //#endregion
74
+ //#region src/transformers/stringToHeaders.d.ts
75
+ /**
76
+ * Converts a string representation of headers (i.e. from XMLHttpRequest)
77
+ * to a new `Headers` instance.
78
+ */
79
+ declare function stringToHeaders(str: string): Headers$1;
80
+ //#endregion
81
+ //#region src/transformers/listToHeaders.d.ts
82
+ declare function listToHeaders(list: HeadersList): Headers$1;
83
+ //#endregion
84
+ //#region src/transformers/objectToHeaders.d.ts
85
+ /**
86
+ * Converts a given headers object to a new `Headers` instance.
87
+ */
88
+ declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): Headers$1;
89
+ //#endregion
90
+ //#region src/transformers/reduceHeadersObject.d.ts
91
+ /**
92
+ * Reduces given headers object instnace.
93
+ */
94
+ declare function reduceHeadersObject<R>(headers: HeadersObject, reducer: (headers: R, name: string, value: string | string[]) => R, initialState: R): R;
95
+ //#endregion
96
+ //#region src/transformers/flattenHeadersList.d.ts
97
+ declare function flattenHeadersList(list: HeadersList): FlatHeadersList;
98
+ //#endregion
99
+ //#region src/transformers/flattenHeadersObject.d.ts
100
+ declare function flattenHeadersObject(headersObject: HeadersObject): FlatHeadersObject;
101
+ //#endregion
102
+ export { type FlatHeadersList, type FlatHeadersObject, Headers$1 as Headers, type HeadersList, type HeadersObject, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
103
+ //# sourceMappingURL=index.d.mts.map
node_modules/headers-polyfill/lib/index.mjs ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { splitCookiesString } from "set-cookie-parser";
2
+ //#region src/utils/normalizeHeaderName.ts
3
+ const HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
4
+ function normalizeHeaderName(name) {
5
+ if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === "") throw new TypeError("Invalid character in header field name");
6
+ return name.trim().toLowerCase();
7
+ }
8
+ //#endregion
9
+ //#region src/utils/normalizeHeaderValue.ts
10
+ const charCodesToRemove = [
11
+ String.fromCharCode(10),
12
+ String.fromCharCode(13),
13
+ String.fromCharCode(9),
14
+ String.fromCharCode(32)
15
+ ];
16
+ const HEADER_VALUE_REMOVE_REGEXP = new RegExp(`(^[${charCodesToRemove.join("")}]|$[${charCodesToRemove.join("")}])`, "g");
17
+ /**
18
+ * Normalize the given header value.
19
+ * @see https://fetch.spec.whatwg.org/#concept-header-value-normalize
20
+ */
21
+ function normalizeHeaderValue(value) {
22
+ return value.replace(HEADER_VALUE_REMOVE_REGEXP, "");
23
+ }
24
+ //#endregion
25
+ //#region src/utils/isValidHeaderName.ts
26
+ /**
27
+ * Validate the given header name.
28
+ * @see https://fetch.spec.whatwg.org/#header-name
29
+ */
30
+ function isValidHeaderName(value) {
31
+ if (typeof value !== "string") return false;
32
+ if (value.length === 0) return false;
33
+ for (let i = 0; i < value.length; i++) {
34
+ const character = value.charCodeAt(i);
35
+ if (character > 127 || !isToken(character)) return false;
36
+ }
37
+ return true;
38
+ }
39
+ function isToken(value) {
40
+ return ![
41
+ 127,
42
+ 32,
43
+ "(",
44
+ ")",
45
+ "<",
46
+ ">",
47
+ "@",
48
+ ",",
49
+ ";",
50
+ ":",
51
+ "\\",
52
+ "\"",
53
+ "/",
54
+ "[",
55
+ "]",
56
+ "?",
57
+ "=",
58
+ "{",
59
+ "}"
60
+ ].includes(value);
61
+ }
62
+ //#endregion
63
+ //#region src/utils/isValidHeaderValue.ts
64
+ /**
65
+ * Validate the given header value.
66
+ * @see https://fetch.spec.whatwg.org/#header-value
67
+ */
68
+ function isValidHeaderValue(value) {
69
+ if (typeof value !== "string") return false;
70
+ if (value.trim() !== value) return false;
71
+ for (let i = 0; i < value.length; i++) {
72
+ const character = value.charCodeAt(i);
73
+ if (character === 0 || character === 10 || character === 13) return false;
74
+ }
75
+ return true;
76
+ }
77
+ //#endregion
78
+ //#region src/Headers.ts
79
+ let _Symbol$toStringTag;
80
+ const NORMALIZED_HEADERS = Symbol("normalizedHeaders");
81
+ const RAW_HEADER_NAMES = Symbol("rawHeaderNames");
82
+ const HEADER_VALUE_DELIMITER = ", ";
83
+ var Headers = class Headers {
84
+ constructor(init) {
85
+ this[NORMALIZED_HEADERS] = {};
86
+ this[RAW_HEADER_NAMES] = /* @__PURE__ */ new Map();
87
+ this[_Symbol$toStringTag] = "Headers";
88
+ /**
89
+ * @note Cannot necessarily check if the `init` is an instance of the
90
+ * `Headers` because that class may not be defined in Node or jsdom.
91
+ */
92
+ if (["Headers", "HeadersPolyfill"].includes(init?.constructor?.name) || init instanceof Headers || typeof globalThis.Headers !== "undefined" && init instanceof globalThis.Headers) init.forEach((value, name) => {
93
+ this.append(name, value);
94
+ }, this);
95
+ else if (Array.isArray(init)) init.forEach(([name, value]) => {
96
+ this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
97
+ });
98
+ else if (init) Object.getOwnPropertyNames(init).forEach((name) => {
99
+ const value = init[name];
100
+ this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
101
+ });
102
+ }
103
+ [(_Symbol$toStringTag = Symbol.toStringTag, Symbol.iterator)]() {
104
+ return this.entries();
105
+ }
106
+ *keys() {
107
+ for (const [name] of this.entries()) yield name;
108
+ }
109
+ *values() {
110
+ for (const [, value] of this.entries()) yield value;
111
+ }
112
+ *entries() {
113
+ let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort((a, b) => a.localeCompare(b));
114
+ for (const name of sortedKeys) if (name === "set-cookie") for (const value of this.getSetCookie()) yield [name, value];
115
+ else yield [name, this.get(name)];
116
+ }
117
+ /**
118
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
119
+ */
120
+ has(name) {
121
+ if (!isValidHeaderName(name)) throw new TypeError(`Invalid header name "${name}"`);
122
+ return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
123
+ }
124
+ /**
125
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
126
+ */
127
+ get(name) {
128
+ if (!isValidHeaderName(name)) throw TypeError(`Invalid header name "${name}"`);
129
+ return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null;
130
+ }
131
+ /**
132
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
133
+ */
134
+ set(name, value) {
135
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) return;
136
+ const normalizedName = normalizeHeaderName(name);
137
+ const normalizedValue = normalizeHeaderValue(value);
138
+ this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(normalizedValue);
139
+ this[RAW_HEADER_NAMES].set(normalizedName, name);
140
+ }
141
+ /**
142
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
143
+ */
144
+ append(name, value) {
145
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) return;
146
+ const normalizedName = normalizeHeaderName(name);
147
+ const normalizedValue = normalizeHeaderValue(value);
148
+ let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${normalizedValue}` : normalizedValue;
149
+ this.set(name, resolvedValue);
150
+ }
151
+ /**
152
+ * Deletes a header from the `Headers` object.
153
+ */
154
+ delete(name) {
155
+ if (!isValidHeaderName(name)) return;
156
+ if (!this.has(name)) return;
157
+ const normalizedName = normalizeHeaderName(name);
158
+ delete this[NORMALIZED_HEADERS][normalizedName];
159
+ this[RAW_HEADER_NAMES].delete(normalizedName);
160
+ }
161
+ /**
162
+ * Traverses the `Headers` object,
163
+ * calling the given callback for each header.
164
+ */
165
+ forEach(callback, thisArg) {
166
+ for (const [name, value] of this.entries()) callback.call(thisArg, value, name, this);
167
+ }
168
+ /**
169
+ * Returns an array containing the values
170
+ * of all Set-Cookie headers associated
171
+ * with a response
172
+ */
173
+ getSetCookie() {
174
+ const setCookieHeader = this.get("set-cookie");
175
+ if (setCookieHeader === null) return [];
176
+ if (setCookieHeader === "") return [""];
177
+ return splitCookiesString(setCookieHeader);
178
+ }
179
+ };
180
+ //#endregion
181
+ //#region src/getRawHeaders.ts
182
+ /**
183
+ * Returns the object of all raw headers.
184
+ */
185
+ function getRawHeaders(headers) {
186
+ const rawHeaders = {};
187
+ for (const [name, value] of headers.entries()) rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
188
+ return rawHeaders;
189
+ }
190
+ //#endregion
191
+ //#region src/transformers/headersToList.ts
192
+ function headersToList(headers) {
193
+ const headersList = [];
194
+ headers.forEach((value, name) => {
195
+ const resolvedValue = value.includes(",") ? value.split(",").map((value) => value.trim()) : value;
196
+ headersList.push([name, resolvedValue]);
197
+ });
198
+ return headersList;
199
+ }
200
+ //#endregion
201
+ //#region src/transformers/headersToString.ts
202
+ /**
203
+ * Converts a given `Headers` instance to its string representation.
204
+ */
205
+ function headersToString(headers) {
206
+ return headersToList(headers).map(([name, value]) => {
207
+ return `${name}: ${[].concat(value).join(", ")}`;
208
+ }).join("\r\n");
209
+ }
210
+ //#endregion
211
+ //#region src/transformers/headersToObject.ts
212
+ const singleValueHeaders = ["user-agent"];
213
+ /**
214
+ * Converts a given `Headers` instance into a plain object.
215
+ * Respects headers with multiple values.
216
+ */
217
+ function headersToObject(headers) {
218
+ const headersObject = {};
219
+ headers.forEach((value, name) => {
220
+ headersObject[name] = !singleValueHeaders.includes(name.toLowerCase()) && value.includes(",") ? value.split(",").map((s) => s.trim()) : value;
221
+ });
222
+ return headersObject;
223
+ }
224
+ //#endregion
225
+ //#region src/transformers/stringToHeaders.ts
226
+ /**
227
+ * Converts a string representation of headers (i.e. from XMLHttpRequest)
228
+ * to a new `Headers` instance.
229
+ */
230
+ function stringToHeaders(str) {
231
+ return str.trim().split(/[\r\n]+/).reduce((headers, line) => {
232
+ if (line.trim() === "") return headers;
233
+ const parts = line.split(": ");
234
+ const name = parts.shift();
235
+ const value = parts.join(": ");
236
+ headers.append(name, value);
237
+ return headers;
238
+ }, new Headers());
239
+ }
240
+ //#endregion
241
+ //#region src/transformers/listToHeaders.ts
242
+ function listToHeaders(list) {
243
+ const headers = new Headers();
244
+ list.forEach(([name, value]) => {
245
+ [].concat(value).forEach((value) => {
246
+ headers.append(name, value);
247
+ });
248
+ });
249
+ return headers;
250
+ }
251
+ //#endregion
252
+ //#region src/transformers/reduceHeadersObject.ts
253
+ /**
254
+ * Reduces given headers object instnace.
255
+ */
256
+ function reduceHeadersObject(headers, reducer, initialState) {
257
+ return Object.keys(headers).reduce((nextHeaders, name) => {
258
+ return reducer(nextHeaders, name, headers[name]);
259
+ }, initialState);
260
+ }
261
+ //#endregion
262
+ //#region src/transformers/objectToHeaders.ts
263
+ /**
264
+ * Converts a given headers object to a new `Headers` instance.
265
+ */
266
+ function objectToHeaders(headersObject) {
267
+ return reduceHeadersObject(headersObject, (headers, name, value) => {
268
+ [].concat(value).filter(Boolean).forEach((value) => {
269
+ headers.append(name, value);
270
+ });
271
+ return headers;
272
+ }, new Headers());
273
+ }
274
+ //#endregion
275
+ //#region src/transformers/flattenHeadersList.ts
276
+ function flattenHeadersList(list) {
277
+ return list.map(([name, values]) => {
278
+ return [name, [].concat(values).join(", ")];
279
+ });
280
+ }
281
+ //#endregion
282
+ //#region src/transformers/flattenHeadersObject.ts
283
+ function flattenHeadersObject(headersObject) {
284
+ return reduceHeadersObject(headersObject, (headers, name, value) => {
285
+ headers[name] = [].concat(value).join(", ");
286
+ return headers;
287
+ }, {});
288
+ }
289
+ //#endregion
290
+ export { Headers, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
291
+
292
+ //# sourceMappingURL=index.mjs.map
node_modules/headers-polyfill/lib/index.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/normalizeHeaderName.ts","../src/utils/normalizeHeaderValue.ts","../src/utils/isValidHeaderName.ts","../src/utils/isValidHeaderValue.ts","../src/Headers.ts","../src/getRawHeaders.ts","../src/transformers/headersToList.ts","../src/transformers/headersToString.ts","../src/transformers/headersToObject.ts","../src/transformers/stringToHeaders.ts","../src/transformers/listToHeaders.ts","../src/transformers/reduceHeadersObject.ts","../src/transformers/objectToHeaders.ts","../src/transformers/flattenHeadersList.ts","../src/transformers/flattenHeadersObject.ts"],"sourcesContent":["const HEADERS_INVALID_CHARACTERS = /[^a-z0-9\\-#$%&'*+.^_`|~]/i\n\nexport function normalizeHeaderName(name: string): string {\n if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === '') {\n throw new TypeError('Invalid character in header field name')\n }\n\n return name.trim().toLowerCase()\n}\n","const charCodesToRemove = [\n String.fromCharCode(0x0a),\n String.fromCharCode(0x0d),\n String.fromCharCode(0x09),\n String.fromCharCode(0x20),\n]\n\nconst HEADER_VALUE_REMOVE_REGEXP = new RegExp(\n `(^[${charCodesToRemove.join('')}]|$[${charCodesToRemove.join('')}])`,\n 'g'\n)\n\n/**\n * Normalize the given header value.\n * @see https://fetch.spec.whatwg.org/#concept-header-value-normalize\n */\nexport function normalizeHeaderValue(value: string): string {\n const nextValue = value.replace(HEADER_VALUE_REMOVE_REGEXP, '')\n return nextValue\n}\n","/**\n * Validate the given header name.\n * @see https://fetch.spec.whatwg.org/#header-name\n */\nexport function isValidHeaderName(value: unknown) {\n if (typeof value !== 'string') {\n return false\n }\n\n if (value.length === 0) {\n return false\n }\n\n for (let i = 0; i < value.length; i++) {\n const character = value.charCodeAt(i)\n\n if (character > 0x7f || !isToken(character)) {\n return false\n }\n }\n\n return true\n}\n\nfunction isToken(value: string | number): boolean {\n return ![\n 0x7f,\n 0x20,\n '(',\n ')',\n '<',\n '>',\n '@',\n ',',\n ';',\n ':',\n '\\\\',\n '\"',\n '/',\n '[',\n ']',\n '?',\n '=',\n '{',\n '}',\n ].includes(value)\n}\n","/**\n * Validate the given header value.\n * @see https://fetch.spec.whatwg.org/#header-value\n */\nexport function isValidHeaderValue(value: unknown): boolean {\n if (typeof value !== 'string') {\n return false\n }\n\n if (value.trim() !== value) {\n return false\n }\n\n for (let i = 0; i < value.length; i++) {\n const character = value.charCodeAt(i)\n\n if (\n // NUL.\n character === 0x00 ||\n // HTTP newline bytes.\n character === 0x0a ||\n character === 0x0d\n ) {\n return false\n }\n }\n\n return true\n}\n","import { splitCookiesString } from 'set-cookie-parser'\nimport { HeadersList, HeadersObject } from './glossary'\nimport { normalizeHeaderName } from './utils/normalizeHeaderName'\nimport { normalizeHeaderValue } from './utils/normalizeHeaderValue'\nimport { isValidHeaderName } from './utils/isValidHeaderName'\nimport { isValidHeaderValue } from './utils/isValidHeaderValue'\n\nexport const NORMALIZED_HEADERS: unique symbol = Symbol('normalizedHeaders')\n\nexport const RAW_HEADER_NAMES: unique symbol = Symbol('rawHeaderNames')\n\nconst HEADER_VALUE_DELIMITER = ', ' as const\n\nexport class Headers {\n // Normalized header {\"name\":\"a, b\"} storage.\n private [NORMALIZED_HEADERS]: Record<string, string> = {}\n\n // Keeps the mapping between the raw header name\n // and the normalized header name to ease the lookup.\n private [RAW_HEADER_NAMES]: Map<string, string> = new Map()\n\n constructor(init?: HeadersInit | HeadersObject | HeadersList) {\n /**\n * @note Cannot necessarily check if the `init` is an instance of the\n * `Headers` because that class may not be defined in Node or jsdom.\n */\n if (\n ['Headers', 'HeadersPolyfill'].includes(init?.constructor?.name) ||\n init instanceof Headers ||\n (typeof globalThis.Headers !== 'undefined' &&\n init instanceof globalThis.Headers)\n ) {\n const initialHeaders = init as Headers\n initialHeaders.forEach((value, name) => {\n this.append(name, value)\n }, this)\n } else if (Array.isArray(init)) {\n init.forEach(([name, value]) => {\n this.append(\n name,\n Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value\n )\n })\n } else if (init) {\n Object.getOwnPropertyNames(init).forEach((name) => {\n const value = init[name]\n this.append(\n name,\n Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value\n )\n })\n }\n }\n\n [Symbol.toStringTag] = 'Headers';\n\n [Symbol.iterator]() {\n return this.entries()\n }\n\n *keys(): Generator<string> {\n for (const [name] of this.entries()) {\n yield name\n }\n }\n\n *values(): Generator<string> {\n for (const [, value] of this.entries()) {\n yield value\n }\n }\n\n *entries(): Generator<[string, string]> {\n // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine\n let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort((a, b) =>\n a.localeCompare(b)\n )\n for (const name of sortedKeys) {\n if (name === 'set-cookie') {\n for (const value of this.getSetCookie()) {\n yield [name, value]\n }\n } else {\n yield [name, this.get(name)]\n }\n }\n }\n\n /**\n * Returns a boolean stating whether a `Headers` object contains a certain header.\n */\n has(name: string): boolean {\n if (!isValidHeaderName(name)) {\n throw new TypeError(`Invalid header name \"${name}\"`)\n }\n\n return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name))\n }\n\n /**\n * Returns a `ByteString` sequence of all the values of a header with a given name.\n */\n get(name: string): string | null {\n if (!isValidHeaderName(name)) {\n throw TypeError(`Invalid header name \"${name}\"`)\n }\n\n return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null\n }\n\n /**\n * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.\n */\n set(name: string, value: string): void {\n if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n const normalizedValue = normalizeHeaderValue(value)\n\n this[NORMALIZED_HEADERS][normalizedName] =\n normalizeHeaderValue(normalizedValue)\n this[RAW_HEADER_NAMES].set(normalizedName, name)\n }\n\n /**\n * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.\n */\n append(name: string, value: string): void {\n if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n const normalizedValue = normalizeHeaderValue(value)\n\n let resolvedValue = this.has(normalizedName)\n ? `${this.get(normalizedName)}, ${normalizedValue}`\n : normalizedValue\n\n this.set(name, resolvedValue)\n }\n\n /**\n * Deletes a header from the `Headers` object.\n */\n delete(name: string): void {\n if (!isValidHeaderName(name)) {\n return\n }\n\n if (!this.has(name)) {\n return\n }\n\n const normalizedName = normalizeHeaderName(name)\n delete this[NORMALIZED_HEADERS][normalizedName]\n this[RAW_HEADER_NAMES].delete(normalizedName)\n }\n\n /**\n * Traverses the `Headers` object,\n * calling the given callback for each header.\n */\n forEach<ThisArg = this>(\n callback: (\n this: ThisArg,\n value: string,\n name: string,\n parent: this\n ) => void,\n thisArg?: ThisArg\n ) {\n for (const [name, value] of this.entries()) {\n callback.call(thisArg, value, name, this)\n }\n }\n\n /**\n * Returns an array containing the values\n * of all Set-Cookie headers associated\n * with a response\n */\n getSetCookie(): string[] {\n const setCookieHeader = this.get('set-cookie')\n\n if (setCookieHeader === null) {\n return []\n }\n\n if (setCookieHeader === '') {\n return ['']\n }\n\n return splitCookiesString(setCookieHeader)\n }\n}\n","import { RAW_HEADER_NAMES } from './Headers'\n\n/**\n * Returns the object of all raw headers.\n */\nexport function getRawHeaders(headers: Headers) {\n const rawHeaders: Record<string, string> = {}\n\n for (const [name, value] of headers.entries()) {\n rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value\n }\n\n return rawHeaders\n}\n","import { HeadersList } from '../glossary'\n\nexport function headersToList(headers: Headers): HeadersList {\n const headersList: HeadersList = []\n\n headers.forEach((value, name) => {\n const resolvedValue = value.includes(',')\n ? value.split(',').map((value) => value.trim())\n : value\n\n headersList.push([name, resolvedValue])\n })\n\n return headersList\n}\n","import { headersToList } from './headersToList'\n\n/**\n * Converts a given `Headers` instance to its string representation.\n */\nexport function headersToString(headers: Headers): string {\n const list = headersToList(headers)\n const lines = list.map(([name, value]) => {\n const values = ([] as string[]).concat(value)\n return `${name}: ${values.join(', ')}`\n })\n\n return lines.join('\\r\\n')\n}\n","import { HeadersObject } from '../glossary'\n\n// List of headers that cannot have multiple values,\n// while potentially having a comma in their single value.\nconst singleValueHeaders = ['user-agent']\n\n/**\n * Converts a given `Headers` instance into a plain object.\n * Respects headers with multiple values.\n */\nexport function headersToObject(headers: Headers): HeadersObject {\n const headersObject: HeadersObject = {}\n\n headers.forEach((value, name) => {\n const isMultiValue =\n !singleValueHeaders.includes(name.toLowerCase()) && value.includes(',')\n headersObject[name] = isMultiValue\n ? value.split(',').map((s) => s.trim())\n : value\n })\n\n return headersObject\n}\n","import { Headers } from '../Headers'\n\n/**\n * Converts a string representation of headers (i.e. from XMLHttpRequest)\n * to a new `Headers` instance.\n */\nexport function stringToHeaders(str: string): Headers {\n const lines = str.trim().split(/[\\r\\n]+/)\n\n return lines.reduce((headers, line) => {\n if (line.trim() === '') {\n return headers\n }\n\n const parts = line.split(': ')\n const name = parts.shift()\n const value = parts.join(': ')\n headers.append(name, value)\n\n return headers\n }, new Headers())\n}\n","import { Headers } from '../Headers'\nimport { HeadersList } from '../glossary'\n\nexport function listToHeaders(list: HeadersList): Headers {\n const headers = new Headers()\n\n list.forEach(([name, value]) => {\n const values = ([] as string[]).concat(value)\n\n values.forEach((value) => {\n headers.append(name, value)\n })\n })\n\n return headers\n}\n","import { HeadersObject } from '../glossary'\n\n/**\n * Reduces given headers object instnace.\n */\nexport function reduceHeadersObject<R>(\n headers: HeadersObject,\n reducer: (headers: R, name: string, value: string | string[]) => R,\n initialState: R\n): R {\n return Object.keys(headers).reduce<R>((nextHeaders, name) => {\n return reducer(nextHeaders, name, headers[name])\n }, initialState)\n}\n","import { Headers } from '../Headers'\nimport { reduceHeadersObject } from './reduceHeadersObject'\n\n/**\n * Converts a given headers object to a new `Headers` instance.\n */\nexport function objectToHeaders(\n headersObject: Record<string, string | string[] | undefined>\n): Headers {\n return reduceHeadersObject(\n headersObject,\n (headers, name, value) => {\n const values = ([] as string[]).concat(value).filter(Boolean)\n\n values.forEach((value) => {\n headers.append(name, value)\n })\n\n return headers\n },\n new Headers()\n )\n}\n","import { HeadersList, FlatHeadersList } from '../glossary'\n\nexport function flattenHeadersList(list: HeadersList): FlatHeadersList {\n return list.map(([name, values]) => {\n return [name, ([] as string[]).concat(values).join(', ')]\n })\n}\n","import { HeadersObject, FlatHeadersObject } from '../glossary'\nimport { reduceHeadersObject } from './reduceHeadersObject'\n\nexport function flattenHeadersObject(\n headersObject: HeadersObject\n): FlatHeadersObject {\n return reduceHeadersObject<FlatHeadersObject>(\n headersObject,\n (headers, name, value) => {\n headers[name] = ([] as string[]).concat(value).join(', ')\n return headers\n },\n {}\n )\n}\n"],"mappings":"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"}
node_modules/headers-polyfill/package.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "module",
3
+ "name": "headers-polyfill",
4
+ "version": "5.0.1",
5
+ "description": "A native \"Headers\" class polyfill.",
6
+ "main": "./lib/index.cjs",
7
+ "module": "./lib/index.mjs",
8
+ "exports": {
9
+ ".": {
10
+ "require": {
11
+ "types": "./lib/index.d.cts",
12
+ "default": "./lib/index.cjs"
13
+ },
14
+ "default": {
15
+ "types": "./lib/index.d.mts",
16
+ "default": "./lib/index.mjs"
17
+ }
18
+ }
19
+ },
20
+ "repository": {
21
+ "type": "http",
22
+ "url": "https://github.com/mswjs/headers-polyfill"
23
+ },
24
+ "author": "Artem Zakharchenko",
25
+ "license": "MIT",
26
+ "files": [
27
+ "./lib",
28
+ "./src",
29
+ "README.md"
30
+ ],
31
+ "devDependencies": {
32
+ "@ossjs/release": "^0.10.1",
33
+ "jsdom": "^28.1.0",
34
+ "publint": "^0.3.18",
35
+ "tsdown": "^0.21.0",
36
+ "typescript": "^5.9.3",
37
+ "vitest": "^4.0.18"
38
+ },
39
+ "dependencies": {
40
+ "@types/set-cookie-parser": "^2.4.10",
41
+ "set-cookie-parser": "^3.0.1"
42
+ },
43
+ "scripts": {
44
+ "start": "tsdown --watch",
45
+ "build": "tsdown",
46
+ "test": "vitest",
47
+ "lint": "publint",
48
+ "release": "release publish"
49
+ }
50
+ }
node_modules/headers-polyfill/src/Headers.test.ts ADDED
@@ -0,0 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import { Headers } from './Headers'
5
+
6
+ describe('constructor()', () => {
7
+ it('can be created without any arguments', () => {
8
+ const headers = new Headers()
9
+ expect(Object.fromEntries(headers.entries())).toEqual({})
10
+ })
11
+
12
+ it('can be created given a Headers instance', () => {
13
+ const headers = new Headers(new window.Headers({ Accept: '*/*' }))
14
+ expect(Object.fromEntries(headers.entries())).toEqual({ accept: '*/*' })
15
+ })
16
+
17
+ it('can be created given a polyfilled Headers instance', () => {
18
+ const firstHeaders = new Headers({ Accept: '*/*' })
19
+ const headers = new Headers(firstHeaders)
20
+ expect(Object.fromEntries(headers.entries())).toEqual({ accept: '*/*' })
21
+ })
22
+
23
+ it('can be created given a ["name", "a"] list', () => {
24
+ const headers = new Headers([['accept', '*/*']])
25
+ expect(headers.get('accept')).toEqual('*/*')
26
+ })
27
+
28
+ it('can be created given a ["name", ["a", "b"]] list', () => {
29
+ const headers = new Headers([['accept', ['application/json', 'image/png']]])
30
+ expect(headers.get('accept')).toEqual('application/json, image/png')
31
+ })
32
+
33
+ it('can be created given a ["name", "a, b"] list', () => {
34
+ const headers = new Headers([['accept', 'application/json, image/png']])
35
+ expect(headers.get('accept')).toEqual('application/json, image/png')
36
+ })
37
+
38
+ it('can be created given an headers object', () => {
39
+ const headers = new Headers({ accept: '*/*' })
40
+ expect(headers.get('accept')).toEqual('*/*')
41
+ })
42
+
43
+ it('can be created given an object with a null prototype', () => {
44
+ const headersInit = Object.create(null)
45
+ headersInit.accept = '*/*'
46
+ const headers = new Headers(headersInit)
47
+ expect(headers.get('accept')).toEqual('*/*')
48
+ })
49
+
50
+ it('duplicates values for the same header names with different casing', () => {
51
+ const headers = new Headers({
52
+ 'accept-encoding': 'gzip, deflate, br',
53
+ 'Accept-Encoding': 'gzip, deflate, br',
54
+ })
55
+ expect(headers.get('accept-encoding')).toEqual(
56
+ 'gzip, deflate, br, gzip, deflate, br'
57
+ )
58
+ })
59
+ })
60
+
61
+ describe('[Symbol.iterator]', () => {
62
+ it('returns the iterator with the [name, value] pairs', () => {
63
+ const headers = new Headers({
64
+ accept: '*/*',
65
+ 'accept-language': 'en-US',
66
+ 'content-type': 'application/json',
67
+ })
68
+
69
+ const entries: Array<[string, string]> = []
70
+
71
+ for (const entry of headers) {
72
+ entries.push(entry)
73
+ }
74
+
75
+ expect(entries).toEqual([
76
+ ['accept', '*/*'],
77
+ ['accept-language', 'en-US'],
78
+ ['content-type', 'application/json'],
79
+ ])
80
+ })
81
+
82
+ it('returns an empty iterator when there is no headers', () => {
83
+ const headers = new Headers()
84
+ const entries: Array<[string, string]> = []
85
+
86
+ for (const entry of headers) {
87
+ entries.push(entry)
88
+ }
89
+
90
+ expect(entries).toEqual([])
91
+ })
92
+ })
93
+
94
+ describe('[Symbol.toStringTag]', () => {
95
+ it('returns "[object Headers]" when called', () => {
96
+ expect(new Headers().toString()).toEqual('[object Headers]')
97
+ })
98
+ })
99
+
100
+ describe('.keys()', () => {
101
+ it('returns the iterator with the header keys', () => {
102
+ const headers = new Headers({
103
+ accept: '*/*',
104
+ 'accept-language': 'en-US',
105
+ 'content-type': 'application/json',
106
+ })
107
+ const keys: Array<string> = []
108
+
109
+ for (const name of headers.keys()) {
110
+ keys.push(name)
111
+ }
112
+
113
+ expect(keys).toEqual(['accept', 'accept-language', 'content-type'])
114
+ })
115
+
116
+ it('returns an empty iterator when there is no headers', () => {
117
+ const headers = new Headers()
118
+ const keys: Array<string> = []
119
+
120
+ for (const name of headers.keys()) {
121
+ keys.push(name)
122
+ }
123
+
124
+ expect(keys).toEqual([])
125
+ })
126
+
127
+ it('sorts returned keys alphabetically', () => {
128
+ const headers = new Headers()
129
+ headers.set('X-B', '1')
130
+ headers.set('X-A', '2')
131
+ headers.set('X-C', '3')
132
+ expect(Array.from(headers.keys())).toEqual(['x-a', 'x-b', 'x-c'])
133
+ })
134
+
135
+ it('does not combine set-cookie headers', () => {
136
+ const headers = new Headers()
137
+ headers.append('Set-Cookie', 'a=1')
138
+ headers.append('Set-Cookie', 'b=2')
139
+ expect(Array.from(headers.keys())).toEqual(['set-cookie', 'set-cookie'])
140
+ })
141
+
142
+ if (process.version.startsWith('22.')) {
143
+ it('returns an iterator with [Symbol.dispose] defined', () => {
144
+ const headers = new Headers()
145
+ expect(headers.keys()[Symbol.dispose]).toBeInstanceOf(Function)
146
+ })
147
+ }
148
+ })
149
+
150
+ describe('.values()', () => {
151
+ it('returns the iterator with the header values', () => {
152
+ const headers = new Headers({
153
+ accept: '*/*',
154
+ 'accept-language': 'en-US',
155
+ 'content-type': 'application/json',
156
+ })
157
+ const values: Array<string> = []
158
+
159
+ for (const value of headers.values()) {
160
+ values.push(value)
161
+ }
162
+
163
+ expect(values).toEqual(['*/*', 'en-US', 'application/json'])
164
+ })
165
+
166
+ it('returns an empty iterator when there is no headers', () => {
167
+ const headers = new Headers()
168
+ const values: Array<string> = []
169
+
170
+ for (const value of headers.values()) {
171
+ values.push(value)
172
+ }
173
+
174
+ expect(values).toEqual([])
175
+ })
176
+
177
+ it('sorts returned values alphabetically', () => {
178
+ const headers = new Headers()
179
+ headers.set('X-B', '1')
180
+ headers.set('X-A', '2')
181
+ headers.set('X-C', '3')
182
+ expect(Array.from(headers.values())).toEqual(['2', '1', '3'])
183
+ })
184
+
185
+ it('does not combine set-cookie headers', () => {
186
+ const headers = new Headers()
187
+ headers.append('Set-Cookie', 'a=1')
188
+ headers.append('Set-Cookie', 'b=2')
189
+ expect(Array.from(headers.values())).toEqual(['a=1', 'b=2'])
190
+ })
191
+
192
+ if (process.version.startsWith('22.')) {
193
+ it('returns an iterator with [Symbol.dispose] defined', () => {
194
+ const headers = new Headers()
195
+ expect(headers.values()[Symbol.dispose]).toBeInstanceOf(Function)
196
+ })
197
+ }
198
+ })
199
+
200
+ describe('.entries()', () => {
201
+ it('returns the iterator with the [name, value] pairs', () => {
202
+ const headers = new Headers({
203
+ accept: '*/*',
204
+ 'accept-language': 'en-US',
205
+ 'content-type': 'application/json',
206
+ })
207
+ const entries: Array<[string, string]> = []
208
+
209
+ for (const entry of headers.entries()) {
210
+ entries.push(entry)
211
+ }
212
+
213
+ expect(entries).toEqual([
214
+ ['accept', '*/*'],
215
+ ['accept-language', 'en-US'],
216
+ ['content-type', 'application/json'],
217
+ ])
218
+ })
219
+
220
+ it('returns an empty iterator when there is no headers', () => {
221
+ const headers = new Headers()
222
+ const entries: Array<[string, string]> = []
223
+
224
+ for (const entry of headers.entries()) {
225
+ entries.push(entry)
226
+ }
227
+
228
+ expect(entries).toEqual([])
229
+ })
230
+
231
+ it('sorts alphabetically', () => {
232
+ const headers = new Headers()
233
+ headers.set('X-B', '1')
234
+ headers.set('X-A', '2')
235
+ headers.set('X-C', '3')
236
+ expect(Array.from(headers.entries())).toEqual([
237
+ ['x-a', '2'],
238
+ ['x-b', '1'],
239
+ ['x-c', '3'],
240
+ ])
241
+ })
242
+
243
+ it('does not combine set-cookie headers', () => {
244
+ const headers = new Headers()
245
+ headers.append('Set-Cookie', 'a=1')
246
+ headers.append('Set-Cookie', 'b=2')
247
+ expect(Array.from(headers.entries())).toEqual([
248
+ ['set-cookie', 'a=1'],
249
+ ['set-cookie', 'b=2'],
250
+ ])
251
+ })
252
+
253
+ if (process.version.startsWith('22.')) {
254
+ it('returns an iterator with [Symbol.dispose] defined', () => {
255
+ const headers = new Headers()
256
+ expect(headers.entries()[Symbol.dispose]).toBeInstanceOf(Function)
257
+ })
258
+ }
259
+ })
260
+
261
+ describe('.has()', () => {
262
+ it('throws a TypeError given an invalid header name', () => {
263
+ const headers = new Headers()
264
+ expect(() =>
265
+ headers.has(
266
+ // @ts-expect-error
267
+ 123
268
+ )
269
+ ).toThrow(new TypeError('Invalid header name "123"'))
270
+ })
271
+
272
+ it('returns true given an existing header name', () => {
273
+ const headers = new Headers({ accept: '*/*' })
274
+ expect(headers.has('accept')).toBe(true)
275
+ expect(headers.has('AcCePt')).toBe(true)
276
+ })
277
+
278
+ it('returns false given a non-existing header name', () => {
279
+ const headers = new Headers({ accept: '*/*' })
280
+ expect(headers.has('content-type')).toBe(false)
281
+ expect(headers.has('CoNtEnT-TyPe')).toBe(false)
282
+ })
283
+ })
284
+
285
+ describe('.get()', () => {
286
+ it('throws a TypeError given an invalid header name', () => {
287
+ const headers = new Headers()
288
+ expect(() =>
289
+ headers.get(
290
+ // @ts-expect-error
291
+ 123
292
+ )
293
+ ).toThrow(new TypeError('Invalid header name "123"'))
294
+ })
295
+
296
+ it('returns the value of the existing header name', () => {
297
+ const headers = new Headers({ 'Content-Type': 'text/plain' })
298
+ expect(headers.get('Content-Type')).toEqual('text/plain')
299
+ expect(headers.get('content-type')).toEqual('text/plain')
300
+ expect(headers.get('CoNtEnT-TyPe')).toEqual('text/plain')
301
+ })
302
+
303
+ it('returns null given a non-existing header name', () => {
304
+ const headers = new Headers({ 'Content-Type': 'text/plain' })
305
+ expect(headers.get('accept')).toBeNull()
306
+ expect(headers.get('Accept')).toBeNull()
307
+ expect(headers.get('AcCePt')).toBeNull()
308
+ })
309
+
310
+ it('return an empty string for an empty header value', () => {
311
+ const headers = new Headers({ 'Content-Type': '' })
312
+ expect(headers.get('Content-Type')).toEqual('')
313
+ })
314
+ })
315
+
316
+ describe('.set()', () => {
317
+ it('returns if given an invalid header name', () => {
318
+ const headers = new Headers()
319
+ expect(
320
+ headers.set(
321
+ // @ts-expect-error
322
+ 123,
323
+ 'value'
324
+ )
325
+ ).toBeUndefined()
326
+ expect(Object.fromEntries(headers.entries())).toEqual({})
327
+ })
328
+
329
+ it('returns if given an invalid header value', () => {
330
+ const headers = new Headers()
331
+ expect(
332
+ headers.set(
333
+ 'foo',
334
+ // @ts-expect-error
335
+ 123
336
+ )
337
+ ).toBeUndefined()
338
+ expect(headers.set('foo', ' value ')).toBeUndefined()
339
+ expect(Object.fromEntries(headers.entries())).toEqual({})
340
+ })
341
+
342
+ it('sets a new header', () => {
343
+ const headers = new Headers({ accept: '*/*' })
344
+
345
+ headers.set('content-type', 'application/json')
346
+ expect(headers.get('accept')).toEqual('*/*')
347
+ expect(headers.get('content-type')).toEqual('application/json')
348
+ })
349
+
350
+ it('overrides an existing header with the same name', () => {
351
+ const headers = new Headers({ accept: '*/*' })
352
+
353
+ headers.set('accept', 'image/png')
354
+ expect(headers.get('accept')).toEqual('image/png')
355
+
356
+ headers.set('AcCePt', 'text/plain')
357
+ expect(headers.get('accept')).toEqual('text/plain')
358
+ })
359
+ })
360
+
361
+ describe('.append()', () => {
362
+ it('appends a new header', () => {
363
+ const headers = new Headers({ accept: '*/*' })
364
+
365
+ headers.append('content-type', 'application/json')
366
+ expect(headers.get('accept')).toEqual('*/*')
367
+ expect(headers.get('content-type')).toEqual('application/json')
368
+ })
369
+
370
+ it('joins the values with the existing header', () => {
371
+ const headers = new Headers({ accept: '*/*' })
372
+
373
+ headers.append('accept', 'image/png')
374
+ expect(headers.get('accept')).toEqual('*/*, image/png')
375
+ })
376
+
377
+ it('duplicates values with the existing header', () => {
378
+ const headers = new Headers({ accept: '*/*' })
379
+
380
+ headers.append('Accept', '*/*')
381
+ expect(headers.get('accept')).toEqual('*/*, */*')
382
+ })
383
+ })
384
+
385
+ describe('.delete()', () => {
386
+ it('returns if given an invalid header name', () => {
387
+ const headers = new Headers({ accept: '*/*' })
388
+ expect(
389
+ headers.delete(
390
+ // @ts-expect-error
391
+ 123
392
+ )
393
+ ).toBeUndefined()
394
+ expect(Object.fromEntries(headers.entries())).toEqual({
395
+ accept: '*/*',
396
+ })
397
+ })
398
+
399
+ it('deletes the existing header', () => {
400
+ const headers = new Headers({ accept: '*/*' })
401
+
402
+ headers.delete('accept')
403
+ expect(headers.has('accept')).toBe(false)
404
+ expect(headers.has('AcCePt')).toBe(false)
405
+ expect(headers.get('accept')).toBeNull()
406
+ expect(headers.get('AcCePt')).toBeNull()
407
+ })
408
+
409
+ it('does nothing given a non-existing header', () => {
410
+ const headers = new Headers({ accept: '*/*' })
411
+
412
+ headers.delete('content-type')
413
+ expect(headers.get('accept')).toEqual('*/*')
414
+ expect(headers.get('AcCePt')).toEqual('*/*')
415
+ })
416
+ })
417
+
418
+ describe('.forEach()', () => {
419
+ it('traverses each header once', () => {
420
+ const headers = new Headers({ accept: '*/*', 'user-agent': 'agent' })
421
+ const headerSet = new Set()
422
+
423
+ headers.forEach((value, name, headers) => {
424
+ expect(value).toBe(headers.get(name))
425
+ expect(headerSet.has(name)).toBe(false)
426
+ headerSet.add(name)
427
+ })
428
+
429
+ // `Headers.forEach` returns normalized lowercase names.
430
+ expect(headerSet).toEqual(new Set(['accept', 'user-agent']))
431
+ })
432
+
433
+ it('traverses each header once with a custom "this" argument', () => {
434
+ const headers = new Headers({ accept: '*/*', 'User-Agent': 'agent' })
435
+ const headerSet = new Set()
436
+
437
+ headers.forEach(function (value, name, headers) {
438
+ expect(value).toBe(headers.get(name))
439
+ expect(this.has(name)).toBe(false)
440
+ this.add(name)
441
+ }, headerSet)
442
+
443
+ expect(headerSet).toEqual(new Set(['accept', 'user-agent']))
444
+ })
445
+ })
446
+
447
+ describe('.getSetCookie()', () => {
448
+ it('returns an empty array given no Set-Cookie headers', () => {
449
+ const headers = new Headers()
450
+ expect(headers.getSetCookie()).toEqual([])
451
+ })
452
+
453
+ it('returns empty string if Set-Cookie header was set to empty string', () => {
454
+ const headers = new Headers({ 'Set-Cookie': '' })
455
+ expect(headers.getSetCookie()).toEqual([''])
456
+ })
457
+
458
+ it('returns a list of a single existing Set-Cookie header', () => {
459
+ const headers = new Headers({
460
+ 'Set-Cookie': 'name=cookie; Expires=Wed, 21 Oct 2015 07:28:00 GMT',
461
+ })
462
+ expect(headers.getSetCookie()).toEqual([
463
+ 'name=cookie; Expires=Wed, 21 Oct 2015 07:28:00 GMT',
464
+ ])
465
+ })
466
+
467
+ it('returns a list of all existing Set-Cookie headers', () => {
468
+ const headers = new Headers()
469
+ headers.append(
470
+ 'Set-Cookie',
471
+ 'name=cookie; Expires=Wed, 21 Oct 2015 07:28:00 GMT'
472
+ )
473
+ headers.append(
474
+ 'Set-Cookie',
475
+ 'name=session; Expires=Wed, 21 Oct 2015 07:28:00 GMT'
476
+ )
477
+
478
+ expect(headers.getSetCookie()).toEqual([
479
+ 'name=cookie; Expires=Wed, 21 Oct 2015 07:28:00 GMT',
480
+ 'name=session; Expires=Wed, 21 Oct 2015 07:28:00 GMT',
481
+ ])
482
+ })
483
+ })
node_modules/headers-polyfill/src/Headers.ts ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { splitCookiesString } from 'set-cookie-parser'
2
+ import { HeadersList, HeadersObject } from './glossary'
3
+ import { normalizeHeaderName } from './utils/normalizeHeaderName'
4
+ import { normalizeHeaderValue } from './utils/normalizeHeaderValue'
5
+ import { isValidHeaderName } from './utils/isValidHeaderName'
6
+ import { isValidHeaderValue } from './utils/isValidHeaderValue'
7
+
8
+ export const NORMALIZED_HEADERS: unique symbol = Symbol('normalizedHeaders')
9
+
10
+ export const RAW_HEADER_NAMES: unique symbol = Symbol('rawHeaderNames')
11
+
12
+ const HEADER_VALUE_DELIMITER = ', ' as const
13
+
14
+ export class Headers {
15
+ // Normalized header {"name":"a, b"} storage.
16
+ private [NORMALIZED_HEADERS]: Record<string, string> = {}
17
+
18
+ // Keeps the mapping between the raw header name
19
+ // and the normalized header name to ease the lookup.
20
+ private [RAW_HEADER_NAMES]: Map<string, string> = new Map()
21
+
22
+ constructor(init?: HeadersInit | HeadersObject | HeadersList) {
23
+ /**
24
+ * @note Cannot necessarily check if the `init` is an instance of the
25
+ * `Headers` because that class may not be defined in Node or jsdom.
26
+ */
27
+ if (
28
+ ['Headers', 'HeadersPolyfill'].includes(init?.constructor?.name) ||
29
+ init instanceof Headers ||
30
+ (typeof globalThis.Headers !== 'undefined' &&
31
+ init instanceof globalThis.Headers)
32
+ ) {
33
+ const initialHeaders = init as Headers
34
+ initialHeaders.forEach((value, name) => {
35
+ this.append(name, value)
36
+ }, this)
37
+ } else if (Array.isArray(init)) {
38
+ init.forEach(([name, value]) => {
39
+ this.append(
40
+ name,
41
+ Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
42
+ )
43
+ })
44
+ } else if (init) {
45
+ Object.getOwnPropertyNames(init).forEach((name) => {
46
+ const value = init[name]
47
+ this.append(
48
+ name,
49
+ Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
50
+ )
51
+ })
52
+ }
53
+ }
54
+
55
+ [Symbol.toStringTag] = 'Headers';
56
+
57
+ [Symbol.iterator]() {
58
+ return this.entries()
59
+ }
60
+
61
+ *keys(): Generator<string> {
62
+ for (const [name] of this.entries()) {
63
+ yield name
64
+ }
65
+ }
66
+
67
+ *values(): Generator<string> {
68
+ for (const [, value] of this.entries()) {
69
+ yield value
70
+ }
71
+ }
72
+
73
+ *entries(): Generator<[string, string]> {
74
+ // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine
75
+ let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort((a, b) =>
76
+ a.localeCompare(b)
77
+ )
78
+ for (const name of sortedKeys) {
79
+ if (name === 'set-cookie') {
80
+ for (const value of this.getSetCookie()) {
81
+ yield [name, value]
82
+ }
83
+ } else {
84
+ yield [name, this.get(name)]
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
91
+ */
92
+ has(name: string): boolean {
93
+ if (!isValidHeaderName(name)) {
94
+ throw new TypeError(`Invalid header name "${name}"`)
95
+ }
96
+
97
+ return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name))
98
+ }
99
+
100
+ /**
101
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
102
+ */
103
+ get(name: string): string | null {
104
+ if (!isValidHeaderName(name)) {
105
+ throw TypeError(`Invalid header name "${name}"`)
106
+ }
107
+
108
+ return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null
109
+ }
110
+
111
+ /**
112
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
113
+ */
114
+ set(name: string, value: string): void {
115
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
116
+ return
117
+ }
118
+
119
+ const normalizedName = normalizeHeaderName(name)
120
+ const normalizedValue = normalizeHeaderValue(value)
121
+
122
+ this[NORMALIZED_HEADERS][normalizedName] =
123
+ normalizeHeaderValue(normalizedValue)
124
+ this[RAW_HEADER_NAMES].set(normalizedName, name)
125
+ }
126
+
127
+ /**
128
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
129
+ */
130
+ append(name: string, value: string): void {
131
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
132
+ return
133
+ }
134
+
135
+ const normalizedName = normalizeHeaderName(name)
136
+ const normalizedValue = normalizeHeaderValue(value)
137
+
138
+ let resolvedValue = this.has(normalizedName)
139
+ ? `${this.get(normalizedName)}, ${normalizedValue}`
140
+ : normalizedValue
141
+
142
+ this.set(name, resolvedValue)
143
+ }
144
+
145
+ /**
146
+ * Deletes a header from the `Headers` object.
147
+ */
148
+ delete(name: string): void {
149
+ if (!isValidHeaderName(name)) {
150
+ return
151
+ }
152
+
153
+ if (!this.has(name)) {
154
+ return
155
+ }
156
+
157
+ const normalizedName = normalizeHeaderName(name)
158
+ delete this[NORMALIZED_HEADERS][normalizedName]
159
+ this[RAW_HEADER_NAMES].delete(normalizedName)
160
+ }
161
+
162
+ /**
163
+ * Traverses the `Headers` object,
164
+ * calling the given callback for each header.
165
+ */
166
+ forEach<ThisArg = this>(
167
+ callback: (
168
+ this: ThisArg,
169
+ value: string,
170
+ name: string,
171
+ parent: this
172
+ ) => void,
173
+ thisArg?: ThisArg
174
+ ) {
175
+ for (const [name, value] of this.entries()) {
176
+ callback.call(thisArg, value, name, this)
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Returns an array containing the values
182
+ * of all Set-Cookie headers associated
183
+ * with a response
184
+ */
185
+ getSetCookie(): string[] {
186
+ const setCookieHeader = this.get('set-cookie')
187
+
188
+ if (setCookieHeader === null) {
189
+ return []
190
+ }
191
+
192
+ if (setCookieHeader === '') {
193
+ return ['']
194
+ }
195
+
196
+ return splitCookiesString(setCookieHeader)
197
+ }
198
+ }
node_modules/headers-polyfill/src/getRawHeaders.test.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Headers } from './Headers'
2
+ import { getRawHeaders } from './getRawHeaders'
3
+
4
+ it('returns a headers objects with the raw names', () => {
5
+ const headers = new Headers({
6
+ Accept: '*/*',
7
+ 'ConTent-Type': ['application/json', 'text/plain'],
8
+ })
9
+ expect(getRawHeaders(headers)).toEqual({
10
+ Accept: '*/*',
11
+ 'ConTent-Type': 'application/json, text/plain',
12
+ })
13
+ })
14
+
15
+ it('returns an empty object when there is no headers', () => {
16
+ expect(getRawHeaders(new Headers())).toEqual({})
17
+ expect(getRawHeaders(new Headers({}))).toEqual({})
18
+ expect(getRawHeaders(new Headers([]))).toEqual({})
19
+ })
node_modules/headers-polyfill/src/getRawHeaders.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { RAW_HEADER_NAMES } from './Headers'
2
+
3
+ /**
4
+ * Returns the object of all raw headers.
5
+ */
6
+ export function getRawHeaders(headers: Headers) {
7
+ const rawHeaders: Record<string, string> = {}
8
+
9
+ for (const [name, value] of headers.entries()) {
10
+ rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value
11
+ }
12
+
13
+ return rawHeaders
14
+ }
node_modules/headers-polyfill/src/glossary.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ export type HeadersList = Array<[string, string | string[]]>
2
+ export type FlatHeadersList = [string, string][]
3
+ export type HeadersObject = Record<string, string | string[]>
4
+ export type FlatHeadersObject = Record<string, string>
node_modules/headers-polyfill/src/index.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export { Headers } from './Headers'
2
+
3
+ export { getRawHeaders } from './getRawHeaders'
4
+ export { headersToString } from './transformers/headersToString'
5
+ export { headersToList } from './transformers/headersToList'
6
+ export { headersToObject } from './transformers/headersToObject'
7
+ export { stringToHeaders } from './transformers/stringToHeaders'
8
+ export { listToHeaders } from './transformers/listToHeaders'
9
+ export { objectToHeaders } from './transformers/objectToHeaders'
10
+
11
+ export { reduceHeadersObject } from './transformers/reduceHeadersObject'
12
+ export { flattenHeadersList } from './transformers/flattenHeadersList'
13
+ export { flattenHeadersObject } from './transformers/flattenHeadersObject'
14
+
15
+ /* Typings */
16
+ export type {
17
+ HeadersList,
18
+ FlatHeadersList,
19
+ HeadersObject,
20
+ FlatHeadersObject,
21
+ } from './glossary'
node_modules/headers-polyfill/src/transformers/appendHeader.test.ts ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { appendHeader } from './appendHeader'
2
+
3
+ describe('appendHeader', () => {
4
+ describe('given appending a non-existing header', () => {
5
+ describe('with a single new value', () => {
6
+ it('should create it and assign the value', () => {
7
+ const headers = appendHeader({}, 'content-type', 'application/json')
8
+ expect(headers).toHaveProperty('content-type', 'application/json')
9
+ })
10
+ })
11
+
12
+ describe('with multiple new values', () => {
13
+ it('should create a list of values', () => {
14
+ const headers = appendHeader({}, 'accept', [
15
+ 'application/json',
16
+ 'text/plain',
17
+ ])
18
+ expect(headers).toHaveProperty('accept', [
19
+ 'application/json',
20
+ 'text/plain',
21
+ ])
22
+ })
23
+ })
24
+ })
25
+
26
+ describe('given appending to an existing header', () => {
27
+ describe('with a single new value', () => {
28
+ it('should append a single value to existing values', () => {
29
+ const headers = appendHeader(
30
+ {
31
+ 'content-type': 'application/json',
32
+ },
33
+ 'content-type',
34
+ 'image/png'
35
+ )
36
+
37
+ expect(headers).toHaveProperty('content-type', [
38
+ 'application/json',
39
+ 'image/png',
40
+ ])
41
+ })
42
+ })
43
+
44
+ describe('with multiple new values', () => {
45
+ it('should merge multiple values with existing values', () => {
46
+ const headers = appendHeader(
47
+ {
48
+ 'content-type': 'application/json',
49
+ },
50
+ 'content-type',
51
+ ['image/png', 'text/plain']
52
+ )
53
+
54
+ expect(headers).toHaveProperty('content-type', [
55
+ 'application/json',
56
+ 'image/png',
57
+ 'text/plain',
58
+ ])
59
+ })
60
+ })
61
+ })
62
+ })
node_modules/headers-polyfill/src/transformers/appendHeader.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HeadersObject } from '../glossary'
2
+
3
+ /**
4
+ * Appends a given header to the headers object.
5
+ * Converts multiple values into a list.
6
+ */
7
+ export function appendHeader(
8
+ headers: HeadersObject,
9
+ name: string,
10
+ value: string | string[]
11
+ ): HeadersObject {
12
+ if (headers.hasOwnProperty(name)) {
13
+ return Object.assign({}, headers, {
14
+ [name]: ([] as string[]).concat(headers[name]).concat(value),
15
+ })
16
+ }
17
+
18
+ return Object.assign({}, headers, {
19
+ [name]: value,
20
+ })
21
+ }
node_modules/headers-polyfill/src/transformers/flattenHeadersList.test.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HeadersList } from '../glossary'
2
+ import { flattenHeadersList } from './flattenHeadersList'
3
+
4
+ describe('given a headers list', () => {
5
+ it('flattens its multi-value headers', () => {
6
+ const headersList: HeadersList = [
7
+ ['accept', ['application/json', 'text/xml']],
8
+ ['content-type', 'application/pdf'],
9
+ ]
10
+
11
+ expect(flattenHeadersList(headersList)).toEqual([
12
+ ['accept', 'application/json, text/xml'],
13
+ ['content-type', 'application/pdf'],
14
+ ])
15
+ })
16
+ })
node_modules/headers-polyfill/src/transformers/flattenHeadersList.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import { HeadersList, FlatHeadersList } from '../glossary'
2
+
3
+ export function flattenHeadersList(list: HeadersList): FlatHeadersList {
4
+ return list.map(([name, values]) => {
5
+ return [name, ([] as string[]).concat(values).join(', ')]
6
+ })
7
+ }
node_modules/headers-polyfill/src/transformers/flattenHeadersObject.test.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { flattenHeadersObject } from './flattenHeadersObject'
2
+ import { HeadersObject } from '../glossary'
3
+
4
+ describe('given a headers object', () => {
5
+ it('flattens its multi-value headers', () => {
6
+ const headersObject: HeadersObject = {
7
+ Accept: ['application/json', 'text/xml'],
8
+ 'Content-Type': 'application/pdf',
9
+ }
10
+
11
+ expect(flattenHeadersObject(headersObject)).toEqual({
12
+ Accept: 'application/json, text/xml',
13
+ 'Content-Type': 'application/pdf',
14
+ })
15
+ })
16
+ })
node_modules/headers-polyfill/src/transformers/flattenHeadersObject.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HeadersObject, FlatHeadersObject } from '../glossary'
2
+ import { reduceHeadersObject } from './reduceHeadersObject'
3
+
4
+ export function flattenHeadersObject(
5
+ headersObject: HeadersObject
6
+ ): FlatHeadersObject {
7
+ return reduceHeadersObject<FlatHeadersObject>(
8
+ headersObject,
9
+ (headers, name, value) => {
10
+ headers[name] = ([] as string[]).concat(value).join(', ')
11
+ return headers
12
+ },
13
+ {}
14
+ )
15
+ }
node_modules/headers-polyfill/src/transformers/headersToList.node.test.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { Headers } from '../Headers'
5
+ import { headersToList } from './headersToList'
6
+
7
+ describe('given Headers with a single header', () => {
8
+ it('should return its list representation', () => {
9
+ const headers = new Headers({ Accept: 'application/json' })
10
+ expect(headersToList(headers)).toEqual([['accept', 'application/json']])
11
+ })
12
+ })
13
+
14
+ describe('given Headers with a single header and multiple values', () => {
15
+ it('should return those values in a nested list', () => {
16
+ const headers = new Headers({ Accept: 'application/json' })
17
+ headers.append('Accept', 'text/plain')
18
+
19
+ expect(headersToList(headers)).toEqual([
20
+ ['accept', ['application/json', 'text/plain']],
21
+ ])
22
+ })
23
+ })
24
+
25
+ describe('given Headers with various headers', () => {
26
+ it('should return their list representation', () => {
27
+ const headers = new Headers({
28
+ Accept: 'application/json',
29
+ 'Content-Length': '1234',
30
+ 'Content-Type': 'text/xml',
31
+ })
32
+ headers.append('Accept', 'text/plain')
33
+
34
+ expect(headersToList(headers)).toEqual([
35
+ ['accept', ['application/json', 'text/plain']],
36
+ ['content-length', '1234'],
37
+ ['content-type', 'text/xml'],
38
+ ])
39
+ })
40
+ })
node_modules/headers-polyfill/src/transformers/headersToList.test.ts ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import { headersToList } from './headersToList'
5
+
6
+ describe('given Headers with a single header', () => {
7
+ it('should return its list representation', () => {
8
+ const headers = new Headers({ Accept: 'application/json' })
9
+ expect(headersToList(headers)).toEqual([['accept', 'application/json']])
10
+ })
11
+ })
12
+
13
+ describe('given Headers with a single header and multiple values', () => {
14
+ it('should return those values in a nested list', () => {
15
+ const headers = new Headers({ Accept: 'application/json' })
16
+ headers.append('Accept', 'text/plain')
17
+
18
+ expect(headersToList(headers)).toEqual([
19
+ ['accept', ['application/json', 'text/plain']],
20
+ ])
21
+ })
22
+ })
23
+
24
+ describe('given Headers with various headers', () => {
25
+ it('should return their list representation', () => {
26
+ const headers = new Headers({
27
+ Accept: 'application/json',
28
+ 'Content-Length': '1234',
29
+ 'Content-Type': 'text/xml',
30
+ })
31
+ headers.append('Accept', 'text/plain')
32
+
33
+ expect(headersToList(headers)).toEqual([
34
+ ['accept', ['application/json', 'text/plain']],
35
+ ['content-length', '1234'],
36
+ ['content-type', 'text/xml'],
37
+ ])
38
+ })
39
+ })
node_modules/headers-polyfill/src/transformers/headersToList.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HeadersList } from '../glossary'
2
+
3
+ export function headersToList(headers: Headers): HeadersList {
4
+ const headersList: HeadersList = []
5
+
6
+ headers.forEach((value, name) => {
7
+ const resolvedValue = value.includes(',')
8
+ ? value.split(',').map((value) => value.trim())
9
+ : value
10
+
11
+ headersList.push([name, resolvedValue])
12
+ })
13
+
14
+ return headersList
15
+ }
node_modules/headers-polyfill/src/transformers/headersToObject.node.test.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { headersToObject } from './headersToObject'
5
+ import { Headers } from '../Headers'
6
+
7
+ describe('given Headers with a single header', () => {
8
+ it('should return that single header in an Object', () => {
9
+ const headers = new Headers({ 'Content-Type': 'application/json' })
10
+ expect(headersToObject(headers)).toEqual({
11
+ 'content-type': 'application/json',
12
+ })
13
+ })
14
+ })
15
+
16
+ describe('given Headers with a single header and multiple values', () => {
17
+ it('should put that header values into an array', () => {
18
+ const headers = new Headers({ Accept: 'application/json' })
19
+ headers.append('Accept', 'text/plain')
20
+
21
+ expect(headersToObject(headers)).toEqual({
22
+ accept: ['application/json', 'text/plain'],
23
+ })
24
+ })
25
+ })
26
+
27
+ describe('given Headers with multiple different headers', () => {
28
+ it('should return an object representing those headers', () => {
29
+ const headers = new Headers({
30
+ Accept: 'application/json',
31
+ 'Content-Length': '1234',
32
+ 'Content-Type': 'application/json',
33
+ })
34
+ headers.append('Accept', 'text/plain')
35
+
36
+ expect(headersToObject(headers)).toEqual({
37
+ accept: ['application/json', 'text/plain'],
38
+ 'content-length': '1234',
39
+ 'content-type': 'application/json',
40
+ })
41
+ })
42
+ })
43
+
44
+ describe('given Headers with a single header that includes a semicolon', () => {
45
+ it('should preserve a single header', () => {
46
+ const headers = new Headers({
47
+ 'user-agent':
48
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
49
+ })
50
+
51
+ expect(headersToObject(headers)).toEqual({
52
+ 'user-agent':
53
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
54
+ })
55
+ })
56
+ })
node_modules/headers-polyfill/src/transformers/headersToObject.test.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import { headersToObject } from './headersToObject'
5
+
6
+ describe('given Headers with a single header', () => {
7
+ it('should return that single header in an Object', () => {
8
+ const headers = new Headers({ 'Content-Type': 'application/json' })
9
+ expect(headersToObject(headers)).toEqual({
10
+ 'content-type': 'application/json',
11
+ })
12
+ })
13
+ })
14
+
15
+ describe('given Headers with a single header and multiple values', () => {
16
+ it('should put that header values into an array', () => {
17
+ const headers = new Headers({ Accept: 'application/json' })
18
+ headers.append('Accept', 'text/plain')
19
+
20
+ expect(headersToObject(headers)).toEqual({
21
+ accept: ['application/json', 'text/plain'],
22
+ })
23
+ })
24
+ })
25
+
26
+ describe('given Headers with multiple different headers', () => {
27
+ it('should return an object representing those headers', () => {
28
+ const headers = new Headers({
29
+ Accept: 'application/json',
30
+ 'Content-Length': '1234',
31
+ 'Content-Type': 'application/json',
32
+ })
33
+ headers.append('Accept', 'text/plain')
34
+
35
+ expect(headersToObject(headers)).toEqual({
36
+ accept: ['application/json', 'text/plain'],
37
+ 'content-length': '1234',
38
+ 'content-type': 'application/json',
39
+ })
40
+ })
41
+ })
42
+
43
+ describe('given Headers with a single header that includes a semicolon', () => {
44
+ it('should preserve a single header', () => {
45
+ const headers = new Headers({
46
+ 'user-agent':
47
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
48
+ })
49
+
50
+ expect(headersToObject(headers)).toEqual({
51
+ 'user-agent':
52
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
53
+ })
54
+ })
55
+ })
node_modules/headers-polyfill/src/transformers/headersToObject.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HeadersObject } from '../glossary'
2
+
3
+ // List of headers that cannot have multiple values,
4
+ // while potentially having a comma in their single value.
5
+ const singleValueHeaders = ['user-agent']
6
+
7
+ /**
8
+ * Converts a given `Headers` instance into a plain object.
9
+ * Respects headers with multiple values.
10
+ */
11
+ export function headersToObject(headers: Headers): HeadersObject {
12
+ const headersObject: HeadersObject = {}
13
+
14
+ headers.forEach((value, name) => {
15
+ const isMultiValue =
16
+ !singleValueHeaders.includes(name.toLowerCase()) && value.includes(',')
17
+ headersObject[name] = isMultiValue
18
+ ? value.split(',').map((s) => s.trim())
19
+ : value
20
+ })
21
+
22
+ return headersObject
23
+ }
node_modules/headers-polyfill/src/transformers/headersToString.test.ts ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import { headersToString } from './headersToString'
5
+ import { Headers } from '../Headers'
6
+
7
+ describe('headersToString', () => {
8
+ describe('given a standard Headers instance', () => {
9
+ it('returns its string representation', () => {
10
+ const headers = new Headers({
11
+ date: 'Fri, 08 Dec 2017 21:04:30 GMT',
12
+ 'content-encoding': 'gzip',
13
+ 'content-type': 'text/html; charset=utf-8',
14
+ connection: 'keep-alive',
15
+ 'content-length': '6502',
16
+ })
17
+
18
+ expect(headersToString(headers)).toEqual(
19
+ `
20
+ connection: keep-alive\r
21
+ content-encoding: gzip\r
22
+ content-length: 6502\r
23
+ content-type: text/html; charset=utf-8\r
24
+ date: Fri, 08 Dec 2017 21:04:30 GMT\r
25
+ `.trim()
26
+ )
27
+ })
28
+ })
29
+
30
+ describe('given a polyfill Headers instance', () => {
31
+ it('returns its string representation', () => {
32
+ const headers = new Headers({
33
+ date: 'Fri, 08 Dec 2017 21:04:30 GMT',
34
+ 'content-encoding': 'gzip',
35
+ 'content-type': 'text/html; charset=utf-8',
36
+ connection: 'keep-alive',
37
+ 'content-length': '6502',
38
+ })
39
+
40
+ expect(headersToString(headers)).toEqual(
41
+ `
42
+ connection: keep-alive\r
43
+ content-encoding: gzip\r
44
+ content-length: 6502\r
45
+ content-type: text/html; charset=utf-8\r
46
+ date: Fri, 08 Dec 2017 21:04:30 GMT\r
47
+ `.trim()
48
+ )
49
+ })
50
+ })
51
+ })
node_modules/headers-polyfill/src/transformers/headersToString.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { headersToList } from './headersToList'
2
+
3
+ /**
4
+ * Converts a given `Headers` instance to its string representation.
5
+ */
6
+ export function headersToString(headers: Headers): string {
7
+ const list = headersToList(headers)
8
+ const lines = list.map(([name, value]) => {
9
+ const values = ([] as string[]).concat(value)
10
+ return `${name}: ${values.join(', ')}`
11
+ })
12
+
13
+ return lines.join('\r\n')
14
+ }
node_modules/headers-polyfill/src/transformers/listToHeaders.test.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { listToHeaders } from './listToHeaders'
2
+ import { Headers } from '../Headers'
3
+ import { HeadersList } from '../glossary'
4
+
5
+ describe('given a list representation of headers', () => {
6
+ it('returns a Headers instance', () => {
7
+ const list: HeadersList = [
8
+ ['accept', ['application/json', 'text/plain']],
9
+ ['content-length', '1234'],
10
+ ['content-type', 'application/json'],
11
+ ]
12
+
13
+ const headers = listToHeaders(list)
14
+ expect(headers).toBeInstanceOf(Headers)
15
+ expect(headers.get('accept')).toEqual('application/json, text/plain')
16
+ expect(headers.get('content-length')).toEqual('1234')
17
+ expect(headers.get('content-type')).toEqual('application/json')
18
+ })
19
+ })
node_modules/headers-polyfill/src/transformers/listToHeaders.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Headers } from '../Headers'
2
+ import { HeadersList } from '../glossary'
3
+
4
+ export function listToHeaders(list: HeadersList): Headers {
5
+ const headers = new Headers()
6
+
7
+ list.forEach(([name, value]) => {
8
+ const values = ([] as string[]).concat(value)
9
+
10
+ values.forEach((value) => {
11
+ headers.append(name, value)
12
+ })
13
+ })
14
+
15
+ return headers
16
+ }
node_modules/headers-polyfill/src/transformers/objectToHeaders.test.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { objectToHeaders } from './objectToHeaders'
2
+ import { Headers } from '../Headers'
3
+ import { HeadersObject } from '../glossary'
4
+
5
+ describe('given an object representation of headers', () => {
6
+ it('returns a Headers instance', () => {
7
+ const headersObject: HeadersObject = {
8
+ Accept: ['application/json', 'text/plain'],
9
+ 'Content-Length': '1234',
10
+ 'Content-Type': 'text/xml',
11
+ 'X-Custom-Header': undefined,
12
+ }
13
+ const headers = objectToHeaders(headersObject)
14
+
15
+ expect(headers).toBeInstanceOf(Headers)
16
+ expect(headers.get('accept')).toEqual('application/json, text/plain')
17
+ expect(headers.get('content-length')).toEqual('1234')
18
+ expect(headers.get('content-type')).toEqual('text/xml')
19
+ expect(headers.get('x-custom-header')).toBeNull()
20
+ })
21
+ })