feedsmith 2.8.0 → 3.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/common/parse.cjs +2 -2
- package/dist/common/parse.d.cts +5 -5
- package/dist/common/parse.d.ts +5 -5
- package/dist/common/parse.js +10 -10
- package/dist/common/types.d.cts +21 -9
- package/dist/common/types.d.ts +21 -9
- package/dist/common/utils.cjs +24 -12
- package/dist/common/utils.js +24 -12
- package/dist/feeds/atom/common/types.d.cts +50 -50
- package/dist/feeds/atom/common/types.d.ts +50 -50
- 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/utils.cjs +9 -9
- package/dist/feeds/atom/generate/utils.js +28 -28
- 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/utils.cjs +3 -11
- package/dist/feeds/atom/parse/utils.js +17 -25
- 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.d.cts +2 -2
- package/dist/feeds/json/generate/index.d.ts +2 -2
- package/dist/feeds/json/parse/index.d.cts +2 -2
- package/dist/feeds/json/parse/index.d.ts +2 -2
- package/dist/feeds/rdf/common/types.d.cts +28 -28
- package/dist/feeds/rdf/common/types.d.ts +28 -28
- 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/utils.cjs +2 -2
- package/dist/feeds/rdf/parse/utils.js +12 -12
- package/dist/feeds/rss/common/types.d.cts +68 -68
- package/dist/feeds/rss/common/types.d.ts +68 -68
- 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/utils.cjs +4 -4
- package/dist/feeds/rss/generate/utils.js +53 -53
- 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/utils.cjs +2 -2
- package/dist/feeds/rss/parse/utils.js +51 -51
- package/dist/namespaces/atom/common/types.d.cts +4 -3
- package/dist/namespaces/atom/common/types.d.ts +4 -3
- package/dist/namespaces/atom/generate/utils.cjs +4 -4
- package/dist/namespaces/atom/generate/utils.js +6 -6
- 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/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/media/common/types.d.cts +86 -84
- package/dist/namespaces/media/common/types.d.ts +86 -84
- 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 +144 -141
- package/dist/namespaces/podcast/common/types.d.ts +144 -141
- package/dist/namespaces/podcast/generate/utils.cjs +5 -2
- package/dist/namespaces/podcast/generate/utils.js +5 -2
- package/dist/namespaces/podcast/parse/utils.cjs +5 -2
- package/dist/namespaces/podcast/parse/utils.js +5 -2
- 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/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/thr/common/types.d.cts +6 -6
- package/dist/namespaces/thr/common/types.d.ts +6 -6
- package/dist/opml/common/types.d.cts +11 -9
- package/dist/opml/common/types.d.ts +11 -9
- package/dist/opml/generate/index.d.cts +2 -2
- package/dist/opml/generate/index.d.ts +2 -2
- package/dist/opml/parse/index.d.cts +1 -2
- package/dist/opml/parse/index.d.ts +1 -2
- package/dist/types.d.cts +1 -2
- package/dist/types.d.ts +1 -2
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
|
|
|
33
33
|
* **Namespace URI tolerance** — Accepts non-official namespace URIs (HTTPS variants, case variations, trailing slashes, whitespace).
|
|
34
34
|
* **Forgiving** — Gracefully handles malformed or incomplete feeds and extracts valid data. This makes it suitable for use with real-world feeds that may not strictly follow specifications.
|
|
35
35
|
|
|
36
|
-
### Performance
|
|
36
|
+
### Performance
|
|
37
37
|
* **Ultrafast parsing** — One of the fastest JavaScript feed parsers ([see benchmarks](/benchmarks)).
|
|
38
38
|
* **Type-safe API** — Built with TypeScript from the ground up, it provides complete type definitions for every feed format and namespace.
|
|
39
39
|
* **Tree-shakable** — Only include the parts of the library you need, reducing bundle size.
|
package/dist/common/parse.cjs
CHANGED
|
@@ -10,7 +10,7 @@ const require_index$6 = require('../feeds/rss/detect/index.cjs');
|
|
|
10
10
|
const require_index$7 = require('../feeds/rss/parse/index.cjs');
|
|
11
11
|
|
|
12
12
|
//#region src/common/parse.ts
|
|
13
|
-
const parse
|
|
13
|
+
const parse = (value, options) => {
|
|
14
14
|
if (require_index$6.detect(value)) return {
|
|
15
15
|
format: "rss",
|
|
16
16
|
feed: require_index$7.parse(value, options)
|
|
@@ -32,4 +32,4 @@ const parse$4 = (value, options) => {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
|
-
exports.parse = parse
|
|
35
|
+
exports.parse = parse;
|
package/dist/common/parse.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions } from "./types.cjs";
|
|
2
2
|
import { Atom } from "../feeds/atom/common/types.cjs";
|
|
3
3
|
import { Json } from "../feeds/json/common/types.cjs";
|
|
4
4
|
import { Rdf } from "../feeds/rdf/common/types.cjs";
|
|
@@ -7,16 +7,16 @@ import { Rss } from "../feeds/rss/common/types.cjs";
|
|
|
7
7
|
//#region src/common/parse.d.ts
|
|
8
8
|
type Parse = (value: unknown, options?: ParseOptions) => {
|
|
9
9
|
format: 'rss';
|
|
10
|
-
feed:
|
|
10
|
+
feed: Rss.Feed<string>;
|
|
11
11
|
} | {
|
|
12
12
|
format: 'atom';
|
|
13
|
-
feed:
|
|
13
|
+
feed: Atom.Feed<string>;
|
|
14
14
|
} | {
|
|
15
15
|
format: 'rdf';
|
|
16
|
-
feed:
|
|
16
|
+
feed: Rdf.Feed<string>;
|
|
17
17
|
} | {
|
|
18
18
|
format: 'json';
|
|
19
|
-
feed:
|
|
19
|
+
feed: Json.Feed<string>;
|
|
20
20
|
};
|
|
21
21
|
declare const parse: Parse;
|
|
22
22
|
//#endregion
|
package/dist/common/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions } from "./types.js";
|
|
2
2
|
import { Atom } from "../feeds/atom/common/types.js";
|
|
3
3
|
import { Json } from "../feeds/json/common/types.js";
|
|
4
4
|
import { Rdf } from "../feeds/rdf/common/types.js";
|
|
@@ -7,16 +7,16 @@ import { Rss } from "../feeds/rss/common/types.js";
|
|
|
7
7
|
//#region src/common/parse.d.ts
|
|
8
8
|
type Parse = (value: unknown, options?: ParseOptions) => {
|
|
9
9
|
format: 'rss';
|
|
10
|
-
feed:
|
|
10
|
+
feed: Rss.Feed<string>;
|
|
11
11
|
} | {
|
|
12
12
|
format: 'atom';
|
|
13
|
-
feed:
|
|
13
|
+
feed: Atom.Feed<string>;
|
|
14
14
|
} | {
|
|
15
15
|
format: 'rdf';
|
|
16
|
-
feed:
|
|
16
|
+
feed: Rdf.Feed<string>;
|
|
17
17
|
} | {
|
|
18
18
|
format: 'json';
|
|
19
|
-
feed:
|
|
19
|
+
feed: Json.Feed<string>;
|
|
20
20
|
};
|
|
21
21
|
declare const parse: Parse;
|
|
22
22
|
//#endregion
|
package/dist/common/parse.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { parseJsonObject } from "./utils.js";
|
|
2
2
|
import { detect } from "../feeds/atom/detect/index.js";
|
|
3
3
|
import { locales } from "./config.js";
|
|
4
|
-
import { parse } from "../feeds/atom/parse/index.js";
|
|
4
|
+
import { parse as parse$1 } from "../feeds/atom/parse/index.js";
|
|
5
5
|
import { detect as detect$1 } from "../feeds/json/detect/index.js";
|
|
6
|
-
import { parse as parse$
|
|
6
|
+
import { parse as parse$2 } from "../feeds/json/parse/index.js";
|
|
7
7
|
import { detect as detect$2 } from "../feeds/rdf/detect/index.js";
|
|
8
|
-
import { parse as parse$
|
|
8
|
+
import { parse as parse$3 } from "../feeds/rdf/parse/index.js";
|
|
9
9
|
import { detect as detect$3 } from "../feeds/rss/detect/index.js";
|
|
10
|
-
import { parse as parse$
|
|
10
|
+
import { parse as parse$4 } from "../feeds/rss/parse/index.js";
|
|
11
11
|
|
|
12
12
|
//#region src/common/parse.ts
|
|
13
|
-
const parse
|
|
13
|
+
const parse = (value, options) => {
|
|
14
14
|
if (detect$3(value)) return {
|
|
15
15
|
format: "rss",
|
|
16
|
-
feed: parse$
|
|
16
|
+
feed: parse$4(value, options)
|
|
17
17
|
};
|
|
18
18
|
if (detect(value)) return {
|
|
19
19
|
format: "atom",
|
|
20
|
-
feed: parse(value, options)
|
|
20
|
+
feed: parse$1(value, options)
|
|
21
21
|
};
|
|
22
22
|
if (detect$2(value)) return {
|
|
23
23
|
format: "rdf",
|
|
24
|
-
feed: parse$
|
|
24
|
+
feed: parse$3(value, options)
|
|
25
25
|
};
|
|
26
26
|
const json = parseJsonObject(value);
|
|
27
27
|
if (detect$1(json)) return {
|
|
28
28
|
format: "json",
|
|
29
|
-
feed: parse$
|
|
29
|
+
feed: parse$2(json, options)
|
|
30
30
|
};
|
|
31
31
|
throw new Error(locales.unrecognizedFeedFormat);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
|
-
export { parse
|
|
35
|
+
export { parse };
|
package/dist/common/types.d.cts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
//#region src/common/types.d.ts
|
|
2
|
+
type Simplify<T> = { [K in keyof T]: T[K] };
|
|
3
|
+
type Unwrap<T> = T extends {
|
|
4
|
+
__requirable: infer U;
|
|
5
|
+
} ? U : T;
|
|
6
|
+
type HasMarker<T> = [Extract<T, {
|
|
7
|
+
__requirable: unknown;
|
|
8
|
+
}>] extends [never] ? false : true;
|
|
9
|
+
type Optional<T> = { [K in keyof T]-?: object extends Pick<T, K> ? K : never }[keyof T];
|
|
10
|
+
type Marked<T> = { [K in keyof T]-?: HasMarker<T[K]> extends true ? K : never }[keyof T];
|
|
11
|
+
type Strict<T, S extends boolean> = Simplify<S extends true ? { [K in Exclude<keyof T, Optional<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T>]?: Unwrap<T[K]> } : { [K in Exclude<keyof T, Optional<T> | Marked<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T> | Marked<T>]?: Unwrap<T[K]> }>;
|
|
12
|
+
type Requirable<T> = T | {
|
|
13
|
+
__requirable: T;
|
|
14
|
+
};
|
|
2
15
|
type DateLike = Date | string;
|
|
3
16
|
type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
|
|
4
17
|
type IsPlainObject<T> = T extends Array<unknown> ? false : T extends ((...args: Array<unknown>) => unknown) ? false : T extends Date ? false : T extends object ? T extends null ? false : true : false;
|
|
5
|
-
type
|
|
6
|
-
type DeepPartial<T> = IsPlainObject<T> extends true ? { [P in keyof T]?: DeepPartial<RemoveUndefined<T[P]>> } : T extends Array<infer U> ? Array<DeepPartial<U>> : T;
|
|
18
|
+
type DeepOmit<T, K$1 extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K$1>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K$1> }, Exclude<keyof T, K$1>> : T;
|
|
7
19
|
type ParseOptions = {
|
|
8
20
|
maxItems?: number;
|
|
9
21
|
};
|
|
@@ -15,14 +27,14 @@ type XmlStylesheet = {
|
|
|
15
27
|
charset?: string;
|
|
16
28
|
alternate?: boolean;
|
|
17
29
|
};
|
|
18
|
-
type XmlGenerateOptions<O,
|
|
19
|
-
|
|
30
|
+
type XmlGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
|
|
31
|
+
strict?: S;
|
|
20
32
|
stylesheets?: Array<XmlStylesheet>;
|
|
21
33
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
34
|
+
type XmlGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: XmlGenerateOptions<O, S>) => string;
|
|
35
|
+
type JsonGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
|
|
36
|
+
strict?: S;
|
|
24
37
|
};
|
|
25
|
-
type
|
|
26
|
-
type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
|
|
38
|
+
type JsonGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: JsonGenerateOptions<O, S>) => unknown;
|
|
27
39
|
//#endregion
|
|
28
|
-
export { DateLike,
|
|
40
|
+
export { DateLike, DeepOmit, ExtraFields, JsonGenerateMain, ParseOptions, Requirable, Strict, XmlGenerateMain, XmlGenerateOptions };
|
package/dist/common/types.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
//#region src/common/types.d.ts
|
|
2
|
+
type Simplify<T> = { [K in keyof T]: T[K] };
|
|
3
|
+
type Unwrap<T> = T extends {
|
|
4
|
+
__requirable: infer U;
|
|
5
|
+
} ? U : T;
|
|
6
|
+
type HasMarker<T> = [Extract<T, {
|
|
7
|
+
__requirable: unknown;
|
|
8
|
+
}>] extends [never] ? false : true;
|
|
9
|
+
type Optional<T> = { [K in keyof T]-?: object extends Pick<T, K> ? K : never }[keyof T];
|
|
10
|
+
type Marked<T> = { [K in keyof T]-?: HasMarker<T[K]> extends true ? K : never }[keyof T];
|
|
11
|
+
type Strict<T, S extends boolean> = Simplify<S extends true ? { [K in Exclude<keyof T, Optional<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T>]?: Unwrap<T[K]> } : { [K in Exclude<keyof T, Optional<T> | Marked<T>>]-?: Unwrap<T[K]> } & { [K in Optional<T> | Marked<T>]?: Unwrap<T[K]> }>;
|
|
12
|
+
type Requirable<T> = T | {
|
|
13
|
+
__requirable: T;
|
|
14
|
+
};
|
|
2
15
|
type DateLike = Date | string;
|
|
3
16
|
type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
|
|
4
17
|
type IsPlainObject<T> = T extends Array<unknown> ? false : T extends ((...args: Array<unknown>) => unknown) ? false : T extends Date ? false : T extends object ? T extends null ? false : true : false;
|
|
5
|
-
type
|
|
6
|
-
type DeepPartial<T> = IsPlainObject<T> extends true ? { [P in keyof T]?: DeepPartial<RemoveUndefined<T[P]>> } : T extends Array<infer U> ? Array<DeepPartial<U>> : T;
|
|
18
|
+
type DeepOmit<T, K$1 extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K$1>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K$1> }, Exclude<keyof T, K$1>> : T;
|
|
7
19
|
type ParseOptions = {
|
|
8
20
|
maxItems?: number;
|
|
9
21
|
};
|
|
@@ -15,14 +27,14 @@ type XmlStylesheet = {
|
|
|
15
27
|
charset?: string;
|
|
16
28
|
alternate?: boolean;
|
|
17
29
|
};
|
|
18
|
-
type XmlGenerateOptions<O,
|
|
19
|
-
|
|
30
|
+
type XmlGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
|
|
31
|
+
strict?: S;
|
|
20
32
|
stylesheets?: Array<XmlStylesheet>;
|
|
21
33
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
34
|
+
type XmlGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: XmlGenerateOptions<O, S>) => string;
|
|
35
|
+
type JsonGenerateOptions<O = Record<string, unknown>, S extends boolean = false> = O & {
|
|
36
|
+
strict?: S;
|
|
24
37
|
};
|
|
25
|
-
type
|
|
26
|
-
type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
|
|
38
|
+
type JsonGenerateMain<L, St, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? St : L, options?: JsonGenerateOptions<O, S>) => unknown;
|
|
27
39
|
//#endregion
|
|
28
|
-
export { DateLike,
|
|
40
|
+
export { DateLike, DeepOmit, ExtraFields, JsonGenerateMain, ParseOptions, Requirable, Strict, XmlGenerateMain, XmlGenerateOptions };
|
package/dist/common/utils.cjs
CHANGED
|
@@ -208,15 +208,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
208
208
|
};
|
|
209
209
|
const detectNamespaces = (value, recursive = false) => {
|
|
210
210
|
const namespaces = /* @__PURE__ */ new Set();
|
|
211
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
211
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
212
212
|
const traverse = (current) => {
|
|
213
213
|
if (Array.isArray(current)) {
|
|
214
214
|
for (const item of current) traverse(item);
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
217
|
if (isObject(current)) for (const key in current) {
|
|
218
|
-
if (seenKeys
|
|
219
|
-
seenKeys
|
|
218
|
+
if (seenKeys?.has(key)) continue;
|
|
219
|
+
seenKeys?.add(key);
|
|
220
220
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
221
221
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
222
222
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -261,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
261
261
|
return namespaceAttrs;
|
|
262
262
|
};
|
|
263
263
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
264
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
264
265
|
const normalizeNamespaceUri = (uri) => {
|
|
265
|
-
|
|
266
|
+
if (typeof uri !== "string") return uri;
|
|
267
|
+
let normalized = normalizedUriCache.get(uri);
|
|
268
|
+
if (normalized === void 0) {
|
|
269
|
+
normalized = uri.trim().toLowerCase();
|
|
270
|
+
normalizedUriCache.set(uri, normalized);
|
|
271
|
+
}
|
|
272
|
+
return normalized;
|
|
266
273
|
};
|
|
267
274
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
268
275
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -302,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
302
309
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
303
310
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
304
311
|
if (!isObject(object)) return object;
|
|
305
|
-
const normalizedObject = {};
|
|
306
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
307
312
|
const declarations = extractNamespaceDeclarations(object);
|
|
308
|
-
|
|
313
|
+
let hasDeclarations = false;
|
|
314
|
+
for (const _ in declarations) {
|
|
315
|
+
hasDeclarations = true;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
const currentContext = hasDeclarations ? {
|
|
309
319
|
...parentContext,
|
|
310
320
|
...declarations
|
|
311
|
-
};
|
|
321
|
+
} : parentContext;
|
|
322
|
+
const normalizedObject = {};
|
|
312
323
|
for (const key in object) {
|
|
313
324
|
const value = object[key];
|
|
314
325
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -317,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
317
328
|
}
|
|
318
329
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
319
330
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
331
|
+
if (normalizedKey in normalizedObject) {
|
|
332
|
+
const existing = normalizedObject[normalizedKey];
|
|
333
|
+
if (Array.isArray(existing)) existing.push(normalizedValue);
|
|
334
|
+
else normalizedObject[normalizedKey] = [existing, normalizedValue];
|
|
335
|
+
} else normalizedObject[normalizedKey] = normalizedValue;
|
|
323
336
|
}
|
|
324
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
325
337
|
return normalizedObject;
|
|
326
338
|
};
|
|
327
339
|
const normalizeRoot = (object) => {
|
package/dist/common/utils.js
CHANGED
|
@@ -208,15 +208,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
208
208
|
};
|
|
209
209
|
const detectNamespaces = (value, recursive = false) => {
|
|
210
210
|
const namespaces = /* @__PURE__ */ new Set();
|
|
211
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
211
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
212
212
|
const traverse = (current) => {
|
|
213
213
|
if (Array.isArray(current)) {
|
|
214
214
|
for (const item of current) traverse(item);
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
217
|
if (isObject(current)) for (const key in current) {
|
|
218
|
-
if (seenKeys
|
|
219
|
-
seenKeys
|
|
218
|
+
if (seenKeys?.has(key)) continue;
|
|
219
|
+
seenKeys?.add(key);
|
|
220
220
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
221
221
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
222
222
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -261,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
261
261
|
return namespaceAttrs;
|
|
262
262
|
};
|
|
263
263
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
264
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
264
265
|
const normalizeNamespaceUri = (uri) => {
|
|
265
|
-
|
|
266
|
+
if (typeof uri !== "string") return uri;
|
|
267
|
+
let normalized = normalizedUriCache.get(uri);
|
|
268
|
+
if (normalized === void 0) {
|
|
269
|
+
normalized = uri.trim().toLowerCase();
|
|
270
|
+
normalizedUriCache.set(uri, normalized);
|
|
271
|
+
}
|
|
272
|
+
return normalized;
|
|
266
273
|
};
|
|
267
274
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
268
275
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -302,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
302
309
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
303
310
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
304
311
|
if (!isObject(object)) return object;
|
|
305
|
-
const normalizedObject = {};
|
|
306
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
307
312
|
const declarations = extractNamespaceDeclarations(object);
|
|
308
|
-
|
|
313
|
+
let hasDeclarations = false;
|
|
314
|
+
for (const _ in declarations) {
|
|
315
|
+
hasDeclarations = true;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
const currentContext = hasDeclarations ? {
|
|
309
319
|
...parentContext,
|
|
310
320
|
...declarations
|
|
311
|
-
};
|
|
321
|
+
} : parentContext;
|
|
322
|
+
const normalizedObject = {};
|
|
312
323
|
for (const key in object) {
|
|
313
324
|
const value = object[key];
|
|
314
325
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -317,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
317
328
|
}
|
|
318
329
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
319
330
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
331
|
+
if (normalizedKey in normalizedObject) {
|
|
332
|
+
const existing = normalizedObject[normalizedKey];
|
|
333
|
+
if (Array.isArray(existing)) existing.push(normalizedValue);
|
|
334
|
+
else normalizedObject[normalizedKey] = [existing, normalizedValue];
|
|
335
|
+
} else normalizedObject[normalizedKey] = normalizedValue;
|
|
323
336
|
}
|
|
324
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
325
337
|
return normalizedObject;
|
|
326
338
|
};
|
|
327
339
|
const normalizeRoot = (object) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateLike } from "../../../common/types.cjs";
|
|
1
|
+
import { DateLike, 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";
|
|
@@ -25,106 +25,106 @@ import { YtNs } from "../../../namespaces/yt/common/types.cjs";
|
|
|
25
25
|
|
|
26
26
|
declare namespace Atom {
|
|
27
27
|
type Text = string;
|
|
28
|
-
type Link<TDate extends DateLike> = {
|
|
29
|
-
href: string
|
|
28
|
+
type Link<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
29
|
+
href: Requirable<string>;
|
|
30
30
|
rel?: string;
|
|
31
31
|
type?: string;
|
|
32
32
|
hreflang?: string;
|
|
33
33
|
title?: string;
|
|
34
34
|
length?: number;
|
|
35
35
|
thr?: ThrNs.Link<TDate>;
|
|
36
|
-
}
|
|
37
|
-
type Person = {
|
|
38
|
-
name: string
|
|
36
|
+
}, TStrict>;
|
|
37
|
+
type Person<TStrict extends boolean = false> = Strict<{
|
|
38
|
+
name: Requirable<string>;
|
|
39
39
|
uri?: string;
|
|
40
40
|
email?: string;
|
|
41
41
|
arxiv?: ArxivNs.Author;
|
|
42
|
-
}
|
|
43
|
-
type Category = {
|
|
44
|
-
term: string
|
|
42
|
+
}, TStrict>;
|
|
43
|
+
type Category<TStrict extends boolean = false> = Strict<{
|
|
44
|
+
term: Requirable<string>;
|
|
45
45
|
scheme?: string;
|
|
46
46
|
label?: string;
|
|
47
|
-
}
|
|
48
|
-
type Generator = {
|
|
49
|
-
text: string
|
|
47
|
+
}, TStrict>;
|
|
48
|
+
type Generator<TStrict extends boolean = false> = Strict<{
|
|
49
|
+
text: Requirable<string>;
|
|
50
50
|
uri?: string;
|
|
51
51
|
version?: string;
|
|
52
|
-
}
|
|
53
|
-
type Source<TDate extends DateLike> = {
|
|
54
|
-
authors?: Array<Person
|
|
55
|
-
categories?: Array<Category
|
|
56
|
-
contributors?: Array<Person
|
|
57
|
-
generator?: Generator
|
|
52
|
+
}, TStrict>;
|
|
53
|
+
type Source<TDate extends DateLike, TStrict extends boolean = false> = {
|
|
54
|
+
authors?: Array<Person<TStrict>>;
|
|
55
|
+
categories?: Array<Category<TStrict>>;
|
|
56
|
+
contributors?: Array<Person<TStrict>>;
|
|
57
|
+
generator?: Generator<TStrict>;
|
|
58
58
|
icon?: string;
|
|
59
59
|
id?: string;
|
|
60
|
-
links?: Array<Link<TDate>>;
|
|
60
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
61
61
|
logo?: string;
|
|
62
62
|
rights?: Text;
|
|
63
63
|
subtitle?: Text;
|
|
64
64
|
title?: Text;
|
|
65
65
|
updated?: TDate;
|
|
66
66
|
};
|
|
67
|
-
type Entry<TDate extends DateLike> = {
|
|
68
|
-
authors?: Array<Person
|
|
69
|
-
categories?: Array<Category
|
|
67
|
+
type Entry<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
68
|
+
authors?: Array<Person<TStrict>>;
|
|
69
|
+
categories?: Array<Category<TStrict>>;
|
|
70
70
|
content?: Text;
|
|
71
|
-
contributors?: Array<Person
|
|
72
|
-
id: string
|
|
73
|
-
links?: Array<Link<TDate>>;
|
|
71
|
+
contributors?: Array<Person<TStrict>>;
|
|
72
|
+
id: Requirable<string>;
|
|
73
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
74
74
|
published?: TDate;
|
|
75
75
|
rights?: Text;
|
|
76
|
-
source?: Source<TDate>;
|
|
76
|
+
source?: Source<TDate, TStrict>;
|
|
77
77
|
summary?: Text;
|
|
78
|
-
title: Text
|
|
79
|
-
updated: TDate
|
|
78
|
+
title: Requirable<Text>;
|
|
79
|
+
updated: Requirable<TDate>;
|
|
80
80
|
app?: AppNs.Entry<TDate>;
|
|
81
81
|
arxiv?: ArxivNs.Entry;
|
|
82
82
|
cc?: CcNs.ItemOrFeed;
|
|
83
83
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
84
84
|
slash?: SlashNs.Item;
|
|
85
85
|
itunes?: ItunesNs.Item;
|
|
86
|
-
googleplay?: GooglePlayNs.Item
|
|
87
|
-
psc?: PscNs.Item
|
|
88
|
-
media?: MediaNs.ItemOrFeed
|
|
89
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
86
|
+
googleplay?: GooglePlayNs.Item<TStrict>;
|
|
87
|
+
psc?: PscNs.Item<TStrict>;
|
|
88
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
89
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
90
90
|
geo?: GeoNs.ItemOrFeed;
|
|
91
|
-
thr?: ThrNs.Item
|
|
91
|
+
thr?: ThrNs.Item<TStrict>;
|
|
92
92
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
93
93
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
94
94
|
wfw?: WfwNs.Item;
|
|
95
95
|
yt?: YtNs.Item;
|
|
96
96
|
pingback?: PingbackNs.Item;
|
|
97
97
|
trackback?: TrackbackNs.Item;
|
|
98
|
-
}
|
|
99
|
-
type Feed<TDate extends DateLike> = {
|
|
100
|
-
authors?: Array<Person
|
|
101
|
-
categories?: Array<Category
|
|
102
|
-
contributors?: Array<Person
|
|
103
|
-
generator?: Generator
|
|
98
|
+
}, TStrict>;
|
|
99
|
+
type Feed<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
100
|
+
authors?: Array<Person<TStrict>>;
|
|
101
|
+
categories?: Array<Category<TStrict>>;
|
|
102
|
+
contributors?: Array<Person<TStrict>>;
|
|
103
|
+
generator?: Generator<TStrict>;
|
|
104
104
|
icon?: string;
|
|
105
|
-
id: string
|
|
106
|
-
links?: Array<Link<TDate>>;
|
|
105
|
+
id: Requirable<string>;
|
|
106
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
107
107
|
logo?: string;
|
|
108
108
|
rights?: Text;
|
|
109
109
|
subtitle?: Text;
|
|
110
|
-
title: Text
|
|
111
|
-
updated: TDate
|
|
112
|
-
entries?: Array<Entry<TDate>>;
|
|
110
|
+
title: Requirable<Text>;
|
|
111
|
+
updated: Requirable<TDate>;
|
|
112
|
+
entries?: Array<Entry<TDate, TStrict>>;
|
|
113
113
|
cc?: CcNs.ItemOrFeed;
|
|
114
114
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
115
115
|
sy?: SyNs.Feed<TDate>;
|
|
116
|
-
itunes?: ItunesNs.Feed
|
|
117
|
-
googleplay?: GooglePlayNs.Feed
|
|
118
|
-
media?: MediaNs.ItemOrFeed
|
|
119
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
116
|
+
itunes?: ItunesNs.Feed<TStrict>;
|
|
117
|
+
googleplay?: GooglePlayNs.Feed<TStrict>;
|
|
118
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
119
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
120
120
|
geo?: GeoNs.ItemOrFeed;
|
|
121
121
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
122
122
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
123
|
-
opensearch?: OpenSearchNs.Feed
|
|
123
|
+
opensearch?: OpenSearchNs.Feed<TStrict>;
|
|
124
124
|
yt?: YtNs.Feed;
|
|
125
125
|
admin?: AdminNs.Feed;
|
|
126
126
|
pingback?: PingbackNs.Feed;
|
|
127
|
-
}
|
|
127
|
+
}, TStrict>;
|
|
128
128
|
}
|
|
129
129
|
//#endregion
|
|
130
130
|
export { Atom };
|