feedsmith 3.0.0-rc.1 → 3.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/common/config.cjs +1 -0
  2. package/dist/common/config.js +29 -28
  3. package/dist/common/parse.d.cts +0 -1
  4. package/dist/common/parse.d.ts +0 -1
  5. package/dist/common/types.d.cts +6 -6
  6. package/dist/common/types.d.ts +6 -6
  7. package/dist/common/utils.cjs +113 -146
  8. package/dist/common/utils.js +111 -144
  9. package/dist/feeds/atom/common/types.d.cts +0 -1
  10. package/dist/feeds/atom/common/types.d.ts +0 -1
  11. package/dist/feeds/atom/generate/config.cjs +6 -2
  12. package/dist/feeds/atom/generate/config.js +5 -1
  13. package/dist/feeds/atom/generate/index.d.cts +0 -1
  14. package/dist/feeds/atom/generate/index.d.ts +0 -1
  15. package/dist/feeds/atom/generate/utils.cjs +45 -8
  16. package/dist/feeds/atom/generate/utils.js +47 -11
  17. package/dist/feeds/atom/parse/config.cjs +4 -74
  18. package/dist/feeds/atom/parse/config.js +6 -73
  19. package/dist/feeds/atom/parse/index.cjs +20 -3
  20. package/dist/feeds/atom/parse/index.d.cts +0 -1
  21. package/dist/feeds/atom/parse/index.d.ts +0 -1
  22. package/dist/feeds/atom/parse/index.js +20 -3
  23. package/dist/feeds/atom/parse/utils.cjs +99 -6
  24. package/dist/feeds/atom/parse/utils.js +96 -8
  25. package/dist/feeds/json/common/types.d.cts +0 -1
  26. package/dist/feeds/json/common/types.d.ts +0 -1
  27. package/dist/feeds/json/generate/index.d.cts +0 -1
  28. package/dist/feeds/json/generate/index.d.ts +0 -1
  29. package/dist/feeds/json/parse/index.d.cts +0 -1
  30. package/dist/feeds/json/parse/index.d.ts +0 -1
  31. package/dist/feeds/json/parse/utils.cjs +29 -29
  32. package/dist/feeds/json/parse/utils.js +30 -30
  33. package/dist/feeds/rdf/common/types.d.cts +0 -1
  34. package/dist/feeds/rdf/common/types.d.ts +0 -1
  35. package/dist/feeds/rdf/parse/config.cjs +14 -29
  36. package/dist/feeds/rdf/parse/config.js +16 -28
  37. package/dist/feeds/rdf/parse/index.cjs +20 -3
  38. package/dist/feeds/rdf/parse/index.d.cts +0 -1
  39. package/dist/feeds/rdf/parse/index.d.ts +0 -1
  40. package/dist/feeds/rdf/parse/index.js +20 -3
  41. package/dist/feeds/rss/common/types.d.cts +0 -1
  42. package/dist/feeds/rss/common/types.d.ts +0 -1
  43. package/dist/feeds/rss/generate/config.cjs +6 -2
  44. package/dist/feeds/rss/generate/config.js +5 -1
  45. package/dist/feeds/rss/generate/index.d.cts +0 -1
  46. package/dist/feeds/rss/generate/index.d.ts +0 -1
  47. package/dist/feeds/rss/parse/config.cjs +1 -15
  48. package/dist/feeds/rss/parse/config.js +3 -15
  49. package/dist/feeds/rss/parse/index.cjs +19 -3
  50. package/dist/feeds/rss/parse/index.d.cts +0 -1
  51. package/dist/feeds/rss/parse/index.d.ts +0 -1
  52. package/dist/feeds/rss/parse/index.js +19 -3
  53. package/dist/index.d.cts +0 -1
  54. package/dist/index.d.ts +0 -1
  55. package/dist/namespaces/atom/common/config.cjs +68 -0
  56. package/dist/namespaces/atom/common/config.js +65 -1
  57. package/dist/namespaces/atom/common/types.d.cts +0 -1
  58. package/dist/namespaces/atom/common/types.d.ts +0 -1
  59. package/dist/namespaces/georss/common/types.d.cts +0 -1
  60. package/dist/namespaces/georss/common/types.d.ts +0 -1
  61. package/dist/namespaces/googleplay/common/types.d.cts +0 -1
  62. package/dist/namespaces/googleplay/common/types.d.ts +0 -1
  63. package/dist/namespaces/itunes/common/types.d.cts +14 -8
  64. package/dist/namespaces/itunes/common/types.d.ts +14 -8
  65. package/dist/namespaces/media/common/types.d.cts +0 -1
  66. package/dist/namespaces/media/common/types.d.ts +0 -1
  67. package/dist/namespaces/opensearch/common/types.d.cts +0 -1
  68. package/dist/namespaces/opensearch/common/types.d.ts +0 -1
  69. package/dist/namespaces/podcast/common/types.d.cts +0 -1
  70. package/dist/namespaces/podcast/common/types.d.ts +0 -1
  71. package/dist/namespaces/prism/common/types.d.cts +16 -8
  72. package/dist/namespaces/prism/common/types.d.ts +16 -8
  73. package/dist/namespaces/psc/common/types.d.cts +0 -1
  74. package/dist/namespaces/psc/common/types.d.ts +0 -1
  75. package/dist/namespaces/rawvoice/common/types.d.cts +0 -1
  76. package/dist/namespaces/rawvoice/common/types.d.ts +0 -1
  77. package/dist/namespaces/rawvoice/parse/utils.cjs +1 -1
  78. package/dist/namespaces/rawvoice/parse/utils.js +2 -2
  79. package/dist/namespaces/source/common/types.d.cts +0 -1
  80. package/dist/namespaces/source/common/types.d.ts +0 -1
  81. package/dist/namespaces/spotify/common/types.d.cts +0 -1
  82. package/dist/namespaces/spotify/common/types.d.ts +0 -1
  83. package/dist/namespaces/thr/common/types.d.cts +0 -1
  84. package/dist/namespaces/thr/common/types.d.ts +0 -1
  85. package/dist/node_modules/trousse/dist/is.cjs +4 -1
  86. package/dist/node_modules/trousse/dist/is.js +4 -1
  87. package/dist/node_modules/trousse/dist/json.cjs +16 -0
  88. package/dist/node_modules/trousse/dist/json.js +16 -0
  89. package/dist/node_modules/trousse/dist/locales.cjs +15 -0
  90. package/dist/node_modules/trousse/dist/locales.js +15 -0
  91. package/dist/node_modules/trousse/dist/urls.cjs +9 -0
  92. package/dist/node_modules/trousse/dist/urls.js +9 -0
  93. package/dist/opml/common/types.d.cts +0 -1
  94. package/dist/opml/common/types.d.ts +0 -1
  95. package/dist/opml/generate/index.d.cts +0 -1
  96. package/dist/opml/generate/index.d.ts +0 -1
  97. package/dist/opml/parse/index.d.cts +0 -1
  98. package/dist/opml/parse/index.d.ts +0 -1
  99. package/package.json +6 -6
