feedsmith 2.7.0 → 3.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +24 -24
  2. package/dist/common/parse.cjs +2 -2
  3. package/dist/common/parse.d.cts +5 -5
  4. package/dist/common/parse.d.ts +5 -5
  5. package/dist/common/parse.js +10 -10
  6. package/dist/common/types.d.cts +21 -9
  7. package/dist/common/types.d.ts +21 -9
  8. package/dist/common/utils.cjs +39 -34
  9. package/dist/common/utils.js +40 -35
  10. package/dist/feeds/atom/common/types.d.cts +50 -50
  11. package/dist/feeds/atom/common/types.d.ts +50 -50
  12. package/dist/feeds/atom/generate/index.d.cts +2 -2
  13. package/dist/feeds/atom/generate/index.d.ts +2 -2
  14. package/dist/feeds/atom/generate/utils.cjs +9 -9
  15. package/dist/feeds/atom/generate/utils.js +28 -28
  16. package/dist/feeds/atom/parse/index.d.cts +2 -2
  17. package/dist/feeds/atom/parse/index.d.ts +2 -2
  18. package/dist/feeds/atom/parse/utils.cjs +3 -11
  19. package/dist/feeds/atom/parse/utils.js +17 -25
  20. package/dist/feeds/json/common/types.d.cts +19 -19
  21. package/dist/feeds/json/common/types.d.ts +19 -19
  22. package/dist/feeds/json/generate/index.d.cts +2 -2
  23. package/dist/feeds/json/generate/index.d.ts +2 -2
  24. package/dist/feeds/json/parse/index.d.cts +2 -2
  25. package/dist/feeds/json/parse/index.d.ts +2 -2
  26. package/dist/feeds/rdf/common/types.d.cts +28 -28
  27. package/dist/feeds/rdf/common/types.d.ts +28 -28
  28. package/dist/feeds/rdf/parse/index.d.cts +2 -2
  29. package/dist/feeds/rdf/parse/index.d.ts +2 -2
  30. package/dist/feeds/rdf/parse/utils.cjs +2 -2
  31. package/dist/feeds/rdf/parse/utils.js +12 -12
  32. package/dist/feeds/rss/common/types.d.cts +68 -68
  33. package/dist/feeds/rss/common/types.d.ts +68 -68
  34. package/dist/feeds/rss/generate/index.d.cts +2 -2
  35. package/dist/feeds/rss/generate/index.d.ts +2 -2
  36. package/dist/feeds/rss/generate/utils.cjs +4 -4
  37. package/dist/feeds/rss/generate/utils.js +53 -53
  38. package/dist/feeds/rss/parse/index.d.cts +2 -2
  39. package/dist/feeds/rss/parse/index.d.ts +2 -2
  40. package/dist/feeds/rss/parse/utils.cjs +2 -2
  41. package/dist/feeds/rss/parse/utils.js +51 -51
  42. package/dist/namespaces/atom/common/types.d.cts +4 -3
  43. package/dist/namespaces/atom/common/types.d.ts +4 -3
  44. package/dist/namespaces/atom/generate/utils.cjs +4 -4
  45. package/dist/namespaces/atom/generate/utils.js +6 -6
  46. package/dist/namespaces/georss/common/types.d.cts +21 -19
  47. package/dist/namespaces/georss/common/types.d.ts +21 -19
  48. package/dist/namespaces/georss/generate/utils.cjs +2 -2
  49. package/dist/namespaces/georss/generate/utils.js +2 -2
  50. package/dist/namespaces/googleplay/common/types.d.cts +9 -7
  51. package/dist/namespaces/googleplay/common/types.d.ts +9 -7
  52. package/dist/namespaces/itunes/common/types.d.cts +9 -5
  53. package/dist/namespaces/itunes/common/types.d.ts +9 -5
  54. package/dist/namespaces/media/common/types.d.cts +86 -84
  55. package/dist/namespaces/media/common/types.d.ts +86 -84
  56. package/dist/namespaces/opensearch/common/types.d.cts +7 -5
  57. package/dist/namespaces/opensearch/common/types.d.ts +7 -5
  58. package/dist/namespaces/podcast/common/types.d.cts +144 -141
  59. package/dist/namespaces/podcast/common/types.d.ts +144 -141
  60. package/dist/namespaces/podcast/generate/utils.cjs +5 -2
  61. package/dist/namespaces/podcast/generate/utils.js +5 -2
  62. package/dist/namespaces/podcast/parse/utils.cjs +5 -2
  63. package/dist/namespaces/podcast/parse/utils.js +5 -2
  64. package/dist/namespaces/psc/common/types.d.cts +8 -6
  65. package/dist/namespaces/psc/common/types.d.ts +8 -6
  66. package/dist/namespaces/rawvoice/common/types.d.cts +24 -24
  67. package/dist/namespaces/rawvoice/common/types.d.ts +24 -24
  68. package/dist/namespaces/source/common/types.d.cts +20 -18
  69. package/dist/namespaces/source/common/types.d.ts +20 -18
  70. package/dist/namespaces/spotify/common/types.d.cts +22 -20
  71. package/dist/namespaces/spotify/common/types.d.ts +22 -20
  72. package/dist/namespaces/thr/common/types.d.cts +6 -6
  73. package/dist/namespaces/thr/common/types.d.ts +6 -6
  74. package/dist/opml/common/types.d.cts +11 -9
  75. package/dist/opml/common/types.d.ts +11 -9
  76. package/dist/opml/generate/index.d.cts +2 -2
  77. package/dist/opml/generate/index.d.ts +2 -2
  78. package/dist/opml/parse/index.d.cts +1 -2
  79. package/dist/opml/parse/index.d.ts +1 -2
  80. package/dist/types.d.cts +1 -2
  81. package/dist/types.d.ts +1 -2
  82. package/package.json +7 -9
