feedsmith 2.9.1 → 3.0.0-beta.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.
- package/README.md +3 -9
- package/dist/common/config.cjs +2 -1
- package/dist/common/config.js +2 -1
- package/dist/common/errors.cjs +30 -0
- package/dist/common/errors.d.cts +15 -0
- package/dist/common/errors.d.ts +15 -0
- package/dist/common/errors.js +27 -0
- package/dist/common/parse.cjs +2 -1
- package/dist/common/parse.d.cts +10 -11
- package/dist/common/parse.d.ts +10 -11
- package/dist/common/parse.js +2 -1
- package/dist/common/types.d.cts +24 -12
- package/dist/common/types.d.ts +24 -12
- package/dist/common/utils.cjs +65 -34
- package/dist/common/utils.js +66 -33
- package/dist/feeds/atom/common/types.d.cts +65 -52
- package/dist/feeds/atom/common/types.d.ts +65 -52
- package/dist/feeds/atom/detect/index.cjs +4 -2
- package/dist/feeds/atom/detect/index.js +4 -2
- package/dist/feeds/atom/generate/index.cjs +2 -1
- package/dist/feeds/atom/generate/index.d.cts +2 -2
- package/dist/feeds/atom/generate/index.d.ts +2 -2
- package/dist/feeds/atom/generate/index.js +2 -1
- package/dist/feeds/atom/generate/utils.cjs +23 -6
- package/dist/feeds/atom/generate/utils.js +20 -3
- package/dist/feeds/atom/parse/index.cjs +10 -3
- package/dist/feeds/atom/parse/index.d.cts +2 -2
- package/dist/feeds/atom/parse/index.d.ts +2 -2
- package/dist/feeds/atom/parse/index.js +10 -3
- package/dist/feeds/atom/parse/utils.cjs +61 -31
- package/dist/feeds/atom/parse/utils.js +59 -29
- package/dist/feeds/json/common/types.d.cts +19 -19
- package/dist/feeds/json/common/types.d.ts +19 -19
- package/dist/feeds/json/generate/index.cjs +5 -1
- package/dist/feeds/json/generate/index.d.cts +2 -2
- package/dist/feeds/json/generate/index.d.ts +2 -2
- package/dist/feeds/json/generate/index.js +5 -1
- package/dist/feeds/json/generate/utils.cjs +7 -2
- package/dist/feeds/json/generate/utils.js +8 -3
- package/dist/feeds/json/parse/index.cjs +3 -2
- package/dist/feeds/json/parse/index.d.cts +2 -2
- package/dist/feeds/json/parse/index.d.ts +2 -2
- package/dist/feeds/json/parse/index.js +3 -2
- package/dist/feeds/json/parse/utils.cjs +4 -4
- package/dist/feeds/json/parse/utils.js +4 -4
- package/dist/feeds/rdf/common/types.d.cts +31 -28
- package/dist/feeds/rdf/common/types.d.ts +31 -28
- package/dist/feeds/rdf/detect/index.cjs +4 -2
- package/dist/feeds/rdf/detect/index.js +4 -2
- package/dist/feeds/rdf/parse/index.cjs +10 -3
- package/dist/feeds/rdf/parse/index.d.cts +2 -2
- package/dist/feeds/rdf/parse/index.d.ts +2 -2
- package/dist/feeds/rdf/parse/index.js +10 -3
- package/dist/feeds/rdf/parse/utils.cjs +23 -20
- package/dist/feeds/rdf/parse/utils.js +15 -12
- package/dist/feeds/rss/common/types.d.cts +76 -74
- package/dist/feeds/rss/common/types.d.ts +76 -74
- package/dist/feeds/rss/detect/index.cjs +6 -3
- package/dist/feeds/rss/detect/index.js +6 -3
- package/dist/feeds/rss/generate/index.cjs +2 -1
- package/dist/feeds/rss/generate/index.d.cts +2 -2
- package/dist/feeds/rss/generate/index.d.ts +2 -2
- package/dist/feeds/rss/generate/index.js +2 -1
- package/dist/feeds/rss/generate/utils.cjs +36 -36
- package/dist/feeds/rss/generate/utils.js +10 -10
- package/dist/feeds/rss/parse/index.cjs +10 -3
- package/dist/feeds/rss/parse/index.d.cts +2 -2
- package/dist/feeds/rss/parse/index.d.ts +2 -2
- package/dist/feeds/rss/parse/index.js +10 -3
- package/dist/feeds/rss/parse/utils.cjs +138 -38
- package/dist/feeds/rss/parse/utils.js +119 -19
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +37 -16
- package/dist/index.d.ts +37 -16
- package/dist/index.js +2 -1
- package/dist/namespaces/app/common/types.d.cts +1 -3
- package/dist/namespaces/app/common/types.d.ts +1 -3
- package/dist/namespaces/app/parse/utils.cjs +2 -2
- package/dist/namespaces/app/parse/utils.js +2 -2
- package/dist/namespaces/atom/common/types.d.cts +3 -3
- package/dist/namespaces/atom/common/types.d.ts +3 -3
- package/dist/namespaces/atom/parse/utils.cjs +4 -2
- package/dist/namespaces/atom/parse/utils.js +4 -2
- package/dist/namespaces/dc/common/types.d.cts +4 -19
- package/dist/namespaces/dc/common/types.d.ts +4 -19
- package/dist/namespaces/dc/generate/utils.cjs +15 -15
- package/dist/namespaces/dc/generate/utils.js +16 -16
- package/dist/namespaces/dc/parse/utils.cjs +4 -17
- package/dist/namespaces/dc/parse/utils.js +5 -18
- package/dist/namespaces/dcterms/common/types.d.cts +23 -59
- package/dist/namespaces/dcterms/common/types.d.ts +23 -59
- package/dist/namespaces/dcterms/generate/utils.cjs +55 -55
- package/dist/namespaces/dcterms/generate/utils.js +56 -56
- package/dist/namespaces/dcterms/parse/utils.cjs +23 -57
- package/dist/namespaces/dcterms/parse/utils.js +24 -58
- package/dist/namespaces/georss/common/types.d.cts +21 -19
- package/dist/namespaces/georss/common/types.d.ts +21 -19
- package/dist/namespaces/georss/generate/utils.cjs +2 -2
- package/dist/namespaces/georss/generate/utils.js +2 -2
- package/dist/namespaces/georss/parse/utils.cjs +2 -1
- package/dist/namespaces/georss/parse/utils.js +2 -1
- package/dist/namespaces/googleplay/common/types.d.cts +9 -7
- package/dist/namespaces/googleplay/common/types.d.ts +9 -7
- package/dist/namespaces/itunes/common/types.d.cts +9 -5
- package/dist/namespaces/itunes/common/types.d.ts +9 -5
- package/dist/namespaces/itunes/parse/utils.cjs +3 -2
- package/dist/namespaces/itunes/parse/utils.js +3 -2
- package/dist/namespaces/media/common/types.d.cts +85 -84
- package/dist/namespaces/media/common/types.d.ts +85 -84
- package/dist/namespaces/media/generate/utils.cjs +1 -1
- package/dist/namespaces/media/generate/utils.js +2 -2
- package/dist/namespaces/media/parse/utils.cjs +1 -2
- package/dist/namespaces/media/parse/utils.js +1 -2
- package/dist/namespaces/opensearch/common/types.d.cts +7 -5
- package/dist/namespaces/opensearch/common/types.d.ts +7 -5
- package/dist/namespaces/podcast/common/types.d.cts +136 -142
- package/dist/namespaces/podcast/common/types.d.ts +136 -142
- package/dist/namespaces/podcast/generate/utils.cjs +6 -6
- package/dist/namespaces/podcast/generate/utils.js +7 -7
- package/dist/namespaces/podcast/parse/utils.cjs +17 -21
- package/dist/namespaces/podcast/parse/utils.js +17 -21
- package/dist/namespaces/prism/common/types.d.cts +2 -4
- package/dist/namespaces/prism/common/types.d.ts +2 -4
- package/dist/namespaces/prism/parse/utils.cjs +19 -19
- package/dist/namespaces/prism/parse/utils.js +19 -19
- package/dist/namespaces/psc/common/types.d.cts +8 -6
- package/dist/namespaces/psc/common/types.d.ts +8 -6
- package/dist/namespaces/rawvoice/common/types.d.cts +24 -24
- package/dist/namespaces/rawvoice/common/types.d.ts +24 -24
- package/dist/namespaces/rawvoice/parse/utils.cjs +8 -8
- package/dist/namespaces/rawvoice/parse/utils.js +8 -8
- package/dist/namespaces/source/common/types.d.cts +20 -18
- package/dist/namespaces/source/common/types.d.ts +20 -18
- package/dist/namespaces/spotify/common/types.d.cts +22 -20
- package/dist/namespaces/spotify/common/types.d.ts +22 -20
- package/dist/namespaces/sy/common/types.d.cts +1 -3
- package/dist/namespaces/sy/common/types.d.ts +1 -3
- package/dist/namespaces/sy/parse/utils.cjs +2 -2
- package/dist/namespaces/sy/parse/utils.js +2 -2
- package/dist/namespaces/thr/common/types.d.cts +7 -7
- package/dist/namespaces/thr/common/types.d.ts +7 -7
- package/dist/namespaces/thr/parse/utils.cjs +2 -2
- package/dist/namespaces/thr/parse/utils.js +2 -2
- package/dist/namespaces/xml/common/types.d.cts +11 -0
- package/dist/namespaces/xml/common/types.d.ts +11 -0
- package/dist/namespaces/xml/generate/utils.cjs +13 -0
- package/dist/namespaces/xml/generate/utils.js +13 -0
- package/dist/namespaces/xml/parse/utils.cjs +13 -0
- package/dist/namespaces/xml/parse/utils.js +13 -0
- package/dist/opml/common/types.d.cts +18 -13
- package/dist/opml/common/types.d.ts +18 -13
- package/dist/opml/generate/index.cjs +2 -1
- package/dist/opml/generate/index.d.cts +3 -3
- package/dist/opml/generate/index.d.ts +3 -3
- package/dist/opml/generate/index.js +2 -1
- package/dist/opml/parse/index.cjs +9 -2
- package/dist/opml/parse/index.d.cts +2 -3
- package/dist/opml/parse/index.d.ts +2 -3
- package/dist/opml/parse/index.js +9 -2
- package/dist/opml/parse/utils.cjs +5 -5
- package/dist/opml/parse/utils.js +5 -5
- package/package.json +7 -24
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +0 -7
- package/dist/types.d.ts +0 -7
- package/dist/types.js +0 -1
package/dist/common/utils.js
CHANGED
|
@@ -26,13 +26,19 @@ const retrieveRdfResourceOrText = (value, parse) => {
|
|
|
26
26
|
return parse(retrieveText(value));
|
|
27
27
|
};
|
|
28
28
|
const trimObject = (object) => {
|
|
29
|
-
let
|
|
29
|
+
let hasPresent = false;
|
|
30
|
+
let hasAbsent = false;
|
|
31
|
+
for (const key in object) {
|
|
32
|
+
if (isPresent(object[key])) hasPresent = true;
|
|
33
|
+
else hasAbsent = true;
|
|
34
|
+
if (hasPresent && hasAbsent) break;
|
|
35
|
+
}
|
|
36
|
+
if (!hasPresent) return;
|
|
37
|
+
if (!hasAbsent) return object;
|
|
38
|
+
const result = {};
|
|
30
39
|
for (const key in object) {
|
|
31
40
|
const value = object[key];
|
|
32
|
-
if (isPresent(value))
|
|
33
|
-
if (!result) result = {};
|
|
34
|
-
result[key] = value;
|
|
35
|
-
}
|
|
41
|
+
if (isPresent(value)) result[key] = value;
|
|
36
42
|
}
|
|
37
43
|
return result;
|
|
38
44
|
};
|
|
@@ -40,31 +46,23 @@ const trimArray = (value, parse) => {
|
|
|
40
46
|
if (!Array.isArray(value) || value.length === 0) return;
|
|
41
47
|
if (!parse) {
|
|
42
48
|
let needsTrimming = false;
|
|
43
|
-
for (
|
|
49
|
+
for (const item of value) if (!isPresent(item)) {
|
|
44
50
|
needsTrimming = true;
|
|
45
51
|
break;
|
|
46
52
|
}
|
|
47
53
|
if (!needsTrimming) return value;
|
|
48
54
|
}
|
|
49
55
|
const result = [];
|
|
50
|
-
for (
|
|
51
|
-
const item = parse ? parse(
|
|
56
|
+
for (const element of value) {
|
|
57
|
+
const item = parse ? parse(element) : element;
|
|
52
58
|
if (isPresent(item)) result.push(item);
|
|
53
59
|
}
|
|
54
60
|
return result.length > 0 ? result : void 0;
|
|
55
61
|
};
|
|
56
|
-
const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
|
|
57
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
58
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
59
|
-
};
|
|
60
|
-
const generateSingularOrArray = (singularValue, pluralValues, generator) => {
|
|
61
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
62
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
63
|
-
};
|
|
64
|
-
const commentStartTag = "<!--";
|
|
65
|
-
const commentEndTag = "-->";
|
|
66
62
|
const cdataStartTag = "<![CDATA[";
|
|
67
63
|
const cdataEndTag = "]]>";
|
|
64
|
+
const commentStartTag = "<!--";
|
|
65
|
+
const commentEndTag = "-->";
|
|
68
66
|
const hasEntities = (text) => {
|
|
69
67
|
const ampIndex = text.indexOf("&");
|
|
70
68
|
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
@@ -75,13 +73,13 @@ const stripComments = (text) => {
|
|
|
75
73
|
let result = "";
|
|
76
74
|
let lastIndex = 0;
|
|
77
75
|
while (currentIndex !== -1) {
|
|
78
|
-
result += text.
|
|
76
|
+
result += text.slice(lastIndex, currentIndex);
|
|
79
77
|
const endIndex = text.indexOf(commentEndTag, currentIndex + 4);
|
|
80
78
|
if (endIndex === -1) return text;
|
|
81
79
|
lastIndex = endIndex + 3;
|
|
82
80
|
currentIndex = text.indexOf(commentStartTag, lastIndex);
|
|
83
81
|
}
|
|
84
|
-
result += text.
|
|
82
|
+
result += text.slice(lastIndex);
|
|
85
83
|
return result;
|
|
86
84
|
};
|
|
87
85
|
const decodeWithCdata = (text) => {
|
|
@@ -90,15 +88,15 @@ const decodeWithCdata = (text) => {
|
|
|
90
88
|
let result = "";
|
|
91
89
|
let lastIndex = 0;
|
|
92
90
|
while (currentIndex !== -1) {
|
|
93
|
-
const textBefore = text.
|
|
91
|
+
const textBefore = text.slice(lastIndex, currentIndex);
|
|
94
92
|
result += hasEntities(textBefore) ? decodeHTML(textBefore) : textBefore;
|
|
95
93
|
const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
|
|
96
94
|
if (endIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
|
|
97
|
-
result += text.
|
|
95
|
+
result += text.slice(currentIndex + 9, endIndex);
|
|
98
96
|
lastIndex = endIndex + 3;
|
|
99
97
|
currentIndex = text.indexOf(cdataStartTag, lastIndex);
|
|
100
98
|
}
|
|
101
|
-
const textAfter = text.
|
|
99
|
+
const textAfter = text.slice(lastIndex);
|
|
102
100
|
result += hasEntities(textAfter) ? decodeHTML(textAfter) : textAfter;
|
|
103
101
|
return result;
|
|
104
102
|
};
|
|
@@ -131,8 +129,10 @@ const parseYesNoBoolean = (value) => {
|
|
|
131
129
|
if (boolean !== void 0) return boolean;
|
|
132
130
|
if (isNonEmptyString(value)) return yesRegex.test(value);
|
|
133
131
|
};
|
|
134
|
-
const parseDate = (value) => {
|
|
135
|
-
|
|
132
|
+
const parseDate = (value, parseDateFn) => {
|
|
133
|
+
const raw = parseString(value);
|
|
134
|
+
if (raw === void 0) return;
|
|
135
|
+
return parseDateFn ? parseDateFn(raw) : raw;
|
|
136
136
|
};
|
|
137
137
|
const parseArray = (value) => {
|
|
138
138
|
if (Array.isArray(value)) return value;
|
|
@@ -300,7 +300,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
300
300
|
if (isObject(element)) {
|
|
301
301
|
for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
|
|
302
302
|
else if (key.indexOf("@xmlns:") === 0) {
|
|
303
|
-
const prefix = key.
|
|
303
|
+
const prefix = key.slice(7);
|
|
304
304
|
declarations[prefix] = normalizeNamespaceUri(element[key]);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
@@ -312,14 +312,14 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
312
312
|
if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
|
|
313
313
|
return name;
|
|
314
314
|
}
|
|
315
|
-
const prefix = name.
|
|
316
|
-
const unprefixedName = name.
|
|
315
|
+
const prefix = name.slice(0, colonIndex);
|
|
316
|
+
const unprefixedName = name.slice(colonIndex + 1);
|
|
317
317
|
const uri = context[prefix];
|
|
318
318
|
if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
|
|
319
319
|
return name;
|
|
320
320
|
};
|
|
321
321
|
const normalizeKey = (key, context) => {
|
|
322
|
-
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.
|
|
322
|
+
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.slice(1), context, false)}`;
|
|
323
323
|
return normalizeWithContext(key, context, true);
|
|
324
324
|
};
|
|
325
325
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
@@ -352,9 +352,40 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
352
352
|
}
|
|
353
353
|
return normalizedObject;
|
|
354
354
|
};
|
|
355
|
+
const needsNormalization = (object) => {
|
|
356
|
+
const check = (value) => {
|
|
357
|
+
if (Array.isArray(value)) {
|
|
358
|
+
for (const item of value) if (check(item)) return true;
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
if (!isObject(value)) return false;
|
|
362
|
+
for (const key in value) {
|
|
363
|
+
if (key[0] === "@") {
|
|
364
|
+
if (key === "@xmlns") {
|
|
365
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
366
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) continue;
|
|
367
|
+
if (namespacePrefixes[normalizedUri]) return true;
|
|
368
|
+
} else if (key.startsWith("@xmlns:")) {
|
|
369
|
+
const prefix = key.slice(7);
|
|
370
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
371
|
+
const standardPrefix = namespacePrefixes[normalizedUri];
|
|
372
|
+
if (standardPrefix) {
|
|
373
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) return true;
|
|
374
|
+
if (standardPrefix !== prefix) return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (key[0] === "#") continue;
|
|
380
|
+
if (check(value[key])) return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
};
|
|
384
|
+
return check(object);
|
|
385
|
+
};
|
|
355
386
|
const normalizeRoot = (object) => {
|
|
356
387
|
if (!isObject(object)) return object;
|
|
357
|
-
if (
|
|
388
|
+
if (!needsNormalization(object)) return object;
|
|
358
389
|
const normalizedObject = {};
|
|
359
390
|
for (const key in object) {
|
|
360
391
|
const value = object[key];
|
|
@@ -366,15 +397,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
366
397
|
};
|
|
367
398
|
return normalizeRoot;
|
|
368
399
|
};
|
|
400
|
+
const startsWithBraceRegex = /^\s*\{/;
|
|
401
|
+
const endsWithBraceRegex = /\}\s*$/;
|
|
369
402
|
const parseJsonObject = (value) => {
|
|
370
403
|
if (isObject(value)) return value;
|
|
371
404
|
if (!isNonEmptyString(value) || value.length < 2) return;
|
|
372
|
-
const startsWithBrace = value.charAt(0) === "{" ||
|
|
373
|
-
const endsWithBrace = value.charAt(value.length - 1) === "}" ||
|
|
405
|
+
const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
|
|
406
|
+
const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
|
|
374
407
|
if (!startsWithBrace || !endsWithBrace) return;
|
|
375
408
|
try {
|
|
376
409
|
return JSON.parse(value);
|
|
377
410
|
} catch {}
|
|
378
411
|
};
|
|
379
412
|
//#endregion
|
|
380
|
-
export { createNamespaceNormalizator, detectNamespaces,
|
|
413
|
+
export { createNamespaceNormalizator, detectNamespaces, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateTextOrCdataString, generateXml, generateYesNoBoolean, isNonEmptyString, isNonEmptyStringOrNumber, isObject, isPresent, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Requirable, Strict } from "../../../common/types.cjs";
|
|
2
2
|
import { AdminNs } from "../../../namespaces/admin/common/types.cjs";
|
|
3
3
|
import { AppNs } from "../../../namespaces/app/common/types.cjs";
|
|
4
4
|
import { ArxivNs } from "../../../namespaces/arxiv/common/types.cjs";
|
|
@@ -19,111 +19,124 @@ import { SyNs } from "../../../namespaces/sy/common/types.cjs";
|
|
|
19
19
|
import { ThrNs } from "../../../namespaces/thr/common/types.cjs";
|
|
20
20
|
import { TrackbackNs } from "../../../namespaces/trackback/common/types.cjs";
|
|
21
21
|
import { WfwNs } from "../../../namespaces/wfw/common/types.cjs";
|
|
22
|
+
import { XmlNs } from "../../../namespaces/xml/common/types.cjs";
|
|
22
23
|
import { YtNs } from "../../../namespaces/yt/common/types.cjs";
|
|
23
24
|
|
|
24
25
|
//#region src/feeds/atom/common/types.d.ts
|
|
25
26
|
declare namespace Atom {
|
|
26
|
-
type Text =
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
type Text = {
|
|
28
|
+
value: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
xml?: XmlNs.ItemOrFeed;
|
|
31
|
+
};
|
|
32
|
+
type Content = {
|
|
33
|
+
value?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
src?: string;
|
|
36
|
+
xml?: XmlNs.ItemOrFeed;
|
|
37
|
+
};
|
|
38
|
+
type Link<TDate, TStrict extends boolean = false> = Strict<{
|
|
39
|
+
href: Requirable<string>;
|
|
29
40
|
rel?: string;
|
|
30
41
|
type?: string;
|
|
31
42
|
hreflang?: string;
|
|
32
43
|
title?: string;
|
|
33
44
|
length?: number;
|
|
34
45
|
thr?: ThrNs.Link<TDate>;
|
|
35
|
-
}
|
|
36
|
-
type Person = {
|
|
37
|
-
name: string
|
|
46
|
+
}, TStrict>;
|
|
47
|
+
type Person<TStrict extends boolean = false> = Strict<{
|
|
48
|
+
name: Requirable<string>;
|
|
38
49
|
uri?: string;
|
|
39
50
|
email?: string;
|
|
40
51
|
arxiv?: ArxivNs.Author;
|
|
41
|
-
}
|
|
42
|
-
type Category = {
|
|
43
|
-
term: string
|
|
52
|
+
}, TStrict>;
|
|
53
|
+
type Category<TStrict extends boolean = false> = Strict<{
|
|
54
|
+
term: Requirable<string>;
|
|
44
55
|
scheme?: string;
|
|
45
56
|
label?: string;
|
|
46
|
-
}
|
|
47
|
-
type Generator = {
|
|
48
|
-
text: string
|
|
57
|
+
}, TStrict>;
|
|
58
|
+
type Generator<TStrict extends boolean = false> = Strict<{
|
|
59
|
+
text: Requirable<string>;
|
|
49
60
|
uri?: string;
|
|
50
61
|
version?: string;
|
|
51
|
-
}
|
|
52
|
-
type Source<TDate extends
|
|
53
|
-
authors?: Array<Person
|
|
54
|
-
categories?: Array<Category
|
|
55
|
-
contributors?: Array<Person
|
|
56
|
-
generator?: Generator
|
|
62
|
+
}, TStrict>;
|
|
63
|
+
type Source<TDate, TStrict extends boolean = false> = {
|
|
64
|
+
authors?: Array<Person<TStrict>>;
|
|
65
|
+
categories?: Array<Category<TStrict>>;
|
|
66
|
+
contributors?: Array<Person<TStrict>>;
|
|
67
|
+
generator?: Generator<TStrict>;
|
|
57
68
|
icon?: string;
|
|
58
69
|
id?: string;
|
|
59
|
-
links?: Array<Link<TDate>>;
|
|
70
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
60
71
|
logo?: string;
|
|
61
72
|
rights?: Text;
|
|
62
73
|
subtitle?: Text;
|
|
63
74
|
title?: Text;
|
|
64
75
|
updated?: TDate;
|
|
65
76
|
};
|
|
66
|
-
type Entry<TDate extends
|
|
67
|
-
authors?: Array<Person
|
|
68
|
-
categories?: Array<Category
|
|
69
|
-
content?:
|
|
70
|
-
contributors?: Array<Person
|
|
71
|
-
id: string
|
|
72
|
-
links?: Array<Link<TDate>>;
|
|
77
|
+
type Entry<TDate, TStrict extends boolean = false> = Strict<{
|
|
78
|
+
authors?: Array<Person<TStrict>>;
|
|
79
|
+
categories?: Array<Category<TStrict>>;
|
|
80
|
+
content?: Content;
|
|
81
|
+
contributors?: Array<Person<TStrict>>;
|
|
82
|
+
id: Requirable<string>;
|
|
83
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
73
84
|
published?: TDate;
|
|
74
85
|
rights?: Text;
|
|
75
|
-
source?: Source<TDate>;
|
|
86
|
+
source?: Source<TDate, TStrict>;
|
|
76
87
|
summary?: Text;
|
|
77
|
-
title: Text
|
|
78
|
-
updated: TDate
|
|
88
|
+
title: Requirable<Text>;
|
|
89
|
+
updated: Requirable<TDate>;
|
|
79
90
|
app?: AppNs.Entry<TDate>;
|
|
80
91
|
arxiv?: ArxivNs.Entry;
|
|
81
92
|
cc?: CcNs.ItemOrFeed;
|
|
82
93
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
83
94
|
slash?: SlashNs.Item;
|
|
84
95
|
itunes?: ItunesNs.Item;
|
|
85
|
-
googleplay?: GooglePlayNs.Item
|
|
86
|
-
psc?: PscNs.Item
|
|
87
|
-
media?: MediaNs.ItemOrFeed
|
|
88
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
96
|
+
googleplay?: GooglePlayNs.Item<TStrict>;
|
|
97
|
+
psc?: PscNs.Item<TStrict>;
|
|
98
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
99
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
89
100
|
geo?: GeoNs.ItemOrFeed;
|
|
90
|
-
thr?: ThrNs.Item
|
|
101
|
+
thr?: ThrNs.Item<TStrict>;
|
|
91
102
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
92
103
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
93
104
|
wfw?: WfwNs.Item;
|
|
94
105
|
yt?: YtNs.Item;
|
|
95
106
|
pingback?: PingbackNs.Item;
|
|
96
107
|
trackback?: TrackbackNs.Item;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
xml?: XmlNs.ItemOrFeed;
|
|
109
|
+
}, TStrict>;
|
|
110
|
+
type Feed<TDate, TStrict extends boolean = false> = Strict<{
|
|
111
|
+
authors?: Array<Person<TStrict>>;
|
|
112
|
+
categories?: Array<Category<TStrict>>;
|
|
113
|
+
contributors?: Array<Person<TStrict>>;
|
|
114
|
+
generator?: Generator<TStrict>;
|
|
103
115
|
icon?: string;
|
|
104
|
-
id: string
|
|
105
|
-
links?: Array<Link<TDate>>;
|
|
116
|
+
id: Requirable<string>;
|
|
117
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
106
118
|
logo?: string;
|
|
107
119
|
rights?: Text;
|
|
108
120
|
subtitle?: Text;
|
|
109
|
-
title: Text
|
|
110
|
-
updated: TDate
|
|
111
|
-
entries?: Array<Entry<TDate>>;
|
|
121
|
+
title: Requirable<Text>;
|
|
122
|
+
updated: Requirable<TDate>;
|
|
123
|
+
entries?: Array<Entry<TDate, TStrict>>;
|
|
112
124
|
cc?: CcNs.ItemOrFeed;
|
|
113
125
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
114
126
|
sy?: SyNs.Feed<TDate>;
|
|
115
|
-
itunes?: ItunesNs.Feed
|
|
116
|
-
googleplay?: GooglePlayNs.Feed
|
|
117
|
-
media?: MediaNs.ItemOrFeed
|
|
118
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
127
|
+
itunes?: ItunesNs.Feed<TStrict>;
|
|
128
|
+
googleplay?: GooglePlayNs.Feed<TStrict>;
|
|
129
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
130
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
119
131
|
geo?: GeoNs.ItemOrFeed;
|
|
120
132
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
121
133
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
122
|
-
opensearch?: OpenSearchNs.Feed
|
|
134
|
+
opensearch?: OpenSearchNs.Feed<TStrict>;
|
|
123
135
|
yt?: YtNs.Feed;
|
|
124
136
|
admin?: AdminNs.Feed;
|
|
125
137
|
pingback?: PingbackNs.Feed;
|
|
126
|
-
|
|
138
|
+
xml?: XmlNs.ItemOrFeed;
|
|
139
|
+
}, TStrict>;
|
|
127
140
|
}
|
|
128
141
|
//#endregion
|
|
129
142
|
export { Atom };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Requirable, Strict } from "../../../common/types.js";
|
|
2
2
|
import { AdminNs } from "../../../namespaces/admin/common/types.js";
|
|
3
3
|
import { AppNs } from "../../../namespaces/app/common/types.js";
|
|
4
4
|
import { ArxivNs } from "../../../namespaces/arxiv/common/types.js";
|
|
@@ -19,111 +19,124 @@ import { SyNs } from "../../../namespaces/sy/common/types.js";
|
|
|
19
19
|
import { ThrNs } from "../../../namespaces/thr/common/types.js";
|
|
20
20
|
import { TrackbackNs } from "../../../namespaces/trackback/common/types.js";
|
|
21
21
|
import { WfwNs } from "../../../namespaces/wfw/common/types.js";
|
|
22
|
+
import { XmlNs } from "../../../namespaces/xml/common/types.js";
|
|
22
23
|
import { YtNs } from "../../../namespaces/yt/common/types.js";
|
|
23
24
|
|
|
24
25
|
//#region src/feeds/atom/common/types.d.ts
|
|
25
26
|
declare namespace Atom {
|
|
26
|
-
type Text =
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
type Text = {
|
|
28
|
+
value: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
xml?: XmlNs.ItemOrFeed;
|
|
31
|
+
};
|
|
32
|
+
type Content = {
|
|
33
|
+
value?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
src?: string;
|
|
36
|
+
xml?: XmlNs.ItemOrFeed;
|
|
37
|
+
};
|
|
38
|
+
type Link<TDate, TStrict extends boolean = false> = Strict<{
|
|
39
|
+
href: Requirable<string>;
|
|
29
40
|
rel?: string;
|
|
30
41
|
type?: string;
|
|
31
42
|
hreflang?: string;
|
|
32
43
|
title?: string;
|
|
33
44
|
length?: number;
|
|
34
45
|
thr?: ThrNs.Link<TDate>;
|
|
35
|
-
}
|
|
36
|
-
type Person = {
|
|
37
|
-
name: string
|
|
46
|
+
}, TStrict>;
|
|
47
|
+
type Person<TStrict extends boolean = false> = Strict<{
|
|
48
|
+
name: Requirable<string>;
|
|
38
49
|
uri?: string;
|
|
39
50
|
email?: string;
|
|
40
51
|
arxiv?: ArxivNs.Author;
|
|
41
|
-
}
|
|
42
|
-
type Category = {
|
|
43
|
-
term: string
|
|
52
|
+
}, TStrict>;
|
|
53
|
+
type Category<TStrict extends boolean = false> = Strict<{
|
|
54
|
+
term: Requirable<string>;
|
|
44
55
|
scheme?: string;
|
|
45
56
|
label?: string;
|
|
46
|
-
}
|
|
47
|
-
type Generator = {
|
|
48
|
-
text: string
|
|
57
|
+
}, TStrict>;
|
|
58
|
+
type Generator<TStrict extends boolean = false> = Strict<{
|
|
59
|
+
text: Requirable<string>;
|
|
49
60
|
uri?: string;
|
|
50
61
|
version?: string;
|
|
51
|
-
}
|
|
52
|
-
type Source<TDate extends
|
|
53
|
-
authors?: Array<Person
|
|
54
|
-
categories?: Array<Category
|
|
55
|
-
contributors?: Array<Person
|
|
56
|
-
generator?: Generator
|
|
62
|
+
}, TStrict>;
|
|
63
|
+
type Source<TDate, TStrict extends boolean = false> = {
|
|
64
|
+
authors?: Array<Person<TStrict>>;
|
|
65
|
+
categories?: Array<Category<TStrict>>;
|
|
66
|
+
contributors?: Array<Person<TStrict>>;
|
|
67
|
+
generator?: Generator<TStrict>;
|
|
57
68
|
icon?: string;
|
|
58
69
|
id?: string;
|
|
59
|
-
links?: Array<Link<TDate>>;
|
|
70
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
60
71
|
logo?: string;
|
|
61
72
|
rights?: Text;
|
|
62
73
|
subtitle?: Text;
|
|
63
74
|
title?: Text;
|
|
64
75
|
updated?: TDate;
|
|
65
76
|
};
|
|
66
|
-
type Entry<TDate extends
|
|
67
|
-
authors?: Array<Person
|
|
68
|
-
categories?: Array<Category
|
|
69
|
-
content?:
|
|
70
|
-
contributors?: Array<Person
|
|
71
|
-
id: string
|
|
72
|
-
links?: Array<Link<TDate>>;
|
|
77
|
+
type Entry<TDate, TStrict extends boolean = false> = Strict<{
|
|
78
|
+
authors?: Array<Person<TStrict>>;
|
|
79
|
+
categories?: Array<Category<TStrict>>;
|
|
80
|
+
content?: Content;
|
|
81
|
+
contributors?: Array<Person<TStrict>>;
|
|
82
|
+
id: Requirable<string>;
|
|
83
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
73
84
|
published?: TDate;
|
|
74
85
|
rights?: Text;
|
|
75
|
-
source?: Source<TDate>;
|
|
86
|
+
source?: Source<TDate, TStrict>;
|
|
76
87
|
summary?: Text;
|
|
77
|
-
title: Text
|
|
78
|
-
updated: TDate
|
|
88
|
+
title: Requirable<Text>;
|
|
89
|
+
updated: Requirable<TDate>;
|
|
79
90
|
app?: AppNs.Entry<TDate>;
|
|
80
91
|
arxiv?: ArxivNs.Entry;
|
|
81
92
|
cc?: CcNs.ItemOrFeed;
|
|
82
93
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
83
94
|
slash?: SlashNs.Item;
|
|
84
95
|
itunes?: ItunesNs.Item;
|
|
85
|
-
googleplay?: GooglePlayNs.Item
|
|
86
|
-
psc?: PscNs.Item
|
|
87
|
-
media?: MediaNs.ItemOrFeed
|
|
88
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
96
|
+
googleplay?: GooglePlayNs.Item<TStrict>;
|
|
97
|
+
psc?: PscNs.Item<TStrict>;
|
|
98
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
99
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
89
100
|
geo?: GeoNs.ItemOrFeed;
|
|
90
|
-
thr?: ThrNs.Item
|
|
101
|
+
thr?: ThrNs.Item<TStrict>;
|
|
91
102
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
92
103
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
93
104
|
wfw?: WfwNs.Item;
|
|
94
105
|
yt?: YtNs.Item;
|
|
95
106
|
pingback?: PingbackNs.Item;
|
|
96
107
|
trackback?: TrackbackNs.Item;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
xml?: XmlNs.ItemOrFeed;
|
|
109
|
+
}, TStrict>;
|
|
110
|
+
type Feed<TDate, TStrict extends boolean = false> = Strict<{
|
|
111
|
+
authors?: Array<Person<TStrict>>;
|
|
112
|
+
categories?: Array<Category<TStrict>>;
|
|
113
|
+
contributors?: Array<Person<TStrict>>;
|
|
114
|
+
generator?: Generator<TStrict>;
|
|
103
115
|
icon?: string;
|
|
104
|
-
id: string
|
|
105
|
-
links?: Array<Link<TDate>>;
|
|
116
|
+
id: Requirable<string>;
|
|
117
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
106
118
|
logo?: string;
|
|
107
119
|
rights?: Text;
|
|
108
120
|
subtitle?: Text;
|
|
109
|
-
title: Text
|
|
110
|
-
updated: TDate
|
|
111
|
-
entries?: Array<Entry<TDate>>;
|
|
121
|
+
title: Requirable<Text>;
|
|
122
|
+
updated: Requirable<TDate>;
|
|
123
|
+
entries?: Array<Entry<TDate, TStrict>>;
|
|
112
124
|
cc?: CcNs.ItemOrFeed;
|
|
113
125
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
114
126
|
sy?: SyNs.Feed<TDate>;
|
|
115
|
-
itunes?: ItunesNs.Feed
|
|
116
|
-
googleplay?: GooglePlayNs.Feed
|
|
117
|
-
media?: MediaNs.ItemOrFeed
|
|
118
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
127
|
+
itunes?: ItunesNs.Feed<TStrict>;
|
|
128
|
+
googleplay?: GooglePlayNs.Feed<TStrict>;
|
|
129
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
130
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
119
131
|
geo?: GeoNs.ItemOrFeed;
|
|
120
132
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
121
133
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
122
|
-
opensearch?: OpenSearchNs.Feed
|
|
134
|
+
opensearch?: OpenSearchNs.Feed<TStrict>;
|
|
123
135
|
yt?: YtNs.Feed;
|
|
124
136
|
admin?: AdminNs.Feed;
|
|
125
137
|
pingback?: PingbackNs.Feed;
|
|
126
|
-
|
|
138
|
+
xml?: XmlNs.ItemOrFeed;
|
|
139
|
+
}, TStrict>;
|
|
127
140
|
}
|
|
128
141
|
//#endregion
|
|
129
142
|
export { Atom };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const require_config = require("../../../common/config.cjs");
|
|
2
2
|
const require_utils = require("../../../common/utils.cjs");
|
|
3
3
|
//#region src/feeds/atom/detect/index.ts
|
|
4
|
+
const feedElementRegex = /(?:^|[\s>])<(?:\w+:)?feed[\s>]/im;
|
|
5
|
+
const atomElementsRegex = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i;
|
|
4
6
|
const detect = (value) => {
|
|
5
7
|
if (!require_utils.isNonEmptyString(value)) return false;
|
|
6
|
-
if (
|
|
8
|
+
if (!feedElementRegex.test(value)) return false;
|
|
7
9
|
const hasAtomNamespace = require_config.namespaceUris.atom.some((uri) => value.includes(uri));
|
|
8
|
-
const hasAtomElements =
|
|
10
|
+
const hasAtomElements = atomElementsRegex.test(value);
|
|
9
11
|
return hasAtomNamespace || hasAtomElements;
|
|
10
12
|
};
|
|
11
13
|
//#endregion
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { namespaceUris } from "../../../common/config.js";
|
|
2
2
|
import { isNonEmptyString } from "../../../common/utils.js";
|
|
3
3
|
//#region src/feeds/atom/detect/index.ts
|
|
4
|
+
const feedElementRegex = /(?:^|[\s>])<(?:\w+:)?feed[\s>]/im;
|
|
5
|
+
const atomElementsRegex = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i;
|
|
4
6
|
const detect = (value) => {
|
|
5
7
|
if (!isNonEmptyString(value)) return false;
|
|
6
|
-
if (
|
|
8
|
+
if (!feedElementRegex.test(value)) return false;
|
|
7
9
|
const hasAtomNamespace = namespaceUris.atom.some((uri) => value.includes(uri));
|
|
8
|
-
const hasAtomElements =
|
|
10
|
+
const hasAtomElements = atomElementsRegex.test(value);
|
|
9
11
|
return hasAtomNamespace || hasAtomElements;
|
|
10
12
|
};
|
|
11
13
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_errors = require("../../../common/errors.cjs");
|
|
1
2
|
const require_config = require("../../../common/config.cjs");
|
|
2
3
|
const require_utils = require("../../../common/utils.cjs");
|
|
3
4
|
const require_config$1 = require("./config.cjs");
|
|
@@ -5,7 +6,7 @@ const require_utils$1 = require("./utils.cjs");
|
|
|
5
6
|
//#region src/feeds/atom/generate/index.ts
|
|
6
7
|
const generate = (value, options) => {
|
|
7
8
|
const generated = require_utils$1.generateFeed(value);
|
|
8
|
-
if (!generated) throw new
|
|
9
|
+
if (!generated) throw new require_errors.GenerateError(require_config.locales.invalidInputAtom);
|
|
9
10
|
return require_utils.generateXml(require_config$1.builder, generated, options);
|
|
10
11
|
};
|
|
11
12
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DateLike,
|
|
1
|
+
import { DateLike, GenerateMainXml } from "../../../common/types.cjs";
|
|
2
2
|
import { Atom } from "../common/types.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/feeds/atom/generate/index.d.ts
|
|
5
|
-
declare const generate:
|
|
5
|
+
declare const generate: GenerateMainXml<Atom.Feed<DateLike>, Atom.Feed<Date, true>>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { generate };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DateLike,
|
|
1
|
+
import { DateLike, GenerateMainXml } from "../../../common/types.js";
|
|
2
2
|
import { Atom } from "../common/types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/feeds/atom/generate/index.d.ts
|
|
5
|
-
declare const generate:
|
|
5
|
+
declare const generate: GenerateMainXml<Atom.Feed<DateLike>, Atom.Feed<Date, true>>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { generate };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenerateError } from "../../../common/errors.js";
|
|
1
2
|
import { locales } from "../../../common/config.js";
|
|
2
3
|
import { generateXml } from "../../../common/utils.js";
|
|
3
4
|
import { builder } from "./config.js";
|
|
@@ -5,7 +6,7 @@ import { generateFeed } from "./utils.js";
|
|
|
5
6
|
//#region src/feeds/atom/generate/index.ts
|
|
6
7
|
const generate = (value, options) => {
|
|
7
8
|
const generated = generateFeed(value);
|
|
8
|
-
if (!generated) throw new
|
|
9
|
+
if (!generated) throw new GenerateError(locales.invalidInputAtom);
|
|
9
10
|
return generateXml(builder, generated, options);
|
|
10
11
|
};
|
|
11
12
|
//#endregion
|