@@ -112,6 +112,7 @@ const namespaceStopNodes = [
112
112
  ...require_config$1.stopNodes,
113
113
  ...require_config$2.stopNodes,
114
114
  ...require_config$3.stopNodes,
115
+ ...require_config$4.stopNodes,
115
116
  ...require_config$5.stopNodes,
116
117
  ...require_config$6.stopNodes,
117
118
  ...require_config$7.stopNodes,
@@ -2,35 +2,35 @@ import { stopNodes, uris } from "../namespaces/acast/common/config.js";
2
2
  import { stopNodes as stopNodes$1, uris as uris$1 } from "../namespaces/admin/common/config.js";
3
3
  import { stopNodes as stopNodes$2, uris as uris$2 } from "../namespaces/app/common/config.js";
4
4
  import { stopNodes as stopNodes$3, uris as uris$3 } from "../namespaces/arxiv/common/config.js";
5
- import { uris as uris$4 } from "../namespaces/atom/common/config.js";
6
- import { stopNodes as stopNodes$4, uris as uris$5 } from "../namespaces/blogchannel/common/config.js";
7
- import { stopNodes as stopNodes$5, uris as uris$6 } from "../namespaces/cc/common/config.js";
8
- import { stopNodes as stopNodes$6, uris as uris$7 } from "../namespaces/content/common/config.js";
9
- import { stopNodes as stopNodes$7, uris as uris$8 } from "../namespaces/creativecommons/common/config.js";
10
- import { stopNodes as stopNodes$8, uris as uris$9 } from "../namespaces/dc/common/config.js";
11
- import { stopNodes as stopNodes$9, uris as uris$10 } from "../namespaces/dcterms/common/config.js";
12
- import { stopNodes as stopNodes$10, uris as uris$11 } from "../namespaces/feedpress/common/config.js";
13
- import { stopNodes as stopNodes$11, uris as uris$12 } from "../namespaces/geo/common/config.js";
14
- import { stopNodes as stopNodes$12, uris as uris$13 } from "../namespaces/georss/common/config.js";
15
- import { stopNodes as stopNodes$13, uris as uris$14 } from "../namespaces/googleplay/common/config.js";
16
- import { stopNodes as stopNodes$14, uris as uris$15 } from "../namespaces/itunes/common/config.js";
17
- import { stopNodes as stopNodes$15, uris as uris$16 } from "../namespaces/media/common/config.js";
18
- import { stopNodes as stopNodes$16, uris as uris$17 } from "../namespaces/opensearch/common/config.js";
19
- import { stopNodes as stopNodes$17, uris as uris$18 } from "../namespaces/pingback/common/config.js";
20
- import { stopNodes as stopNodes$18, uris as uris$19 } from "../namespaces/podcast/common/config.js";
21
- import { stopNodes as stopNodes$19, uris as uris$20 } from "../namespaces/prism/common/config.js";
5
+ import { stopNodes as stopNodes$4, uris as uris$4 } from "../namespaces/atom/common/config.js";
6
+ import { stopNodes as stopNodes$5, uris as uris$5 } from "../namespaces/blogchannel/common/config.js";
7
+ import { stopNodes as stopNodes$6, uris as uris$6 } from "../namespaces/cc/common/config.js";
8
+ import { stopNodes as stopNodes$7, uris as uris$7 } from "../namespaces/content/common/config.js";
9
+ import { stopNodes as stopNodes$8, uris as uris$8 } from "../namespaces/creativecommons/common/config.js";
10
+ import { stopNodes as stopNodes$9, uris as uris$9 } from "../namespaces/dc/common/config.js";
11
+ import { stopNodes as stopNodes$10, uris as uris$10 } from "../namespaces/dcterms/common/config.js";
12
+ import { stopNodes as stopNodes$11, uris as uris$11 } from "../namespaces/feedpress/common/config.js";
13
+ import { stopNodes as stopNodes$12, uris as uris$12 } from "../namespaces/geo/common/config.js";
14
+ import { stopNodes as stopNodes$13, uris as uris$13 } from "../namespaces/georss/common/config.js";
15
+ import { stopNodes as stopNodes$14, uris as uris$14 } from "../namespaces/googleplay/common/config.js";
16
+ import { stopNodes as stopNodes$15, uris as uris$15 } from "../namespaces/itunes/common/config.js";
17
+ import { stopNodes as stopNodes$16, uris as uris$16 } from "../namespaces/media/common/config.js";
18
+ import { stopNodes as stopNodes$17, uris as uris$17 } from "../namespaces/opensearch/common/config.js";
19
+ import { stopNodes as stopNodes$18, uris as uris$18 } from "../namespaces/pingback/common/config.js";
20
+ import { stopNodes as stopNodes$19, uris as uris$19 } from "../namespaces/podcast/common/config.js";
21
+ import { stopNodes as stopNodes$20, uris as uris$20 } from "../namespaces/prism/common/config.js";
22
22
  import { uris as uris$21 } from "../namespaces/psc/common/config.js";
23
- import { stopNodes as stopNodes$20, uris as uris$22 } from "../namespaces/rawvoice/common/config.js";
24
- import { stopNodes as stopNodes$21, uris as uris$23 } from "../namespaces/rdf/common/config.js";
23
+ import { stopNodes as stopNodes$21, uris as uris$22 } from "../namespaces/rawvoice/common/config.js";
24
+ import { stopNodes as stopNodes$22, uris as uris$23 } from "../namespaces/rdf/common/config.js";
25
25
  import { uris as uris$24 } from "../namespaces/rss/common/config.js";
26
- import { stopNodes as stopNodes$22, uris as uris$25 } from "../namespaces/slash/common/config.js";
27
- import { stopNodes as stopNodes$23, uris as uris$26 } from "../namespaces/source/common/config.js";
28
- import { stopNodes as stopNodes$24, uris as uris$27 } from "../namespaces/spotify/common/config.js";
29
- import { stopNodes as stopNodes$25, uris as uris$28 } from "../namespaces/sy/common/config.js";
30
- import { stopNodes as stopNodes$26, uris as uris$29 } from "../namespaces/thr/common/config.js";
31
- import { stopNodes as stopNodes$27, uris as uris$30 } from "../namespaces/trackback/common/config.js";
32
- import { stopNodes as stopNodes$28, uris as uris$31 } from "../namespaces/wfw/common/config.js";
33
- import { stopNodes as stopNodes$29, uris as uris$32 } from "../namespaces/yt/common/config.js";
26
+ import { stopNodes as stopNodes$23, uris as uris$25 } from "../namespaces/slash/common/config.js";
27
+ import { stopNodes as stopNodes$24, uris as uris$26 } from "../namespaces/source/common/config.js";
28
+ import { stopNodes as stopNodes$25, uris as uris$27 } from "../namespaces/spotify/common/config.js";
29
+ import { stopNodes as stopNodes$26, uris as uris$28 } from "../namespaces/sy/common/config.js";
30
+ import { stopNodes as stopNodes$27, uris as uris$29 } from "../namespaces/thr/common/config.js";
31
+ import { stopNodes as stopNodes$28, uris as uris$30 } from "../namespaces/trackback/common/config.js";
32
+ import { stopNodes as stopNodes$29, uris as uris$31 } from "../namespaces/wfw/common/config.js";
33
+ import { stopNodes as stopNodes$30, uris as uris$32 } from "../namespaces/yt/common/config.js";
34
34
  //#region src/common/config.ts
35
35
  const parserConfig = {
36
36
  trimValues: false,
@@ -137,7 +137,8 @@ const namespaceStopNodes = [
137
137
  ...stopNodes$26,
138
138
  ...stopNodes$27,
139
139
  ...stopNodes$28,
140
- ...stopNodes$29
140
+ ...stopNodes$29,
141
+ ...stopNodes$30
141
142
  ];
142
143
  //#endregion
143
144
  export { builderConfig, locales, namespacePrefixes, namespaceStopNodes, namespaceUris, parserConfig };
@@ -3,7 +3,6 @@ import { AtomFeed } from "../feeds/atom/common/types.cjs";
3
3
  import { JsonFeed } from "../feeds/json/common/types.cjs";
4
4
  import { RdfFeed } from "../feeds/rdf/common/types.cjs";
5
5
  import { RssFeed } from "../feeds/rss/common/types.cjs";
6
-
7
6
  //#region src/common/parse.d.ts
8
7
  type AnyFeed<TDate = string> = {
9
8
  format: 'rss';
@@ -3,7 +3,6 @@ import { AtomFeed } from "../feeds/atom/common/types.js";
3
3
  import { JsonFeed } from "../feeds/json/common/types.js";
4
4
  import { RdfFeed } from "../feeds/rdf/common/types.js";
5
5
  import { RssFeed } from "../feeds/rss/common/types.js";
6
-
7
6
  //#region src/common/parse.d.ts
8
7
  type AnyFeed<TDate = string> = {
9
8
  format: 'rss';
@@ -1,21 +1,21 @@
1
1
  //#region src/common/types.d.ts
2
- type Simplify<T> = { [K in keyof T]: T[K] };
2
+ type Simplify<T> = { [K in keyof T]: T[K]; };
3
3
  type Unwrap<T> = T extends {
4
4
  __requirable: infer U;
5
5
  } ? U : T;
6
6
  type HasMarker<T> = [Extract<T, {
7
7
  __requirable: unknown;
8
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]> }>;
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
12
  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;
13
- type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K> }, Exclude<keyof T, K>> : T;
13
+ type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K>; }, Exclude<keyof T, K>> : T;
14
14
  type Requirable<T> = T | {
15
15
  __requirable: T;
16
16
  };
17
17
  type DateLike = Date | string;
18
- type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
18
+ type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V; };
19
19
  type ParseMainOptions<TDate> = {
20
20
  maxItems?: number;
21
21
  parseDateFn?: (raw: string) => TDate;
@@ -1,21 +1,21 @@
1
1
  //#region src/common/types.d.ts
2
- type Simplify<T> = { [K in keyof T]: T[K] };
2
+ type Simplify<T> = { [K in keyof T]: T[K]; };
3
3
  type Unwrap<T> = T extends {
4
4
  __requirable: infer U;
5
5
  } ? U : T;
6
6
  type HasMarker<T> = [Extract<T, {
7
7
  __requirable: unknown;
8
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]> }>;
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
12
  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;
13
- type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K> }, Exclude<keyof T, K>> : T;
13
+ type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K>; }, Exclude<keyof T, K>> : T;
14
14
  type Requirable<T> = T | {
15
15
  __requirable: T;
16
16
  };