package/README.md CHANGED
@@ -22,22 +22,22 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
22
22
 
23
23
  ### Core
24
24
 
25
- * **Comprehensive support** 🎯 — Supports all major feed formats and namespaces.
26
- * **Preserves structure** 📦 — Parsed feed object maintains the original feed structure making it easy to access the data.
27
- * **Smart namespace handling** 🧠 — Normalizes custom namespace prefixes to standard ones (e.g., `<custom:creator>` becomes `dc.creator`).
28
- * **Parsing & generating** 🔩 — Use one package for both parsing and generating feeds.
25
+ * **Comprehensive support** — Supports all major feed formats and namespaces.
26
+ * **Preserves structure** — Parsed feed object maintains the original feed structure making it easy to access the data.
27
+ * **Smart namespace handling** — Normalizes custom namespace prefixes to standard ones (e.g., `<custom:creator>` becomes `dc.creator`).
28
+ * **Parsing & generating** — Use one package for both parsing and generating feeds.
29
29
 
30
30
  ### Leniency
31
- * **Normalizes legacy elements** ✨ — Upgrades feed elements to their modern equivalents so that you never need to worry about reading feeds in older formats.
32
- * **CaSe INSENsiTive** 🐍 — Handles fields and attributes in any case (lowercase, uppercase, mixed).
33
- * **Namespace URI tolerance** 🔧 — Accepts non-official namespace URIs (HTTPS variants, case variations, trailing slashes, whitespace).
34
- * **Forgiving** 🤝 — Gracefully handles malformed or incomplete feeds and extracts valid data. This makes it suitable for use with real-world feeds that may not strictly follow specifications.
31
+ * **Normalizes legacy elements** — Upgrades feed elements to their modern equivalents so that you never need to worry about reading feeds in older formats.
32
+ * **CaSe INSENsiTive** — Handles fields and attributes in any case (lowercase, uppercase, mixed).
33
+ * **Namespace URI tolerance** — Accepts non-official namespace URIs (HTTPS variants, case variations, trailing slashes, whitespace).
34
+ * **Forgiving** — Gracefully handles malformed or incomplete feeds and extracts valid data. This makes it suitable for use with real-world feeds that may not strictly follow specifications.
35
35
 
36
- ### Performance and Type-Safety
37
- * **Ultrafast parsing** ⚡ — One of the fastest JavaScript feed parsers ([see benchmarks](/benchmarks)).
38
- * **Type-safe API** 🛟 — Built with TypeScript from the ground up, it provides complete type definitions for every feed format and namespace.
39
- * **Tree-shakable** 🍃 — Only include the parts of the library you need, reducing bundle size.
40
- * **Well-tested** 🔬 — Comprehensive test suite with over 2000 tests and 99% code coverage.
36
+ ### Performance
37
+ * **Ultrafast parsing** — One of the fastest JavaScript feed parsers ([see benchmarks](/benchmarks)).
38
+ * **Type-safe API** — Built with TypeScript from the ground up, it provides complete type definitions for every feed format and namespace.
39
+ * **Tree-shakable** — Only include the parts of the library you need, reducing bundle size.
40
+ * **Well-tested** — Comprehensive test suite with over 2000 tests and 99% code coverage.
41
41
 
