feedsmith 2.8.0 → 3.0.0-next.2
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 +2 -1
- package/dist/common/parse.cjs +3 -3
- package/dist/common/parse.d.cts +5 -5
- package/dist/common/parse.d.ts +5 -5
- package/dist/common/parse.js +11 -11
- package/dist/common/types.d.cts +21 -9
- package/dist/common/types.d.ts +21 -9
- package/dist/common/utils.cjs +24 -17
- package/dist/common/utils.js +25 -17
- package/dist/feeds/atom/common/types.d.cts +53 -50
- package/dist/feeds/atom/common/types.d.ts +53 -50
- package/dist/feeds/atom/detect/index.cjs +2 -1
- package/dist/feeds/atom/detect/index.js +2 -1
- package/dist/feeds/atom/generate/index.cjs +1 -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 +1 -1
- package/dist/feeds/atom/generate/utils.cjs +17 -14
- package/dist/feeds/atom/generate/utils.js +33 -30
- package/dist/feeds/atom/parse/index.cjs +1 -1
- 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 +1 -1
- package/dist/feeds/atom/parse/utils.cjs +11 -16
- package/dist/feeds/atom/parse/utils.js +21 -26
- 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.cjs +1 -1
- 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 +1 -1
- 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 +13 -2
- package/dist/feeds/rdf/detect/index.js +13 -2
- package/dist/feeds/rdf/parse/index.cjs +1 -1
- 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 +1 -1
- package/dist/feeds/rdf/parse/utils.cjs +17 -14
- package/dist/feeds/rdf/parse/utils.js +15 -12
- package/dist/feeds/rss/common/types.d.cts +71 -68
- package/dist/feeds/rss/common/types.d.ts +71 -68
- package/dist/feeds/rss/generate/index.cjs +1 -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 +1 -1
- package/dist/feeds/rss/generate/utils.cjs +35 -32
- package/dist/feeds/rss/generate/utils.js +57 -54
- package/dist/feeds/rss/parse/index.cjs +1 -1
- 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 +1 -1
- package/dist/feeds/rss/parse/utils.cjs +69 -65
- package/dist/feeds/rss/parse/utils.js +87 -83
- 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 +85 -85
- package/dist/namespaces/media/common/types.d.ts +85 -85
- 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 +139 -148
- package/dist/namespaces/podcast/common/types.d.ts +139 -148
- package/dist/namespaces/podcast/generate/utils.cjs +11 -8
- package/dist/namespaces/podcast/generate/utils.js +12 -9
- package/dist/namespaces/podcast/parse/utils.cjs +7 -10
- package/dist/namespaces/podcast/parse/utils.js +7 -10
- 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/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 +15 -0
- package/dist/namespaces/xml/generate/utils.js +15 -0
- package/dist/namespaces/xml/parse/utils.cjs +15 -0
- package/dist/namespaces/xml/parse/utils.js +15 -0
- package/dist/opml/common/types.d.cts +11 -9
- package/dist/opml/common/types.d.ts +11 -9
- package/dist/opml/generate/index.cjs +1 -1
- package/dist/opml/generate/index.d.cts +2 -2
- package/dist/opml/generate/index.d.ts +2 -2
- package/dist/opml/generate/index.js +1 -1
- 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.
|
|
@@ -105,6 +105,7 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
|
|
|
105
105
|
| [W3C Basic Geo](https://feedsmith.dev/reference/namespaces/geo) | `<geo:*>` | RSS, Atom | ✅ | ✅ |
|
|
106
106
|
| [GeoRSS Simple](https://feedsmith.dev/reference/namespaces/georss) | `<georss:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
|
107
107
|
| [RDF](https://feedsmith.dev/reference/namespaces/rdf) | `<rdf:*>` | RDF | ✅ | ✅ |
|
|
108
|
+
| [XML](https://feedsmith.dev/reference/namespaces/xml) | `<xml:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
|
108
109
|
|
|
109
110
|
## Quick Start
|
|
110
111
|
|
package/dist/common/parse.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
const require_config = require('./config.cjs');
|
|
1
2
|
const require_utils = require('./utils.cjs');
|
|
2
3
|
const require_index = require('../feeds/atom/detect/index.cjs');
|
|
3
|
-
const require_config = require('./config.cjs');
|
|
4
4
|
const require_index$1 = require('../feeds/atom/parse/index.cjs');
|
|
5
5
|
const require_index$2 = require('../feeds/json/detect/index.cjs');
|
|
6
6
|
const require_index$3 = require('../feeds/json/parse/index.cjs');
|
|
@@ -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
|
+
import { locales } from "./config.js";
|
|
1
2
|
import { parseJsonObject } from "./utils.js";
|
|
2
3
|
import { detect } from "../feeds/atom/detect/index.js";
|
|
3
|
-
import {
|
|
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
|
@@ -58,10 +58,6 @@ const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
|
|
|
58
58
|
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
59
59
|
if (isPresent(singularValue)) return generator(singularValue);
|
|
60
60
|
};
|
|
61
|
-
const generateSingularOrArray = (singularValue, pluralValues, generator) => {
|
|
62
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
63
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
64
|
-
};
|
|
65
61
|
const cdataStartTag = "<![CDATA[";
|
|
66
62
|
const cdataEndTag = "]]>";
|
|
67
63
|
const hasEntities = (text) => {
|
|
@@ -208,15 +204,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
208
204
|
};
|
|
209
205
|
const detectNamespaces = (value, recursive = false) => {
|
|
210
206
|
const namespaces = /* @__PURE__ */ new Set();
|
|
211
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
207
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
212
208
|
const traverse = (current) => {
|
|
213
209
|
if (Array.isArray(current)) {
|
|
214
210
|
for (const item of current) traverse(item);
|
|
215
211
|
return;
|
|
216
212
|
}
|
|
217
213
|
if (isObject(current)) for (const key in current) {
|
|
218
|
-
if (seenKeys
|
|
219
|
-
seenKeys
|
|
214
|
+
if (seenKeys?.has(key)) continue;
|
|
215
|
+
seenKeys?.add(key);
|
|
220
216
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
221
217
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
222
218
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -261,8 +257,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
261
257
|
return namespaceAttrs;
|
|
262
258
|
};
|
|
263
259
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
260
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
264
261
|
const normalizeNamespaceUri = (uri) => {
|
|
265
|
-
|
|
262
|
+
if (typeof uri !== "string") return uri;
|
|
263
|
+
let normalized = normalizedUriCache.get(uri);
|
|
264
|
+
if (normalized === void 0) {
|
|
265
|
+
normalized = uri.trim().toLowerCase();
|
|
266
|
+
normalizedUriCache.set(uri, normalized);
|
|
267
|
+
}
|
|
268
|
+
return normalized;
|
|
266
269
|
};
|
|
267
270
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
268
271
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -302,13 +305,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
302
305
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
303
306
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
304
307
|
if (!isObject(object)) return object;
|
|
305
|
-
const normalizedObject = {};
|
|
306
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
307
308
|
const declarations = extractNamespaceDeclarations(object);
|
|
308
|
-
|
|
309
|
+
let hasDeclarations = false;
|
|
310
|
+
for (const _ in declarations) {
|
|
311
|
+
hasDeclarations = true;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
const currentContext = hasDeclarations ? {
|
|
309
315
|
...parentContext,
|
|
310
316
|
...declarations
|
|
311
|
-
};
|
|
317
|
+
} : parentContext;
|
|
318
|
+
const normalizedObject = {};
|
|
312
319
|
for (const key in object) {
|
|
313
320
|
const value = object[key];
|
|
314
321
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -317,11 +324,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
317
324
|
}
|
|
318
325
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
319
326
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
if (normalizedKey in normalizedObject) {
|
|
328
|
+
const existing = normalizedObject[normalizedKey];
|
|
329
|
+
if (Array.isArray(existing)) existing.push(normalizedValue);
|
|
330
|
+
else normalizedObject[normalizedKey] = [existing, normalizedValue];
|
|
331
|
+
} else normalizedObject[normalizedKey] = normalizedValue;
|
|
323
332
|
}
|
|
324
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
325
333
|
return normalizedObject;
|
|
326
334
|
};
|
|
327
335
|
const normalizeRoot = (object) => {
|
|
@@ -362,7 +370,6 @@ exports.generatePlainString = generatePlainString;
|
|
|
362
370
|
exports.generateRdfResource = generateRdfResource;
|
|
363
371
|
exports.generateRfc3339Date = generateRfc3339Date;
|
|
364
372
|
exports.generateRfc822Date = generateRfc822Date;
|
|
365
|
-
exports.generateSingularOrArray = generateSingularOrArray;
|
|
366
373
|
exports.generateTextOrCdataString = generateTextOrCdataString;
|
|
367
374
|
exports.generateXml = generateXml;
|
|
368
375
|
exports.generateYesNoBoolean = generateYesNoBoolean;
|
package/dist/common/utils.js
CHANGED
|
@@ -58,10 +58,6 @@ const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
|
|
|
58
58
|
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
59
59
|
if (isPresent(singularValue)) return generator(singularValue);
|
|
60
60
|
};
|
|
61
|
-
const generateSingularOrArray = (singularValue, pluralValues, generator) => {
|
|
62
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
63
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
64
|
-
};
|
|
65
61
|
const cdataStartTag = "<![CDATA[";
|
|
66
62
|
const cdataEndTag = "]]>";
|
|
67
63
|
const hasEntities = (text) => {
|
|
@@ -208,15 +204,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
208
204
|
};
|
|
209
205
|
const detectNamespaces = (value, recursive = false) => {
|
|
210
206
|
const namespaces = /* @__PURE__ */ new Set();
|
|
211
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
207
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
212
208
|
const traverse = (current) => {
|
|
213
209
|
if (Array.isArray(current)) {
|
|
214
210
|
for (const item of current) traverse(item);
|
|
215
211
|
return;
|
|
216
212
|
}
|
|
217
213
|
if (isObject(current)) for (const key in current) {
|
|
218
|
-
if (seenKeys
|
|
219
|
-
seenKeys
|
|
214
|
+
if (seenKeys?.has(key)) continue;
|
|
215
|
+
seenKeys?.add(key);
|
|
220
216
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
221
217
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
222
218
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -261,8 +257,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
261
257
|
return namespaceAttrs;
|
|
262
258
|
};
|
|
263
259
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
260
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
264
261
|
const normalizeNamespaceUri = (uri) => {
|
|
265
|
-
|
|
262
|
+
if (typeof uri !== "string") return uri;
|
|
263
|
+
let normalized = normalizedUriCache.get(uri);
|
|
264
|
+
if (normalized === void 0) {
|
|
265
|
+
normalized = uri.trim().toLowerCase();
|
|
266
|
+
normalizedUriCache.set(uri, normalized);
|
|
267
|
+
}
|
|
268
|
+
return normalized;
|
|
266
269
|
};
|
|
267
270
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
268
271
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -302,13 +305,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
302
305
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
303
306
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
304
307
|
if (!isObject(object)) return object;
|
|
305
|
-
const normalizedObject = {};
|
|
306
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
307
308
|
const declarations = extractNamespaceDeclarations(object);
|
|
308
|
-
|
|
309
|
+
let hasDeclarations = false;
|
|
310
|
+
for (const _ in declarations) {
|
|
311
|
+
hasDeclarations = true;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
const currentContext = hasDeclarations ? {
|
|
309
315
|
...parentContext,
|
|
310
316
|
...declarations
|
|
311
|
-
};
|
|
317
|
+
} : parentContext;
|
|
318
|
+
const normalizedObject = {};
|
|
312
319
|
for (const key in object) {
|
|
313
320
|
const value = object[key];
|
|
314
321
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -317,11 +324,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
317
324
|
}
|
|
318
325
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
319
326
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
if (normalizedKey in normalizedObject) {
|
|
328
|
+
const existing = normalizedObject[normalizedKey];
|
|
329
|
+
if (Array.isArray(existing)) existing.push(normalizedValue);
|
|
330
|
+
else normalizedObject[normalizedKey] = [existing, normalizedValue];
|
|
331
|
+
} else normalizedObject[normalizedKey] = normalizedValue;
|
|
323
332
|
}
|
|
324
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
325
333
|
return normalizedObject;
|
|
326
334
|
};
|
|
327
335
|
const normalizeRoot = (object) => {
|
|
@@ -350,4 +358,4 @@ const parseJsonObject = (value) => {
|
|
|
350
358
|
};
|
|
351
359
|
|
|
352
360
|
//#endregion
|
|
353
|
-
export { createNamespaceNormalizator, detectNamespaces, generateArrayOrSingular, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date,
|
|
361
|
+
export { createNamespaceNormalizator, detectNamespaces, generateArrayOrSingular, 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 { 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";
|
|
@@ -19,112 +19,115 @@ 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
|
|
|
26
27
|
declare namespace Atom {
|
|
27
28
|
type Text = string;
|
|
28
|
-
type Link<TDate extends DateLike> = {
|
|
29
|
-
href: string
|
|
29
|
+
type Link<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
30
|
+
href: Requirable<string>;
|
|
30
31
|
rel?: string;
|
|
31
32
|
type?: string;
|
|
32
33
|
hreflang?: string;
|
|
33
34
|
title?: string;
|
|
34
35
|
length?: number;
|
|
35
36
|
thr?: ThrNs.Link<TDate>;
|
|
36
|
-
}
|
|
37
|
-
type Person = {
|
|
38
|
-
name: string
|
|
37
|
+
}, TStrict>;
|
|
38
|
+
type Person<TStrict extends boolean = false> = Strict<{
|
|
39
|
+
name: Requirable<string>;
|
|
39
40
|
uri?: string;
|
|
40
41
|
email?: string;
|
|
41
42
|
arxiv?: ArxivNs.Author;
|
|
42
|
-
}
|
|
43
|
-
type Category = {
|
|
44
|
-
term: string
|
|
43
|
+
}, TStrict>;
|
|
44
|
+
type Category<TStrict extends boolean = false> = Strict<{
|
|
45
|
+
term: Requirable<string>;
|
|
45
46
|
scheme?: string;
|
|
46
47
|
label?: string;
|
|
47
|
-
}
|
|
48
|
-
type Generator = {
|
|
49
|
-
text: string
|
|
48
|
+
}, TStrict>;
|
|
49
|
+
type Generator<TStrict extends boolean = false> = Strict<{
|
|
50
|
+
text: Requirable<string>;
|
|
50
51
|
uri?: string;
|
|
51
52
|
version?: string;
|
|
52
|
-
}
|
|
53
|
-
type Source<TDate extends DateLike> = {
|
|
54
|
-
authors?: Array<Person
|
|
55
|
-
categories?: Array<Category
|
|
56
|
-
contributors?: Array<Person
|
|
57
|
-
generator?: Generator
|
|
53
|
+
}, TStrict>;
|
|
54
|
+
type Source<TDate extends DateLike, TStrict extends boolean = false> = {
|
|
55
|
+
authors?: Array<Person<TStrict>>;
|
|
56
|
+
categories?: Array<Category<TStrict>>;
|
|
57
|
+
contributors?: Array<Person<TStrict>>;
|
|
58
|
+
generator?: Generator<TStrict>;
|
|
58
59
|
icon?: string;
|
|
59
60
|
id?: string;
|
|
60
|
-
links?: Array<Link<TDate>>;
|
|
61
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
61
62
|
logo?: string;
|
|
62
63
|
rights?: Text;
|
|
63
64
|
subtitle?: Text;
|
|
64
65
|
title?: Text;
|
|
65
66
|
updated?: TDate;
|
|
66
67
|
};
|
|
67
|
-
type Entry<TDate extends DateLike> = {
|
|
68
|
-
authors?: Array<Person
|
|
69
|
-
categories?: Array<Category
|
|
68
|
+
type Entry<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
69
|
+
authors?: Array<Person<TStrict>>;
|
|
70
|
+
categories?: Array<Category<TStrict>>;
|
|
70
71
|
content?: Text;
|
|
71
|
-
contributors?: Array<Person
|
|
72
|
-
id: string
|
|
73
|
-
links?: Array<Link<TDate>>;
|
|
72
|
+
contributors?: Array<Person<TStrict>>;
|
|
73
|
+
id: Requirable<string>;
|
|
74
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
74
75
|
published?: TDate;
|
|
75
76
|
rights?: Text;
|
|
76
|
-
source?: Source<TDate>;
|
|
77
|
+
source?: Source<TDate, TStrict>;
|
|
77
78
|
summary?: Text;
|
|
78
|
-
title: Text
|
|
79
|
-
updated: TDate
|
|
79
|
+
title: Requirable<Text>;
|
|
80
|
+
updated: Requirable<TDate>;
|
|
80
81
|
app?: AppNs.Entry<TDate>;
|
|
81
82
|
arxiv?: ArxivNs.Entry;
|
|
82
83
|
cc?: CcNs.ItemOrFeed;
|
|
83
84
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
84
85
|
slash?: SlashNs.Item;
|
|
85
86
|
itunes?: ItunesNs.Item;
|
|
86
|
-
googleplay?: GooglePlayNs.Item
|
|
87
|
-
psc?: PscNs.Item
|
|
88
|
-
media?: MediaNs.ItemOrFeed
|
|
89
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
87
|
+
googleplay?: GooglePlayNs.Item<TStrict>;
|
|
88
|
+
psc?: PscNs.Item<TStrict>;
|
|
89
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
90
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
90
91
|
geo?: GeoNs.ItemOrFeed;
|
|
91
|
-
thr?: ThrNs.Item
|
|
92
|
+
thr?: ThrNs.Item<TStrict>;
|
|
92
93
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
93
94
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
94
95
|
wfw?: WfwNs.Item;
|
|
95
96
|
yt?: YtNs.Item;
|
|
96
97
|
pingback?: PingbackNs.Item;
|
|
97
98
|
trackback?: TrackbackNs.Item;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
xml?: XmlNs.ItemOrFeed;
|
|
100
|
+
}, TStrict>;
|
|
101
|
+
type Feed<TDate extends DateLike, TStrict extends boolean = false> = Strict<{
|
|
102
|
+
authors?: Array<Person<TStrict>>;
|
|
103
|
+
categories?: Array<Category<TStrict>>;
|
|
104
|
+
contributors?: Array<Person<TStrict>>;
|
|
105
|
+
generator?: Generator<TStrict>;
|
|
104
106
|
icon?: string;
|
|
105
|
-
id: string
|
|
106
|
-
links?: Array<Link<TDate>>;
|
|
107
|
+
id: Requirable<string>;
|
|
108
|
+
links?: Array<Link<TDate, TStrict>>;
|
|
107
109
|
logo?: string;
|
|
108
110
|
rights?: Text;
|
|
109
111
|
subtitle?: Text;
|
|
110
|
-
title: Text
|
|
111
|
-
updated: TDate
|
|
112
|
-
entries?: Array<Entry<TDate>>;
|
|
112
|
+
title: Requirable<Text>;
|
|
113
|
+
updated: Requirable<TDate>;
|
|
114
|
+
entries?: Array<Entry<TDate, TStrict>>;
|
|
113
115
|
cc?: CcNs.ItemOrFeed;
|
|
114
116
|
dc?: DcNs.ItemOrFeed<TDate>;
|
|
115
117
|
sy?: SyNs.Feed<TDate>;
|
|
116
|
-
itunes?: ItunesNs.Feed
|
|
117
|
-
googleplay?: GooglePlayNs.Feed
|
|
118
|
-
media?: MediaNs.ItemOrFeed
|
|
119
|
-
georss?: GeoRssNs.ItemOrFeed
|
|
118
|
+
itunes?: ItunesNs.Feed<TStrict>;
|
|
119
|
+
googleplay?: GooglePlayNs.Feed<TStrict>;
|
|
120
|
+
media?: MediaNs.ItemOrFeed<TStrict>;
|
|
121
|
+
georss?: GeoRssNs.ItemOrFeed<TStrict>;
|
|
120
122
|
geo?: GeoNs.ItemOrFeed;
|
|
121
123
|
dcterms?: DcTermsNs.ItemOrFeed<TDate>;
|
|
122
124
|
creativeCommons?: CreativeCommonsNs.ItemOrFeed;
|
|
123
|
-
opensearch?: OpenSearchNs.Feed
|
|
125
|
+
opensearch?: OpenSearchNs.Feed<TStrict>;
|
|
124
126
|
yt?: YtNs.Feed;
|
|
125
127
|
admin?: AdminNs.Feed;
|
|
126
128
|
pingback?: PingbackNs.Feed;
|
|
127
|
-
|
|
129
|
+
xml?: XmlNs.ItemOrFeed;
|
|
130
|
+
}, TStrict>;
|
|
128
131
|
}
|
|
129
132
|
//#endregion
|
|
130
133
|
export { Atom };
|