17
17
  type DateLike = Date | string;
18
- type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
18
+ type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V; };
19
19
  type ParseMainOptions<TDate> = {
20
20
  maxItems?: number;
21
21
  parseDateFn?: (raw: string) => TDate;
@@ -1,10 +1,14 @@
1
1
  const require_is = require("../node_modules/trousse/dist/is.cjs");
2
2
  const require_coercions = require("../node_modules/trousse/dist/coercions.cjs");
3
+ const require_json = require("../node_modules/trousse/dist/json.cjs");
3
4
  let entities = require("entities");
4
5
  //#region src/common/utils.ts
5
6
  const isNonEmptyStringOrNumber = (value) => {
6
7
  return require_is.isNumber(value) || require_is.isNonEmptyString(value);
7
8
  };
9
+ const isXmlAttributeKey = (key) => {
10
+ return key.charCodeAt(0) === 64;
11
+ };
8
12
  const retrieveText = (value) => {
9
13
  return value?.["#text"] ?? value;
10
14
  };
@@ -99,7 +103,7 @@ const parseString = (value) => {
99
103
  }
100
104
  if (typeof value === "number") return value.toString();
101
105
  };
102
- const parseJsonString = (value) => {
106
+ const parseVerbatimString = (value) => {
103
107
  if (typeof value === "string") {
104
108
  if (value === "") return;
105
109
  return value.trim() || void 0;
@@ -222,7 +226,7 @@ const detectNamespaces = (value, recursive = false) => {
222
226
  if (require_is.isPlainObject(current)) for (const key in current) {
223
227
  if (seenKeys?.has(key)) continue;
224
228
  seenKeys?.add(key);
225
- const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
229
+ const keyWithoutAt = isXmlAttributeKey(key) ? key.slice(1) : key;
226
230
  const colonIndex = keyWithoutAt.indexOf(":");
227
231
  if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
228
232
  if (recursive) traverse(current[key]);
@@ -265,166 +269,128 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
265
269
  }
266
270
  return namespaceAttrs;
267
271
  };
268
- const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespaces) => {
269
- const normalizedUriCache = /* @__PURE__ */ new Map();
270
- const normalizeNamespaceUri = (uri) => {
271
- if (typeof uri !== "string") return uri;
272
- let normalized = normalizedUriCache.get(uri);
273
- if (normalized === void 0) {
274
- normalized = uri.trim().toLowerCase();
275
- normalizedUriCache.set(uri, normalized);
276
- }
277
- return normalized;
278
- };
279
- const primaryNamespaceUris = primaryNamespaces?.length ? primaryNamespaces.flatMap((key) => namespaceUris[key].map(normalizeNamespaceUri)) : void 0;
280
- const resolveNamespacePrefix = (uri, localName, fallback) => {
281
- const normalizedUri = normalizeNamespaceUri(uri);
282
- if (primaryNamespaceUris?.includes(normalizedUri)) return localName;
283
- const standardPrefix = namespacePrefixes[normalizedUri];
284
- if (standardPrefix) return `${standardPrefix}:${localName}`;
285
- return fallback;
286
- };
287
- const extractNamespaceDeclarations = (element) => {
288
- const declarations = {};
289
- if (require_is.isPlainObject(element)) {
290
- for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
291
- else if (key.indexOf("@xmlns:") === 0) {
292
- const prefix = key.slice(7);
293
- declarations[prefix] = normalizeNamespaceUri(element[key]);
294
- }
295
- }
296
- return declarations;
297
- };
298
- const normalizeWithContext = (name, context, useDefault = false) => {
299
- const colonIndex = name.indexOf(":");
300
- if (colonIndex === -1) {
301
- if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
302
- return name;
303
- }
304
- const prefix = name.slice(0, colonIndex);
305
- const unprefixedName = name.slice(colonIndex + 1);
306
- const uri = context[prefix];
307
- if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
308
- return name;
272
+ const createNamespaceResolver = (options) => {
273
+ const { namespaceUris, namespacePrefixes, primaryNamespaces } = options;
274
+ const primaryUris = new Set(primaryNamespaces?.flatMap((key) => {
275
+ return namespaceUris[key]?.map((uri) => uri.toLowerCase()) ?? [];
276
+ }));
277
+ const resolveUri = (uri) => {
278
+ const normalized = uri.trim().toLowerCase();
279
+ if (primaryUris.has(normalized)) return "";
280
+ return namespacePrefixes[normalized];
309
281
  };
310
- const normalizeKey = (key, context) => {
311
- if (key.charCodeAt(0) === 64) {
312
- const attrName = key.slice(1);
313
- return `@${normalizeWithContext(attrName, context, false)}`;
282
+ const seedScanLimit = 65536;
283
+ const findRootIndex = (document) => {
284
+ let index = document.indexOf("<");
285
+ while (index !== -1) {
286
+ const marker = document.charCodeAt(index + 1);
287
+ if (marker !== 63 && marker !== 33) return index;
288
+ const end = document.startsWith("<!--", index) ? document.indexOf("-->", index) : document.indexOf(">", index);
289
+ if (end === -1) return -1;
290
+ index = document.indexOf("<", end);
314
291
  }
315
- return normalizeWithContext(key, context, true);
292
+ return -1;
316
293
  };
317
- const traverseAndNormalize = (object, parentContext = {}) => {
318
- if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
319
- if (!require_is.isPlainObject(object)) return object;
320
- const declarations = extractNamespaceDeclarations(object);
321
- let hasDeclarations = false;
322
- for (const _ in declarations) {
323
- hasDeclarations = true;
324
- break;
325
- }
326
- const currentContext = hasDeclarations ? {
327
- ...parentContext,
328
- ...declarations
329
- } : parentContext;
330
- const normalizedObject = {};
331
- for (const key in object) {
332
- const value = object[key];
333
- if (key.indexOf("@xmlns") === 0) {
334
- normalizedObject[key] = value;
335
- continue;
294
+ return (document) => {
295
+ const prefixMap = /* @__PURE__ */ new Map();
296
+ const seededPrefixes = /* @__PURE__ */ new Set();
297
+ let defaultCanonical;
298
+ let hasRemapping = false;
299
+ let tagsSeen = 0;
300
+ const recordPrefix = (prefix, uri) => {
301
+ if (!prefixMap.has(prefix)) {
302
+ const canonical = resolveUri(uri);
303
+ if (canonical !== void 0) {
304
+ prefixMap.set(prefix, canonical);
305
+ if (canonical !== prefix) hasRemapping = true;
306
+ }
336
307
  }
337
- const normalizedKey = normalizeKey(key, currentContext);
338
- const normalizedValue = traverseAndNormalize(value, currentContext);
339
- if (normalizedKey in normalizedObject) {
340
- const existing = normalizedObject[normalizedKey];
341
- if (Array.isArray(existing)) existing.push(normalizedValue);
342
- else normalizedObject[normalizedKey] = [existing, normalizedValue];
343
- } else normalizedObject[normalizedKey] = normalizedValue;
344
- }
345
- return normalizedObject;
346
- };
347
- const needsNormalization = (object) => {
348
- const check = (value) => {
349
- if (Array.isArray(value)) {
350
- for (const item of value) if (check(item)) return true;
351
- return false;
308
+ };
309
+ if (document) {
310
+ const head = document.length > seedScanLimit ? document.slice(0, seedScanLimit) : document;
311
+ const declarationTailRegex = /([\w.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/y;
312
+ let index = head.indexOf("xmlns:", findRootIndex(head));
313
+ while (index !== -1) {
314
+ declarationTailRegex.lastIndex = index + 6;
315
+ const match = declarationTailRegex.exec(head);
316
+ if (match) {
317
+ const prefix = match[1].toLowerCase();
318
+ recordPrefix(prefix, match[2] ?? match[3]);
319
+ seededPrefixes.add(prefix);
320
+ }
321
+ index = head.indexOf("xmlns:", match ? declarationTailRegex.lastIndex : index + 6);
352
322
  }
353
- if (!require_is.isPlainObject(value)) return false;
354
- for (const key in value) {
355
- if (key[0] === "@") {
356
- if (key === "@xmlns") {
357
- const normalizedUri = normalizeNamespaceUri(value[key]);
358
- if (primaryNamespaceUris?.includes(normalizedUri)) continue;
359
- if (namespacePrefixes[normalizedUri]) return true;
360
- } else if (key.startsWith("@xmlns:")) {
361
- const prefix = key.slice(7);
362
- const normalizedUri = normalizeNamespaceUri(value[key]);
363
- const standardPrefix = namespacePrefixes[normalizedUri];
364
- if (standardPrefix) {
365
- if (primaryNamespaceUris?.includes(normalizedUri)) return true;
366
- if (standardPrefix !== prefix) return true;
367
- }
368
- }
369
- continue;
323
+ }
324
+ const recordDeclaration = (rawAttrName, value) => {
325
+ const firstCharCode = rawAttrName.charCodeAt(0);
326
+ if (firstCharCode !== 120 && firstCharCode !== 88 || typeof value !== "string") return;
327
+ const attrName = rawAttrName.toLowerCase();
328
+ if (attrName === "xmlns") {
329
+ if (tagsSeen === 1 && defaultCanonical === void 0) {
330
+ defaultCanonical = resolveUri(value);
331
+ if (defaultCanonical) hasRemapping = true;
370
332
  }
371
- if (key[0] === "#") continue;
372
- if (check(value[key])) return true;
333
+ return;
334
+ }
335
+ if (attrName.startsWith("xmlns:")) {
336
+ const prefix = attrName.slice(6);
337
+ if (seededPrefixes.delete(prefix)) prefixMap.delete(prefix);
338
+ recordPrefix(prefix, value);
373
339
  }
374
- return false;
375
340
  };
376
- return check(object);
377
- };
378
- const normalizeRoot = (object) => {
379
- if (!require_is.isPlainObject(object)) return object;
380
- if (!needsNormalization(object)) return object;
381
- const normalizedObject = {};
382
- for (const key in object) {
383
- const value = object[key];
384
- const declarations = extractNamespaceDeclarations(value);
385
- const normalizedKey = Object.keys(declarations).length ? normalizeKey(key, declarations) : key;
386
- normalizedObject[normalizedKey] = traverseAndNormalize(value);
387
- }
388
- return normalizedObject;
341
+ const transformName = (name, useDefault) => {
342
+ const lowered = name.toLowerCase();
343
+ if (!hasRemapping) return lowered;
344
+ const colonIndex = lowered.indexOf(":");
345
+ if (colonIndex === -1) {
346
+ if (useDefault && defaultCanonical) return `${defaultCanonical}:${lowered}`;
347
+ return lowered;
348
+ }
349
+ const prefix = lowered.slice(0, colonIndex);
350
+ if (prefix === "xmlns" || prefix === "xml") return lowered;
351
+ const canonical = prefixMap.get(prefix);
352
+ if (canonical === void 0) return lowered;
353
+ const local = lowered.slice(colonIndex + 1);
354
+ return canonical === "" ? local : `${canonical}:${local}`;
355
+ };
356
+ const transformTagName = (name) => {
357
+ tagsSeen++;
358
+ return transformName(name, true);
359
+ };
360
+ const transformAttributeName = (name) => `@${transformName(name.slice(1), false)}`;
361
+ const attributeValueProcessor = (attrName, value) => {
362
+ recordDeclaration(attrName, value);
363
+ return value;
364
+ };
365
+ const updateTag = (tagName) => {
366
+ if (!hasRemapping) return tagName;
367
+ const colonIndex = tagName.indexOf(":");
368
+ if (colonIndex === -1) return defaultCanonical ? `${defaultCanonical}:${tagName}` : tagName;
369
+ const prefix = tagName.slice(0, colonIndex);
370
+ const canonical = prefixMap.get(prefix);
371
+ if (canonical === void 0 || canonical === prefix) return tagName;
372
+ const local = tagName.slice(colonIndex + 1);
373
+ return canonical === "" ? local : `${canonical}:${local}`;
374
+ };
375
+ return {
376
+ transformTagName,
377
+ transformAttributeName,
378
+ attributeValueProcessor,
379
+ updateTag
380
+ };
389
381
  };
390
- return normalizeRoot;
391
382
  };
392
- const startsWithBraceRegex = /^\s*\{/;
393
- const endsWithBraceRegex = /\}\s*$/;
394
383
  const parseJsonObject = (value) => {
395
384
  if (require_is.isPlainObject(value)) return value;
396
- if (!require_is.isNonEmptyString(value) || value.length < 2) return;
397
- const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
398
- const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
399
- if (!startsWithBrace || !endsWithBrace) return;
385
+ if (!require_is.isNonEmptyString(value) || !require_json.isJsonLike(value)) return;
400
386
  try {
401
- return JSON.parse(value);
387
+ const parsed = JSON.parse(value);
388
+ if (require_is.isPlainObject(parsed)) return parsed;
402
389
  } catch {}
403
390
  };
404
- const namespaceContainers = [
405
- "media:group",
406
- "media:content",
407
- "media:group.media:content",
408
- "media:embed",
409
- "podcast:liveitem",
410
- "itunes:owner"
411
- ];
412
- const expandStopNodes = (stopNodes, feedContainerPaths) => {
413
- const set = /* @__PURE__ */ new Set();
414
- for (const node of stopNodes) {
415
- const suffix = node.slice(2);
416
- const prefix = suffix.split(":")[0];
417
- for (const feedPath of feedContainerPaths) {
418
- set.add(`${feedPath}.${suffix}`);
419
- for (const nsContainer of namespaceContainers) if (nsContainer.split(":")[0] === prefix) set.add(`${feedPath}.${nsContainer}.${suffix}`);
420
- }
421
- }
422
- return [...set];
423
- };
424
391
  //#endregion
425
- exports.createNamespaceNormalizator = createNamespaceNormalizator;
392
+ exports.createNamespaceResolver = createNamespaceResolver;
426
393
  exports.detectNamespaces = detectNamespaces;
427
- exports.expandStopNodes = expandStopNodes;
428
394
  exports.generateBoolean = generateBoolean;
429
395
  exports.generateCdataString = generateCdataString;
430
396
  exports.generateCsvOf = generateCsvOf;
@@ -440,6 +406,7 @@ exports.generateXmlStylesheet = generateXmlStylesheet;
440
406
  exports.generateYesNoBoolean = generateYesNoBoolean;
441
407
  exports.hasEntities = hasEntities;
442
408
  exports.isNonEmptyStringOrNumber = isNonEmptyStringOrNumber;
409
+ exports.isXmlAttributeKey = isXmlAttributeKey;
443
410
  exports.limitArray = limitArray;
444
411
  exports.parseArray = parseArray;
445
412
  exports.parseArrayOf = parseArrayOf;
@@ -447,11 +414,11 @@ exports.parseBoolean = parseBoolean;
447
414
  exports.parseCsvOf = parseCsvOf;
448
415
  exports.parseDate = parseDate;
449
416
  exports.parseJsonObject = parseJsonObject;
450
- exports.parseJsonString = parseJsonString;
451
417
  exports.parseNumber = parseNumber;
452
418
  exports.parseSingular = parseSingular;
453
419
  exports.parseSingularOf = parseSingularOf;
454
420
  exports.parseString = parseString;
421
+ exports.parseVerbatimString = parseVerbatimString;
455
422
  exports.parseYesNoBoolean = parseYesNoBoolean;
456
423
  exports.retrieveRdfResourceOrText = retrieveRdfResourceOrText;
457
424
  exports.retrieveText = retrieveText;