feedsmith 2.7.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 +24 -24
- 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 +39 -34
- package/dist/common/utils.js +40 -35
- 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 +7 -9
package/README.md
CHANGED
|
@@ -22,22 +22,22 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
|
|
|
22
22
|
|
|
23
23
|
### Core
|
|
24
24
|
|
|
25
|
-
* **Comprehensive support**
|
|
26
|
-
* **Preserves structure**
|
|
27
|
-
* **Smart namespace handling**
|
|
28
|
-
* **Parsing & generating**
|
|
25
|
+
* **Comprehensive support** — Supports all major feed formats and namespaces.
|
|
26
|
+
* **Preserves structure** — Parsed feed object maintains the original feed structure making it easy to access the data.
|
|
27
|
+
* **Smart namespace handling** — Normalizes custom namespace prefixes to standard ones (e.g., `<custom:creator>` becomes `dc.creator`).
|
|
28
|
+
* **Parsing & generating** — Use one package for both parsing and generating feeds.
|
|
29
29
|
|
|
30
30
|
### Leniency
|
|
31
|
-
* **Normalizes legacy elements**
|
|
32
|
-
* **CaSe INSENsiTive**
|
|
33
|
-
* **Namespace URI tolerance**
|
|
34
|
-
* **Forgiving**
|
|
31
|
+
* **Normalizes legacy elements** — Upgrades feed elements to their modern equivalents so that you never need to worry about reading feeds in older formats.
|
|
32
|
+
* **CaSe INSENsiTive** — Handles fields and attributes in any case (lowercase, uppercase, mixed).
|
|
33
|
+
* **Namespace URI tolerance** — Accepts non-official namespace URIs (HTTPS variants, case variations, trailing slashes, whitespace).
|
|
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
|
|
37
|
-
* **Ultrafast parsing**
|
|
38
|
-
* **Type-safe API**
|
|
39
|
-
* **Tree-shakable**
|
|
40
|
-
* **Well-tested**
|
|
36
|
+
### Performance
|
|
37
|
+
* **Ultrafast parsing** — One of the fastest JavaScript feed parsers ([see benchmarks](/benchmarks)).
|
|
38
|
+
* **Type-safe API** — Built with TypeScript from the ground up, it provides complete type definitions for every feed format and namespace.
|
|
39
|
+
* **Tree-shakable** — Only include the parts of the library you need, reducing bundle size.
|
|
40
|
+
* **Well-tested** — Comprehensive test suite with over 2000 tests and 99% code coverage.
|
|
41
41
|
|
|
42
42
|
### Compatibility
|
|
43
43
|
* Works in Node.js 14.0.0+ and modern browsers.
|
|
@@ -56,23 +56,23 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
|
|
|
56
56
|
|
|
57
57
|
### Feeds
|
|
58
58
|
|
|
59
|
-
| Format | Versions |
|
|
60
|
-
|
|
61
|
-
| [RSS](
|
|
62
|
-
| [Atom](https://
|
|
63
|
-
| [RDF](https://
|
|
64
|
-
| [JSON Feed](https://
|
|
59
|
+
| Format | Versions | Parse | Generate |
|
|
60
|
+
|--------|----------|-------|----------|
|
|
61
|
+
| [RSS](https://feedsmith.dev/reference/feeds/rss) | 0.9x, 2.0 | ✅ | ✅ |
|
|
62
|
+
| [Atom](https://feedsmith.dev/reference/feeds/atom) | 0.3, 1.0 | ✅ | ✅ |
|
|
63
|
+
| [RDF](https://feedsmith.dev/reference/feeds/rdf) | 0.9, 1.0 | ✅ | 📋 |
|
|
64
|
+
| [JSON Feed](https://feedsmith.dev/reference/feeds/json) | 1.0, 1.1 | ✅ | ✅ |
|
|
65
65
|
|
|
66
66
|
### Other
|
|
67
67
|
|
|
68
|
-
| Format | Versions |
|
|
69
|
-
|
|
70
|
-
| [OPML](https://
|
|
68
|
+
| Format | Versions | Parse | Generate |
|
|
69
|
+
|--------|----------|-------|----------|
|
|
70
|
+
| [OPML](https://feedsmith.dev/reference/other/opml) | 1.0, 2.0 | ✅ | ✅ |
|
|
71
71
|
|
|
72
72
|
### Feed Namespaces
|
|
73
73
|
|
|
74
|
-
| Name | Prefix | Supported in |
|
|
75
|
-
|
|
74
|
+
| Name | Prefix | Supported in | Parse | Generate |
|
|
75
|
+
|------|---------|--------------|-------|----------|
|
|
76
76
|
| [Atom](https://feedsmith.dev/reference/namespaces/atom) | `<atom:*>` | RSS, RDF | ✅ | ✅ |
|
|
77
77
|
| [Dublin Core](https://feedsmith.dev/reference/namespaces/dc) | `<dc:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
|
78
78
|
| [Dublin Core Terms](https://feedsmith.dev/reference/namespaces/dcterms) | `<dcterms:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
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
|
@@ -64,39 +64,32 @@ const generateSingularOrArray = (singularValue, pluralValues, generator) => {
|
|
|
64
64
|
};
|
|
65
65
|
const cdataStartTag = "<![CDATA[";
|
|
66
66
|
const cdataEndTag = "]]>";
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const hasEntities = (text) => {
|
|
68
|
+
const ampIndex = text.indexOf("&");
|
|
69
|
+
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
70
|
+
};
|
|
71
|
+
const decodeWithCdata = (text) => {
|
|
69
72
|
let currentIndex = text.indexOf(cdataStartTag);
|
|
70
|
-
if (currentIndex === -1) return text;
|
|
73
|
+
if (currentIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
|
|
71
74
|
let result = "";
|
|
72
75
|
let lastIndex = 0;
|
|
73
76
|
while (currentIndex !== -1) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const textBefore = text.substring(lastIndex, currentIndex);
|
|
78
|
+
result += hasEntities(textBefore) ? (0, entities.decodeHTML)(textBefore) : textBefore;
|
|
79
|
+
const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
|
|
80
|
+
if (endIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
|
|
81
|
+
result += text.substring(currentIndex + 9, endIndex);
|
|
82
|
+
lastIndex = endIndex + 3;
|
|
79
83
|
currentIndex = text.indexOf(cdataStartTag, lastIndex);
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
const textAfter = text.substring(lastIndex);
|
|
86
|
+
result += hasEntities(textAfter) ? (0, entities.decodeHTML)(textAfter) : textAfter;
|
|
82
87
|
return result;
|
|
83
88
|
};
|
|
84
|
-
const hasEntities = (text) => {
|
|
85
|
-
const ampIndex = text.indexOf("&");
|
|
86
|
-
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
87
|
-
};
|
|
88
89
|
const parseString = (value) => {
|
|
89
90
|
if (typeof value === "string") {
|
|
90
91
|
if (value === "") return;
|
|
91
|
-
|
|
92
|
-
if (value.indexOf(cdataStartTag) !== -1) string = stripCdata(value);
|
|
93
|
-
string = string.trim();
|
|
94
|
-
if (string === "") return;
|
|
95
|
-
if (hasEntities(string)) {
|
|
96
|
-
string = (0, entities.decodeXML)(string);
|
|
97
|
-
if (hasEntities(string)) string = (0, entities.decodeHTML)(string);
|
|
98
|
-
}
|
|
99
|
-
return string || void 0;
|
|
92
|
+
return decodeWithCdata(value).trim() || void 0;
|
|
100
93
|
}
|
|
101
94
|
if (typeof value === "number") return value.toString();
|
|
102
95
|
};
|
|
@@ -215,15 +208,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
215
208
|
};
|
|
216
209
|
const detectNamespaces = (value, recursive = false) => {
|
|
217
210
|
const namespaces = /* @__PURE__ */ new Set();
|
|
218
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
211
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
219
212
|
const traverse = (current) => {
|
|
220
213
|
if (Array.isArray(current)) {
|
|
221
214
|
for (const item of current) traverse(item);
|
|
222
215
|
return;
|
|
223
216
|
}
|
|
224
217
|
if (isObject(current)) for (const key in current) {
|
|
225
|
-
if (seenKeys
|
|
226
|
-
seenKeys
|
|
218
|
+
if (seenKeys?.has(key)) continue;
|
|
219
|
+
seenKeys?.add(key);
|
|
227
220
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
228
221
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
229
222
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -268,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
268
261
|
return namespaceAttrs;
|
|
269
262
|
};
|
|
270
263
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
264
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
271
265
|
const normalizeNamespaceUri = (uri) => {
|
|
272
|
-
|
|
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;
|
|
273
273
|
};
|
|
274
274
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
275
275
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -309,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
309
309
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
310
310
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
311
311
|
if (!isObject(object)) return object;
|
|
312
|
-
const normalizedObject = {};
|
|
313
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
314
312
|
const declarations = extractNamespaceDeclarations(object);
|
|
315
|
-
|
|
313
|
+
let hasDeclarations = false;
|
|
314
|
+
for (const _ in declarations) {
|
|
315
|
+
hasDeclarations = true;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
const currentContext = hasDeclarations ? {
|
|
316
319
|
...parentContext,
|
|
317
320
|
...declarations
|
|
318
|
-
};
|
|
321
|
+
} : parentContext;
|
|
322
|
+
const normalizedObject = {};
|
|
319
323
|
for (const key in object) {
|
|
320
324
|
const value = object[key];
|
|
321
325
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -324,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
324
328
|
}
|
|
325
329
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
326
330
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
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;
|
|
330
336
|
}
|
|
331
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
332
337
|
return normalizedObject;
|
|
333
338
|
};
|
|
334
339
|
const normalizeRoot = (object) => {
|
package/dist/common/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodeHTML
|
|
1
|
+
import { decodeHTML } from "entities";
|
|
2
2
|
|
|
3
3
|
//#region src/common/utils.ts
|
|
4
4
|
const isPresent = (value) => {
|
|
@@ -64,39 +64,32 @@ const generateSingularOrArray = (singularValue, pluralValues, generator) => {
|
|
|
64
64
|
};
|
|
65
65
|
const cdataStartTag = "<![CDATA[";
|
|
66
66
|
const cdataEndTag = "]]>";
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const hasEntities = (text) => {
|
|
68
|
+
const ampIndex = text.indexOf("&");
|
|
69
|
+
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
70
|
+
};
|
|
71
|
+
const decodeWithCdata = (text) => {
|
|
69
72
|
let currentIndex = text.indexOf(cdataStartTag);
|
|
70
|
-
if (currentIndex === -1) return text;
|
|
73
|
+
if (currentIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
|
|
71
74
|
let result = "";
|
|
72
75
|
let lastIndex = 0;
|
|
73
76
|
while (currentIndex !== -1) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const textBefore = text.substring(lastIndex, currentIndex);
|
|
78
|
+
result += hasEntities(textBefore) ? decodeHTML(textBefore) : textBefore;
|
|
79
|
+
const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
|
|
80
|
+
if (endIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
|
|
81
|
+
result += text.substring(currentIndex + 9, endIndex);
|
|
82
|
+
lastIndex = endIndex + 3;
|
|
79
83
|
currentIndex = text.indexOf(cdataStartTag, lastIndex);
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
const textAfter = text.substring(lastIndex);
|
|
86
|
+
result += hasEntities(textAfter) ? decodeHTML(textAfter) : textAfter;
|
|
82
87
|
return result;
|
|
83
88
|
};
|
|
84
|
-
const hasEntities = (text) => {
|
|
85
|
-
const ampIndex = text.indexOf("&");
|
|
86
|
-
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
87
|
-
};
|
|
88
89
|
const parseString = (value) => {
|
|
89
90
|
if (typeof value === "string") {
|
|
90
91
|
if (value === "") return;
|
|
91
|
-
|
|
92
|
-
if (value.indexOf(cdataStartTag) !== -1) string = stripCdata(value);
|
|
93
|
-
string = string.trim();
|
|
94
|
-
if (string === "") return;
|
|
95
|
-
if (hasEntities(string)) {
|
|
96
|
-
string = decodeXML(string);
|
|
97
|
-
if (hasEntities(string)) string = decodeHTML(string);
|
|
98
|
-
}
|
|
99
|
-
return string || void 0;
|
|
92
|
+
return decodeWithCdata(value).trim() || void 0;
|
|
100
93
|
}
|
|
101
94
|
if (typeof value === "number") return value.toString();
|
|
102
95
|
};
|
|
@@ -215,15 +208,15 @@ const generateYesNoBoolean = (value) => {
|
|
|
215
208
|
};
|
|
216
209
|
const detectNamespaces = (value, recursive = false) => {
|
|
217
210
|
const namespaces = /* @__PURE__ */ new Set();
|
|
218
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
211
|
+
const seenKeys = recursive ? /* @__PURE__ */ new Set() : void 0;
|
|
219
212
|
const traverse = (current) => {
|
|
220
213
|
if (Array.isArray(current)) {
|
|
221
214
|
for (const item of current) traverse(item);
|
|
222
215
|
return;
|
|
223
216
|
}
|
|
224
217
|
if (isObject(current)) for (const key in current) {
|
|
225
|
-
if (seenKeys
|
|
226
|
-
seenKeys
|
|
218
|
+
if (seenKeys?.has(key)) continue;
|
|
219
|
+
seenKeys?.add(key);
|
|
227
220
|
const keyWithoutAt = key.charCodeAt(0) === 64 ? key.slice(1) : key;
|
|
228
221
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
229
222
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
@@ -268,8 +261,15 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
268
261
|
return namespaceAttrs;
|
|
269
262
|
};
|
|
270
263
|
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespace) => {
|
|
264
|
+
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
271
265
|
const normalizeNamespaceUri = (uri) => {
|
|
272
|
-
|
|
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;
|
|
273
273
|
};
|
|
274
274
|
const primaryNamespaceUris = primaryNamespace && namespaceUris[primaryNamespace] ? namespaceUris[primaryNamespace].map(normalizeNamespaceUri) : void 0;
|
|
275
275
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
@@ -309,13 +309,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
309
309
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
310
310
|
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
311
311
|
if (!isObject(object)) return object;
|
|
312
|
-
const normalizedObject = {};
|
|
313
|
-
const keyGroups = /* @__PURE__ */ new Map();
|
|
314
312
|
const declarations = extractNamespaceDeclarations(object);
|
|
315
|
-
|
|
313
|
+
let hasDeclarations = false;
|
|
314
|
+
for (const _ in declarations) {
|
|
315
|
+
hasDeclarations = true;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
const currentContext = hasDeclarations ? {
|
|
316
319
|
...parentContext,
|
|
317
320
|
...declarations
|
|
318
|
-
};
|
|
321
|
+
} : parentContext;
|
|
322
|
+
const normalizedObject = {};
|
|
319
323
|
for (const key in object) {
|
|
320
324
|
const value = object[key];
|
|
321
325
|
if (key.indexOf("@xmlns") === 0) {
|
|
@@ -324,11 +328,12 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
324
328
|
}
|
|
325
329
|
const normalizedKey = normalizeKey(key, currentContext);
|
|
326
330
|
const normalizedValue = traverseAndNormalize(value, currentContext);
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
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;
|
|
330
336
|
}
|
|
331
|
-
for (const [normalizedKey, values] of keyGroups) normalizedObject[normalizedKey] = values.length === 1 ? values[0] : values;
|
|
332
337
|
return normalizedObject;
|
|
333
338
|
};
|
|
334
339
|
const normalizeRoot = (object) => {
|