42
42
  ### Compatibility
43
43
  * Works in Node.js 14.0.0+ and modern browsers.
@@ -56,23 +56,23 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
56
56
 
57
57
  ### Feeds
58
58
 
59
- | Format | Versions | Parsing | Generating |
60
- |--------|----------|---------|------------|
61
- | [RSS](http://cyber.law.harvard.edu/rss/rss.html) | 0.9x, 2.0 | ✅ | ✅ |
62
- | [Atom](https://tools.ietf.org/html/rfc4287) | 0.3, 1.0 | ✅ | ✅ |
63
- | [RDF](https://web.resource.org/rss/1.0/spec) | 0.9, 1.0 | ✅ | 📋 |
64
- | [JSON Feed](https://jsonfeed.org) | 1.0, 1.1 | ✅ | ✅ |
59
+ | Format | Versions | Parse | Generate |
60
+ |--------|----------|-------|----------|
61
+ | [RSS](https://feedsmith.dev/reference/feeds/rss) | 0.9x, 2.0 | ✅ | ✅ |
62
+ | [Atom](https://feedsmith.dev/reference/feeds/atom) | 0.3, 1.0 | ✅ | ✅ |
63
+ | [RDF](https://feedsmith.dev/reference/feeds/rdf) | 0.9, 1.0 | ✅ | 📋 |
64
+ | [JSON Feed](https://feedsmith.dev/reference/feeds/json) | 1.0, 1.1 | ✅ | ✅ |
65
65
 
66
66
  ### Other
67
67
 
68
- | Format | Versions | Parsing | Generating |
69
- |--------|----------|---------|------------|
70
- | [OPML](https://opml.org/) | 1.0, 2.0 | ✅ | ✅ |
68
+ | Format | Versions | Parse | Generate |
69
+ |--------|----------|-------|----------|
70
+ | [OPML](https://feedsmith.dev/reference/other/opml) | 1.0, 2.0 | ✅ | ✅ |
71
71
 
72
72
  ### Feed Namespaces
73
73
 
74
- | Name | Prefix | Supported in | Parsing | Generating |
75
- |------|---------|--------------|---------|------------|
74
+ | Name | Prefix | Supported in | Parse | Generate |
75
+ |------|---------|--------------|-------|----------|
76
76
  | [Atom](https://feedsmith.dev/reference/namespaces/atom) | `<atom:*>` | RSS, RDF | ✅ | ✅ |
77
77
  | [Dublin Core](https://feedsmith.dev/reference/namespaces/dc) | `<dc:*>` | RSS, Atom, RDF | ✅ | ✅ |
78
78
  | [Dublin Core Terms](https://feedsmith.dev/reference/namespaces/dcterms) | `<dcterms:*>` | RSS, Atom, RDF | ✅ | ✅ |
@@ -10,7 +10,7 @@ const require_index$6 = require('../feeds/rss/detect/index.cjs');
10
10
  const require_index$7 = require('../feeds/rss/parse/index.cjs');
11
11
 
12
12
  //#region src/common/parse.ts
13
- const parse$4 = (value, options) => {
13
+ const parse = (value, options) => {
14
14
  if (require_index$6.detect(value)) return {
15
15
  format: "rss",
16
16
  feed: require_index$7.parse(value, options)
@@ -32,4 +32,4 @@ const parse$4 = (value, options) => {
32
32
  };
33
33
 
34
34
  //#endregion
35
- exports.parse = parse$4;
35
+ exports.parse = parse;
@@ -1,4 +1,4 @@
1
- import { DeepPartial, ParseOptions } from "./types.cjs";
1
+ import { ParseOptions } from "./types.cjs";
2
2
  import { Atom } from "../feeds/atom/common/types.cjs";
3
3
  import { Json } from "../feeds/json/common/types.cjs";
4
4
  import { Rdf } from "../feeds/rdf/common/types.cjs";
@@ -7,16 +7,16 @@ import { Rss } from "../feeds/rss/common/types.cjs";
7
7
  //#region src/common/parse.d.ts
8
8
  type Parse = (value: unknown, options?: ParseOptions) => {
9
9
  format: 'rss';
10
- feed: DeepPartial<Rss.Feed<string>>;
10
+ feed: Rss.Feed<string>;
11
11
  } | {
12
12
  format: 'atom';
13
- feed: DeepPartial<Atom.Feed<string>>;
13
+ feed: Atom.Feed<string>;
14
14
  } | {
15
15
  format: 'rdf';
16
- feed: DeepPartial<Rdf.Feed<string>>;
16
+ feed: Rdf.Feed<string>;
17
17
  } | {
18
18
  format: 'json';
19
- feed: DeepPartial<Json.Feed<string>>;
19
+ feed: Json.Feed<string>;
20
20
  };
21
21
  declare const parse: Parse;
22
22
  //#endregion
@@ -1,4 +1,4 @@
1
- import { DeepPartial, ParseOptions } from "./types.js";
1
+ import { ParseOptions } from "./types.js";
2
2
  import { Atom } from "../feeds/atom/common/types.js";
3
3
  import { Json } from "../feeds/json/common/types.js";
4
4
  import { Rdf } from "../feeds/rdf/common/types.js";
@@ -7,16 +7,16 @@ import { Rss } from "../feeds/rss/common/types.js";
7
7
  //#region src/common/parse.d.ts
8
8
  type Parse = (value: unknown, options?: ParseOptions) => {
9
9
  format: 'rss';
10
- feed: DeepPartial<Rss.Feed<string>>;
10
+ feed: Rss.Feed<string>;
11
11
  } | {
12
12
  format: 'atom';
13
- feed: DeepPartial<Atom.Feed<string>>;
13
+ feed: Atom.Feed<string>;
14
14
  } | {
15
15
  format: 'rdf';
16
- feed: DeepPartial<Rdf.Feed<string>>;
16
+ feed: Rdf.Feed<string>;
17
17
  } | {
18
18
  format: 'json';
19
- feed: DeepPartial<Json.Feed<string>>;
19
+ feed: Json.Feed<string>;
20
20
  };
21
21
  declare const parse: Parse;
22
22
  //#endregion
@@ -1,35 +1,35 @@
1
1
  import { parseJsonObject } from "./utils.js";
2
2
  import { detect } from "../feeds/atom/detect/index.js";
3
3
  import { locales } from "./config.js";
4
- import { parse } from "../feeds/atom/parse/index.js";
4
+ import { parse as parse$1 } from "../feeds/atom/parse/index.js";
5
5
  import { detect as detect$1 } from "../feeds/json/detect/index.js";
6
- import { parse as parse$1 } from "../feeds/json/parse/index.js";
6
+ import { parse as parse$2 } from "../feeds/json/parse/index.js";
7
7
  import { detect as detect$2 } from "../feeds/rdf/detect/index.js";
8
- import { parse as parse$2 } from "../feeds/rdf/parse/index.js";
8
+ import { parse as parse$3 } from "../feeds/rdf/parse/index.js";
9
9
  import { detect as detect$3 } from "../feeds/rss/detect/index.js";
10
- import { parse as parse$3 } from "../feeds/rss/parse/index.js";
10
+ import { parse as parse$4 } from "../feeds/rss/parse/index.js";
11
11
 
12
12
  //#region src/common/parse.ts
13
- const parse$4 = (value, options) => {
13
+ const parse = (value, options) => {
14
14
  if (detect$3(value)) return {
15
15
  format: "rss",
16
- feed: parse$3(value, options)
16
+ feed: parse$4(value, options)
17
17
  };
18
18
  if (detect(value)) return {
19
19
  format: "atom",
20
- feed: parse(value, options)
20
+ feed: parse$1(value, options)
21
21
  };
22
22
  if (detect$2(value)) return {
23
23
  format: "rdf",
24
- feed: parse$2(value, options)
24
+ feed: parse$3(value, options)
25
25
  };
26
26
  const json = parseJsonObject(value);
27
27
  if (detect$1(json)) return {
28
28
  format: "json",
29
- feed: parse$1(json, options)
29
+ feed: parse$2(json, options)
30
30
  };
31
31
  throw new Error(locales.unrecognizedFeedFormat);
32
32
  };
33
33
 
34
34
  //#endregion
35
- export { parse$4 as parse };
35
+ export { parse };
@@ -1,9 +1,21 @@
1
1
  //#region src/common/types.d.ts
2
+ type Simplify<T> = { [K in keyof T]: T[K] };
3
+ type Unwrap<T> = T extends {
4
+ __requirable: infer U;
5
+ } ? U : T;
6
+ type HasMarker<T> = [Extract<T, {
7
+ __requirable: unknown;
8
+ }>] extends [never] ? false : true;
9
+ type Optional<T> = { [K in keyof T]-?: object extends Pick<T, K> ? K : never }[keyof T];
10
+ type Marked<T> = { [K in keyof T]-?: HasMarker<T[K]> extends true ? K : never }[keyof T];
11
+ type Strict<T, S extends boolean> = Simplify<S extends true ? { [K in Exclude<keyof T, Optional<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T>]?: Unwrap<T[K]> } : { [K in Exclude<keyof T, Optional<T> | Marked<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T> | Marked<T>]?: Unwrap<T[K]> }>;
12
+ type Requirable<T> = T | {
13
+ __requirable: T;
14
+ };
2
15
  type DateLike = Date | string;
3
16
  type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
4
17
  type IsPlainObject<T> = T extends Array<unknown> ? false : T extends ((...args: Array<unknown>) => unknown) ? false : T extends Date ? false : T extends object ? T extends null ? false : true : false;
5
- type RemoveUndefined<T> = T extends undefined ? never : T;
6
- type DeepPartial<T> = IsPlainObject<T> extends true ? { [P in keyof T]?: DeepPartial<RemoveUndefined<T[P]>> } : T extends Array<infer U> ? Array<DeepPartial<U>> : T;
18
+ type DeepOmit<T, K$1 extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K$1>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K$1> }, Exclude<keyof T, K$1>> : T;
7
19
  type ParseOptions = {
8
20
  maxItems?: number;
9
21
  };
@@ -15,14 +27,14 @@ type XmlStylesheet = {
15
27
  charset?: string;
16
28
  alternate?: boolean;
17
29
  };
18
- type XmlGenerateOptions<O, F extends boolean = false> = O & {
19
- lenient?: F;
30
+ type XmlGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
31
+ strict?: S;
20
32
  stylesheets?: Array<XmlStylesheet>;
21
33
  };
22
- type JsonGenerateOptions<O, F extends boolean = false> = O & {
23
- lenient?: F;
34
+ type XmlGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: XmlGenerateOptions<O, S>) => string;
35
+ type JsonGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
36
+ strict?: S;
24
37
  };
25
- type XmlGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: XmlGenerateOptions<O, F>) => string;
26
- type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
38
+ type JsonGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: JsonGenerateOptions<O, S>) => unknown;
27
39
  //#endregion
28
- export { DateLike, DeepPartial, ExtraFields, JsonGenerateMain, ParseOptions, XmlGenerateMain, XmlGenerateOptions };
40
+ export { DateLike, DeepOmit, ExtraFields, JsonGenerateMain, ParseOptions, Requirable, Strict, XmlGenerateMain, XmlGenerateOptions };
@@ -1,9 +1,21 @@
1
1
  //#region src/common/types.d.ts
2
+ type Simplify<T> = { [K in keyof T]: T[K] };
3
+ type Unwrap<T> = T extends {
4
+ __requirable: infer U;
5
+ } ? U : T;
6
+ type HasMarker<T> = [Extract<T, {
7
+ __requirable: unknown;
8
+ }>] extends [never] ? false : true;
9
+ type Optional<T> = { [K in keyof T]-?: object extends Pick<T, K> ? K : never }[keyof T];
10
+ type Marked<T> = { [K in keyof T]-?: HasMarker<T[K]> extends true ? K : never }[keyof T];
11
+ type Strict<T, S extends boolean> = Simplify<S extends true ? { [K in Exclude<keyof T, Optional<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T>]?: Unwrap<T[K]> } : { [K in Exclude<keyof T, Optional<T> | Marked<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T> | Marked<T>]?: Unwrap<T[K]> }>;
12
+ type Requirable<T> = T | {
13
+ __requirable: T;
14
+ };
2
15
  type DateLike = Date | string;
3
16
  type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
4
17
  type IsPlainObject<T> = T extends Array<unknown> ? false : T extends ((...args: Array<unknown>) => unknown) ? false : T extends Date ? false : T extends object ? T extends null ? false : true : false;
5
- type RemoveUndefined<T> = T extends undefined ? never : T;
6
- type DeepPartial<T> = IsPlainObject<T> extends true ? { [P in keyof T]?: DeepPartial<RemoveUndefined<T[P]>> } : T extends Array<infer U> ? Array<DeepPartial<U>> : T;
18
+ type DeepOmit<T, K$1 extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K$1>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K$1> }, Exclude<keyof T, K$1>> : T;
7
19
  type ParseOptions = {
8
20
  maxItems?: number;
9
21
  };
@@ -15,14 +27,14 @@ type XmlStylesheet = {
15
27
  charset?: string;
16
28
  alternate?: boolean;
17
29
  };
18
- type XmlGenerateOptions<O, F extends boolean = false> = O & {
19
- lenient?: F;
30
+ type XmlGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
31
+ strict?: S;
20
32
  stylesheets?: Array<XmlStylesheet>;
21
33
  };
22
- type JsonGenerateOptions<O, F extends boolean = false> = O & {
23
- lenient?: F;
34
+ type XmlGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: XmlGenerateOptions<O, S>) => string;
35
+ type JsonGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
36
+ strict?: S;
24
37
  };
25
- type XmlGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: XmlGenerateOptions<O, F>) => string;
26
- type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
38
+ type JsonGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: JsonGenerateOptions<O, S>) => unknown;
27
39
  //#endregion
28
- export { DateLike, DeepPartial, ExtraFields, JsonGenerateMain, ParseOptions, XmlGenerateMain, XmlGenerateOptions };
40
+ export { DateLike, DeepOmit, ExtraFields, JsonGenerateMain, ParseOptions, Requirable, Strict, XmlGenerateMain, XmlGenerateOptions };
@@ -64,39 +64,32 @@ const generateSingularOrArray = (singularValue, pluralValues, generator) => {
64
64
  };
65
65
  const cdataStartTag = "<![CDATA[";
66
66
  const cdataEndTag = "]]>";
67
- const stripCdata = (text) => {
68
- if (typeof text !== "string") return text;
67
+ const hasEntities = (text) => {
68
+ const ampIndex = text.indexOf("&");
69
+ return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
70
+ };
71
+ const decodeWithCdata = (text) => {
69
72
  let currentIndex = text.indexOf(cdataStartTag);
70
- if (currentIndex === -1) return text;
73
+ if (currentIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
71
74
  let result = "";
72
75
  let lastIndex = 0;
73
76
  while (currentIndex !== -1) {
74
- result += text.substring(lastIndex, currentIndex);
75
- lastIndex = text.indexOf(cdataEndTag, currentIndex + 9);
76
- if (lastIndex === -1) return text;
77
- result += text.substring(currentIndex + 9, lastIndex);
78
- lastIndex += 3;
77
+ const textBefore = text.substring(lastIndex, currentIndex);
78
+ result += hasEntities(textBefore) ? (0, entities.decodeHTML)(textBefore) : textBefore;
79
+ const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
80
+ if (endIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
81
+ result += text.substring(currentIndex + 9, endIndex);
82
+ lastIndex = endIndex + 3;
79
83
  currentIndex = text.indexOf(cdataStartTag, lastIndex);
80
84
  }
81
- result += text.substring(lastIndex);
85
+ const textAfter = text.substring(lastIndex);
86
+ result += hasEntities(textAfter) ? (0, entities.decodeHTML)(textAfter) : textAfter;
82
87
  return result;
83
88
  };
84
- const hasEntities = (text) => {
85
- const ampIndex = text.indexOf("&");
86
- return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
87
- };
88
89
  const parseString = (value) => {
89
90
  if (typeof value === "string") {
90
91
  if (value === "") return;
91
- let string = value;
92
- if (value.indexOf(cdataStartTag) !== -1) string = stripCdata(value);
93
- string = string.trim();
94
- if (string === "") return;
95
- if (hasEntities(string)) {
96
- string = (0, entities.decodeXML)(string);
97
- if (hasEntities(string)) string = (0, entities.decodeHTML)(string);
98
- }
99
- return string || void 0;
92
+ return decodeWithCdata(value).trim() || void 0;
100
93
  }
101
94
  if (typeof value === "number") return value.toString();
102
95
  };
@@ -215,15 +208,15 @@ const generateYesNoBoolean = (value) => {
215
208
  };
216
209
  const detectNamespaces = (value, recursive = false) => {
217
210
  const namespaces = /* @__PURE__ */ new Set();
218
- const seenKeys = /* @__PURE__ */ new Set();
211
+ const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
219
212
  const traverse = (current) => {
220
213
  if (Array.isArray(current)) {
221
214
  for (const item of current) traverse(item);
222
215
  return;
223
216
  }
224
217
  if (isObject(current)) for (const key in current) {
225
- if (seenKeys.has(key)) continue;
226
- seenKeys.add(key);
218
+ if (seenKeys?.has(key)) continue;
219
+ seenKeys?.add(key);
227
220
  const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
228
221
  const colonIndex = keyWithoutAt.indexOf(":");
229
222
  if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
@@ -268,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
268
261
  return namespaceAttrs;
269
262
  };
270
263
  const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
264
+ const normalizedUriCache = /* @__PURE__ */ new Map();
271
265
  const normalizeNamespaceUri = (uri) => {
272
- return typeof uri === "string" ? uri.trim().toLowerCase() : uri;
266
+ if (typeof uri !== "string") return uri;
267
+ let normalized = normalizedUriCache.get(uri);
268
+ if (normalized === void 0) {
269
+ normalized = uri.trim().toLowerCase();
270
+ normalizedUriCache.set(uri, normalized);
271
+ }
272
+ return normalized;
273
273
  };
274
274
  const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
275
275
  const resolveNamespacePrefix = (uri, localName, fallback) => {
@@ -309,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
309
309
  const traverseAndNormalize = (object, parentContext = {}) => {
310
310
  if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
311
311
  if (!isObject(object)) return object;
312
- const normalizedObject = {};
313
- const keyGroups = /* @__PURE__ */ new Map();
314
312
  const declarations = extractNamespaceDeclarations(object);
315
- const currentContext = {
313
+ let hasDeclarations = false;
314
+ for (const _ in declarations) {
315
+ hasDeclarations = true;
316
+ break;
317
+ }
318
+ const currentContext = hasDeclarations ? {
316
319
  ...parentContext,
317
320
  ...declarations
318
- };
321
+ } : parentContext;
322
+ const normalizedObject = {};
319
323
  for (const key in object) {
320
324
  const value = object[key];
321
325
  if (key.indexOf("@xmlns") === 0) {
@@ -324,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
324
328
  }
325
329
  const normalizedKey = normalizeKey(key, currentContext);
326
330
  const normalizedValue = traverseAndNormalize(value, currentContext);
327
- if (!keyGroups.has(normalizedKey)) keyGroups.set(normalizedKey, []);
328
- const group = keyGroups.get(normalizedKey);
329
- if (group) group.push(normalizedValue);
331
+ if (normalizedKey in normalizedObject) {
332
+ const existing = normalizedObject[normalizedKey];
333
+ if (Array.isArray(existing)) existing.push(normalizedValue);
334
+ else normalizedObject[normalizedKey] = [existing, normalizedValue];
335
+ } else normalizedObject[normalizedKey] = normalizedValue;
330
336
  }
331
- for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
332
337
  return normalizedObject;
333
338
  };
334
339
  const normalizeRoot = (object) => {
@@ -1,4 +1,4 @@
1
- import { decodeHTML, decodeXML } from "entities";
1
+ import { decodeHTML } from "entities";
2
2
 
3
3
  //#region src/common/utils.ts
4
4
  const isPresent = (value) => {
@@ -64,39 +64,32 @@ const generateSingularOrArray = (singularValue, pluralValues, generator) => {
64
64
  };
65
65
  const cdataStartTag = "<![CDATA[";
66
66
  const cdataEndTag = "]]>";
67
- const stripCdata = (text) => {
68
- if (typeof text !== "string") return text;
67
+ const hasEntities = (text) => {
68
+ const ampIndex = text.indexOf("&");
69
+ return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
70
+ };
71
+ const decodeWithCdata = (text) => {
69
72
  let currentIndex = text.indexOf(cdataStartTag);
70
- if (currentIndex === -1) return text;
73
+ if (currentIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
71
74
  let result = "";
72
75
  let lastIndex = 0;
73
76
  while (currentIndex !== -1) {
74
- result += text.substring(lastIndex, currentIndex);
75
- lastIndex = text.indexOf(cdataEndTag, currentIndex + 9);
76
- if (lastIndex === -1) return text;
77
- result += text.substring(currentIndex + 9, lastIndex);
78
- lastIndex += 3;
77
+ const textBefore = text.substring(lastIndex, currentIndex);
78
+ result += hasEntities(textBefore) ? decodeHTML(textBefore) : textBefore;
79
+ const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
80
+ if (endIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
81
+ result += text.substring(currentIndex + 9, endIndex);
82
+ lastIndex = endIndex + 3;
79
83
  currentIndex = text.indexOf(cdataStartTag, lastIndex);
80
84
  }
81
- result += text.substring(lastIndex);
85
+ const textAfter = text.substring(lastIndex);
86
+ result += hasEntities(textAfter) ? decodeHTML(textAfter) : textAfter;
82
87
  return result;
83
88
  };
84
- const hasEntities = (text) => {
85
- const ampIndex = text.indexOf("&");
86
- return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
87
- };
88
89
  const parseString = (value) => {
89
90
  if (typeof value === "string") {
90
91
  if (value === "") return;
91
- let string = value;
92
- if (value.indexOf(cdataStartTag) !== -1) string = stripCdata(value);
93
- string = string.trim();
94
- if (string === "") return;
95
- if (hasEntities(string)) {
96
- string = decodeXML(string);
97
- if (hasEntities(string)) string = decodeHTML(string);
98
- }
99
- return string || void 0;
92
+ return decodeWithCdata(value).trim() || void 0;
100
93
  }
101
94
  if (typeof value === "number") return value.toString();
102
95
  };
@@ -215,15 +208,15 @@ const generateYesNoBoolean = (value) => {
215
208
  };
216
209
  const detectNamespaces = (value, recursive = false) => {
217
210
  const namespaces = /* @__PURE__ */ new Set();
218
- const seenKeys = /* @__PURE__ */ new Set();
211
+ const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
219
212
  const traverse = (current) => {
220
213
  if (Array.isArray(current)) {
221
214
  for (const item of current) traverse(item);
222
215
  return;
223
216
  }
224
217
  if (isObject(current)) for (const key in current) {
225
- if (seenKeys.has(key)) continue;
226
- seenKeys.add(key);
218
+ if (seenKeys?.has(key)) continue;
219
+ seenKeys?.add(key);
227
220
  const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
228
221
  const colonIndex = keyWithoutAt.indexOf(":");
229
222
  if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
@@ -268,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
268
261
  return namespaceAttrs;
269
262
  };
270
263
  const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
264
+ const normalizedUriCache = /* @__PURE__ */ new Map();
271
265
  const normalizeNamespaceUri = (uri) => {
272
- return typeof uri === "string" ? uri.trim().toLowerCase() : uri;
266
+ if (typeof uri !== "string") return uri;
267
+ let normalized = normalizedUriCache.get(uri);
268
+ if (normalized === void 0) {
269
+ normalized = uri.trim().toLowerCase();
270
+ normalizedUriCache.set(uri, normalized);
271
+ }
272
+ return normalized;
273
273
  };
274
274
  const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
275
275
  const resolveNamespacePrefix = (uri, localName, fallback) => {
@@ -309,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
309
309
  const traverseAndNormalize = (object, parentContext = {}) => {
310
310
  if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
311
311
  if (!isObject(object)) return object;
312
- const normalizedObject = {};
313
- const keyGroups = /* @__PURE__ */ new Map();
314
312
  const declarations = extractNamespaceDeclarations(object);
315
- const currentContext = {
313
+ let hasDeclarations = false;
314
+ for (const _ in declarations) {
315
+ hasDeclarations = true;
316
+ break;
317
+ }
318
+ const currentContext = hasDeclarations ? {
316
319
  ...parentContext,
317
320
  ...declarations
318
- };
321
+ } : parentContext;
322
+ const normalizedObject = {};
319
323
  for (const key in object) {
320
324
  const value = object[key];
321
325
  if (key.indexOf("@xmlns") === 0) {
@@ -324,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
324
328
  }
325
329
  const normalizedKey = normalizeKey(key, currentContext);
326
330
  const normalizedValue = traverseAndNormalize(value, currentContext);
327
- if (!keyGroups.has(normalizedKey)) keyGroups.set(normalizedKey, []);
328
- const group = keyGroups.get(normalizedKey);
329
- if (group) group.push(normalizedValue);
331
+ if (normalizedKey in normalizedObject) {
332
+ const existing = normalizedObject[normalizedKey];
333
+ if (Array.isArray(existing)) existing.push(normalizedValue);
334
+ else normalizedObject[normalizedKey] = [existing, normalizedValue];
335
+ } else normalizedObject[normalizedKey] = normalizedValue;
330
336
  }
331
- for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
332
337
  return normalizedObject;
333
338
  };
334
339
  const normalizeRoot = (object) => {