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
@@ -1,10 +1,14 @@
1
1
  import { isNonEmptyString, isNumber, isPlainObject, isPresent } from "../node_modules/trousse/dist/is.js";
2
2
  import { coerceBoolean, coerceNumber, coerceSingular } from "../node_modules/trousse/dist/coercions.js";
3
+ import { isJsonLike } from "../node_modules/trousse/dist/json.js";
3
4
  import { decodeHTML } from "entities";
4
5
  //#region src/common/utils.ts
5
6
  const isNonEmptyStringOrNumber = (value) => {
6
7
  return isNumber(value) || 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 (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,161 +269,124 @@ 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 (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 (!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 (!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 (!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 (isPlainObject(value)) return value;
396
- if (!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 (!isNonEmptyString(value) || !isJsonLike(value)) return;
400
386
  try {
401
- return JSON.parse(value);
387
+ const parsed = JSON.parse(value);
388
+ if (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
- export { createNamespaceNormalizator, detectNamespaces, expandStopNodes, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateTextOrCdataString, generateXml, generateXmlStylesheet, generateYesNoBoolean, hasEntities, isNonEmptyStringOrNumber, limitArray, parseArray, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseJsonString, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
392
+ export { createNamespaceResolver, detectNamespaces, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateTextOrCdataString, generateXml, generateXmlStylesheet, generateYesNoBoolean, hasEntities, isNonEmptyStringOrNumber, isXmlAttributeKey, limitArray, parseArray, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseVerbatimString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
@@ -21,7 +21,6 @@ import { TrackbackNs } from "../../../namespaces/trackback/common/types.cjs";
21
21
  import { WfwNs } from "../../../namespaces/wfw/common/types.cjs";
22
22
  import { XmlNs } from "../../../namespaces/xml/common/types.cjs";
23
23
  import { YtNs } from "../../../namespaces/yt/common/types.cjs";
24
-
25
24
  //#region src/feeds/atom/common/types.d.ts
26
25
  declare namespace AtomFeed {
27
26
  type Text = {
@@ -21,7 +21,6 @@ import { TrackbackNs } from "../../../namespaces/trackback/common/types.js";
21
21
  import { WfwNs } from "../../../namespaces/wfw/common/types.js";
22
22
  import { XmlNs } from "../../../namespaces/xml/common/types.js";
23
23
  import { YtNs } from "../../../namespaces/yt/common/types.js";
24
-
25
24
  //#region src/feeds/atom/common/types.d.ts
26
25
  declare namespace AtomFeed {
27
26
  type Text = {
@@ -1,5 +1,9 @@
1
- const require_config = require("../../../common/config.cjs");
1
+ const require_config = require("../../../namespaces/atom/common/config.cjs");
2
+ const require_config$1 = require("../../../common/config.cjs");
2
3
  //#region src/feeds/atom/generate/config.ts
3
- const builder = new (require("fast-xml-parser")).XMLBuilder({ ...require_config.builderConfig });
4
+ const builder = new (require("fast-xml-parser")).XMLBuilder({
5
+ ...require_config$1.builderConfig,
6
+ stopNodes: require_config.textConstructs.map((element) => `..${element}[type=xhtml]`)
7
+ });
4
8
  //#endregion
5
9
  exports.builder = builder;
@@ -1,6 +1,10 @@
1
+ import { textConstructs } from "../../../namespaces/atom/common/config.js";
1
2
  import { builderConfig } from "../../../common/config.js";
2
3
  import { XMLBuilder } from "fast-xml-parser";
3
4
  //#region src/feeds/atom/generate/config.ts
4
- const builder = new XMLBuilder({ ...builderConfig });
5
+ const builder = new XMLBuilder({
6
+ ...builderConfig,
7
+ stopNodes: textConstructs.map((element) => `..${element}[type=xhtml]`)
8
+ });
5
9
  //#endregion
6
10
  export { builder };
@@ -1,6 +1,5 @@
1
1
  import { DateLike, GenerateMainXml } from "../../../common/types.cjs";
2
2
  import { AtomFeed } from "../common/types.cjs";
3
-
4
3
  //#region src/feeds/atom/generate/index.d.ts
5
4
  declare const generate: GenerateMainXml<AtomFeed.Feed<DateLike>, AtomFeed.Feed<Date, true>>;
6
5
  //#endregion
@@ -1,6 +1,5 @@
1
1
  import { DateLike, GenerateMainXml } from "../../../common/types.js";
2
2
  import { AtomFeed } from "../common/types.js";
3
-
4
3
  //#region src/feeds/atom/generate/index.d.ts
5
4
  declare const generate: GenerateMainXml<AtomFeed.Feed<DateLike>, AtomFeed.Feed<Date, true>>;
6
5
  //#endregion
@@ -1,4 +1,5 @@
1
1
  const require_is = require("../../../node_modules/trousse/dist/is.cjs");
2
+ const require_locales = require("../../../node_modules/trousse/dist/locales.cjs");
2
3
  const require_config = require("../../../common/config.cjs");
3
4
  const require_utils = require("../../../common/utils.cjs");
4
5
  const require_utils$1 = require("../../../namespaces/admin/generate/utils.cjs");
@@ -23,26 +24,61 @@ const require_utils$19 = require("../../../namespaces/trackback/generate/utils.c
23
24
  const require_utils$20 = require("../../../namespaces/wfw/generate/utils.cjs");
24
25
  const require_utils$21 = require("../../../namespaces/xml/generate/utils.cjs");
25
26
  const require_utils$22 = require("../../../namespaces/yt/generate/utils.cjs");
27
+ let fast_xml_parser = require("fast-xml-parser");
26
28
  //#region src/feeds/atom/generate/utils.ts
27
29
  const createNamespaceSetter = (prefix) => {
28
30
  return (key) => prefix ? `${prefix}${key}` : key;
29
31
  };
32
+ const nonXmlEntityRegex = /&(?!(?:amp|lt|gt|quot|apos);|#\d+;|#x[0-9a-fA-F]+;)[^;\s&<]+;/;
33
+ const generateXhtmlValue = (value) => {
34
+ if (!require_is.isNonEmptyString(value)) return;
35
+ const wrapped = `<div xmlns="http://www.w3.org/1999/xhtml">${value.trim().replace(/\r/g, "&#13;")}</div>`;
36
+ if (fast_xml_parser.XMLValidator.validate(wrapped) !== true || nonXmlEntityRegex.test(wrapped)) return;
37
+ return { "#text": `${wrapped}\n` };
38
+ };
39
+ const escapeStopNodeAttributes = (value) => {
40
+ if (value["@type"] !== "xhtml") return value;
41
+ const escaped = {};
42
+ for (const key in value) {
43
+ const attribute = value[key];
44
+ escaped[key] = require_utils.isXmlAttributeKey(key) && typeof attribute === "string" ? require_locales.escapeHtml(attribute) : attribute;
45
+ }
46
+ return escaped;
47
+ };
48
+ const generateTypedText = (value, rawType) => {
49
+ const type = require_utils.generatePlainString(rawType);
50
+ if (type !== "xhtml") return {
51
+ ...require_utils.generateTextOrCdataString(value),
52
+ "@type": type
53
+ };
54
+ const xhtml = generateXhtmlValue(value);
55
+ if (xhtml || !require_is.isNonEmptyString(value)) return {
56
+ ...xhtml,
57
+ "@type": "xhtml"
58
+ };
59
+ return {
60
+ ...require_utils.generateTextOrCdataString(value),
61
+ "@type": "html"
62
+ };
63
+ };
30
64
  const generateText = (text) => {
31
65
  if (!require_is.isPlainObject(text)) return;
32
- return require_utils.trimObject({
33
- ...require_utils.generateTextOrCdataString(text.value),
34
- "@type": require_utils.generatePlainString(text.type),
66
+ const typed = generateTypedText(text.value, text.type);
67
+ if (!typed?.["#text"] && !typed?.["#cdata"]) return;
68
+ const value = {
69
+ ...typed,
35
70
  ...require_utils$21.generateItemOrFeed(text.xml)
36
- });
71
+ };
72
+ return require_utils.trimObject(escapeStopNodeAttributes(value));
37
73
  };
38
74
  const generateContent = (content) => {
39
75
  if (!require_is.isPlainObject(content)) return;
40
- return require_utils.trimObject({
41
- ...require_utils.generateTextOrCdataString(content.value),
42
- "@type": require_utils.generatePlainString(content.type),
76
+ const value = {
77
+ ...generateTypedText(content.value, content.type),
43
78
  "@src": require_utils.generatePlainString(content.src),
44
79
  ...require_utils$21.generateItemOrFeed(content.xml)
45
- });
80
+ };
81
+ return require_utils.trimObject(escapeStopNodeAttributes(value));
46
82
  };
47
83
  const generateLink = (link) => {
48
84
  if (!require_is.isPlainObject(link)) return;
@@ -201,3 +237,4 @@ exports.generateLink = generateLink;
201
237
  exports.generatePerson = generatePerson;
202
238
  exports.generateSource = generateSource;
203
239
  exports.generateText = generateText;
240
+ exports.generateXhtmlValue = generateXhtmlValue;
@@ -1,6 +1,7 @@
1
- import { isPlainObject } from "../../../node_modules/trousse/dist/is.js";
1
+ import { isNonEmptyString, isPlainObject } from "../../../node_modules/trousse/dist/is.js";
2
+ import { escapeHtml } from "../../../node_modules/trousse/dist/locales.js";
2
3
  import { namespaceUris } from "../../../common/config.js";
3
- import { generateCdataString, generateNamespaceAttrs, generateNumber, generatePlainString, generateRfc3339Date, generateTextOrCdataString, trimArray, trimObject } from "../../../common/utils.js";
4
+ import { generateCdataString, generateNamespaceAttrs, generateNumber, generatePlainString, generateRfc3339Date, generateTextOrCdataString, isXmlAttributeKey, trimArray, trimObject } from "../../../common/utils.js";
4
5
  import { generateFeed as generateFeed$1 } from "../../../namespaces/admin/generate/utils.js";
5
6
  import { generateEntry as generateEntry$1 } from "../../../namespaces/app/generate/utils.js";
6
7
  import { generateAuthor, generateEntry as generateEntry$2 } from "../../../namespaces/arxiv/generate/utils.js";
@@ -23,26 +24,61 @@ import { generateItem as generateItem$6 } from "../../../namespaces/trackback/ge
23
24
  import { generateItem as generateItem$7 } from "../../../namespaces/wfw/generate/utils.js";
24
25
  import { generateItemOrFeed as generateItemOrFeed$7 } from "../../../namespaces/xml/generate/utils.js";
25
26
  import { generateFeed as generateFeed$7, generateItem as generateItem$8 } from "../../../namespaces/yt/generate/utils.js";
27
+ import { XMLValidator } from "fast-xml-parser";
26
28
  //#region src/feeds/atom/generate/utils.ts
27
29
  const createNamespaceSetter = (prefix) => {
28
30
  return (key) => prefix ? `${prefix}${key}` : key;
29
31
  };
32
+ const nonXmlEntityRegex = /&(?!(?:amp|lt|gt|quot|apos);|#\d+;|#x[0-9a-fA-F]+;)[^;\s&<]+;/;
33
+ const generateXhtmlValue = (value) => {
34
+ if (!isNonEmptyString(value)) return;
35
+ const wrapped = `<div xmlns="http://www.w3.org/1999/xhtml">${value.trim().replace(/\r/g, "&#13;")}</div>`;
36
+ if (XMLValidator.validate(wrapped) !== true || nonXmlEntityRegex.test(wrapped)) return;
37
+ return { "#text": `${wrapped}\n` };
38
+ };
39
+ const escapeStopNodeAttributes = (value) => {
40
+ if (value["@type"] !== "xhtml") return value;
41
+ const escaped = {};
42
+ for (const key in value) {
43
+ const attribute = value[key];
44
+ escaped[key] = isXmlAttributeKey(key) && typeof attribute === "string" ? escapeHtml(attribute) : attribute;
45
+ }
46
+ return escaped;
47
+ };
48
+ const generateTypedText = (value, rawType) => {
49
+ const type = generatePlainString(rawType);
50
+ if (type !== "xhtml") return {
51
+ ...generateTextOrCdataString(value),
52
+ "@type": type
53
+ };
54
+ const xhtml = generateXhtmlValue(value);
55
+ if (xhtml || !isNonEmptyString(value)) return {
56
+ ...xhtml,
57
+ "@type": "xhtml"
58
+ };
59
+ return {
60
+ ...generateTextOrCdataString(value),
61
+ "@type": "html"
62
+ };
63
+ };
30
64
  const generateText = (text) => {
31
65
  if (!isPlainObject(text)) return;
32
- return trimObject({
33
- ...generateTextOrCdataString(text.value),
34
- "@type": generatePlainString(text.type),
66
+ const typed = generateTypedText(text.value, text.type);
67
+ if (!typed?.["#text"] && !typed?.["#cdata"]) return;
68
+ const value = {
69
+ ...typed,
35
70
  ...generateItemOrFeed$7(text.xml)
36
- });
71
+ };
72
+ return trimObject(escapeStopNodeAttributes(value));
37
73
  };
38
74
  const generateContent = (content) => {
39
75
  if (!isPlainObject(content)) return;
40
- return trimObject({
41
- ...generateTextOrCdataString(content.value),
42
- "@type": generatePlainString(content.type),
76
+ const value = {
77
+ ...generateTypedText(content.value, content.type),
43
78
  "@src": generatePlainString(content.src),
44
79
  ...generateItemOrFeed$7(content.xml)
45
- });
80
+ };
81
+ return trimObject(escapeStopNodeAttributes(value));
46
82
  };
47
83
  const generateLink = (link) => {
48
84
  if (!isPlainObject(link)) return;
@@ -191,4 +227,4 @@ const generateFeed = (feed, options) => {
191
227
  } };
192
228
  };
193
229
  //#endregion
194
- export { createNamespaceSetter, generateCategory, generateContent, generateEntry, generateFeed, generateGenerator, generateLink, generatePerson, generateSource, generateText };
230
+ export { createNamespaceSetter, generateCategory, generateContent, generateEntry, generateFeed, generateGenerator, generateLink, generatePerson, generateSource, generateText, generateXhtmlValue };
@@ -1,79 +1,9 @@
1
- const require_config = require("../../../common/config.cjs");
2
- const require_utils = require("../../../common/utils.cjs");
3
- let fast_xml_parser = require("fast-xml-parser");
1
+ const require_config = require("../../../namespaces/atom/common/config.cjs");
4
2
  //#region src/feeds/atom/parse/config.ts
5
3
  const stopNodes = [
6
- ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
7
- "feed",
8
- "feed.entry",
9
- "feed.entry.source"
10
- ]),
11
- "feed.author.name",
12
- "feed.author.uri",
13
- "feed.author.url",
14
- "feed.author.email",
15
- "feed.category",
16
- "feed.contributor.name",
17
- "feed.contributor.uri",
18
- "feed.contributor.url",
19
- "feed.contributor.email",
20
- "feed.generator",
21
- "feed.icon",
22
- "feed.id",
23
- "feed.link",
24
- "feed.logo",
25
- "feed.rights",
26
- "feed.subtitle",
27
- "feed.tagline",
28
- "feed.title",
29
- "feed.updated",
30
- "feed.modified",
31
- "feed.entry.author.name",
32
- "feed.entry.author.uri",
33
- "feed.entry.author.url",
34
- "feed.entry.author.email",
35
- "feed.entry.category",
36
- "feed.entry.content",
37
- "feed.entry.contributor.name",
38
- "feed.entry.contributor.uri",
39
- "feed.entry.contributor.url",
40
- "feed.entry.contributor.email",
41
- "feed.entry.id",
42
- "feed.entry.link",
43
- "feed.entry.published",
44
- "feed.entry.issued",
45
- "feed.entry.created",
46
- "feed.entry.rights",
47
- "feed.entry.source.author.name",
48
- "feed.entry.source.author.uri",
49
- "feed.entry.source.author.url",
50
- "feed.entry.source.author.email",
51
- "feed.entry.source.category",
52
- "feed.entry.source.contributor.name",
53
- "feed.entry.source.contributor.uri",
54
- "feed.entry.source.contributor.url",
55
- "feed.entry.source.contributor.email",
56
- "feed.entry.source.generator",
57
- "feed.entry.source.icon",
58
- "feed.entry.source.id",
59
- "feed.entry.source.link",
60
- "feed.entry.source.logo",
61
- "feed.entry.source.rights",
62
- "feed.entry.source.subtitle",
63
- "feed.entry.source.title",
64
- "feed.entry.source.updated",
65
- "feed.entry.source.modified",
66
- "feed.entry.summary",
67
- "feed.entry.title",
68
- "feed.entry.updated",
69
- "feed.entry.modified"
4
+ ...require("../../../common/config.cjs").namespaceStopNodes,
5
+ ...require_config.feedPaths.map((path) => `feed.${path}`),
6
+ ...require_config.entryPaths.map((path) => `feed.entry.${path}`)
70
7
  ];
71
- const parser = new fast_xml_parser.XMLParser({
72
- ...require_config.parserConfig,
73
- stopNodes
74
- });
75
- const normalizeNamespaces = require_utils.createNamespaceNormalizator(require_config.namespaceUris, require_config.namespacePrefixes, ["atom"]);
76
8
  //#endregion
77
- exports.normalizeNamespaces = normalizeNamespaces;
78
- exports.parser = parser;
79
9
  exports.stopNodes = stopNodes;