feedsmith 2.9.0 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -9
- package/dist/common/config.cjs +102 -274
- package/dist/common/config.js +101 -273
- package/dist/common/errors.cjs +30 -0
- package/dist/common/errors.d.cts +15 -0
- package/dist/common/errors.d.ts +15 -0
- package/dist/common/errors.js +27 -0
- package/dist/common/parse.cjs +13 -14
- package/dist/common/parse.d.cts +10 -11
- package/dist/common/parse.d.ts +10 -11
- package/dist/common/parse.js +3 -4
- package/dist/common/types.d.cts +24 -12
- package/dist/common/types.d.ts +24 -12
- package/dist/common/utils.cjs +82 -36
- package/dist/common/utils.js +82 -34
- package/dist/feeds/atom/common/types.d.cts +65 -52
- package/dist/feeds/atom/common/types.d.ts +65 -52
- package/dist/feeds/atom/detect/index.cjs +7 -7
- package/dist/feeds/atom/detect/index.js +5 -5
- package/dist/feeds/atom/generate/config.cjs +3 -6
- package/dist/feeds/atom/generate/config.js +1 -3
- package/dist/feeds/atom/generate/index.cjs +7 -8
- 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 +3 -4
- package/dist/feeds/atom/generate/utils.cjs +46 -31
- package/dist/feeds/atom/generate/utils.js +21 -6
- package/dist/feeds/atom/parse/config.cjs +7 -5
- package/dist/feeds/atom/parse/config.js +6 -5
- package/dist/feeds/atom/parse/index.cjs +15 -11
- 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 +13 -9
- package/dist/feeds/atom/parse/utils.cjs +112 -84
- package/dist/feeds/atom/parse/utils.js +89 -61
- package/dist/feeds/json/common/types.d.cts +19 -19
- package/dist/feeds/json/common/types.d.ts +19 -19
- package/dist/feeds/json/detect/index.cjs +3 -5
- package/dist/feeds/json/detect/index.js +1 -3
- package/dist/feeds/json/generate/index.cjs +7 -5
- package/dist/feeds/json/generate/index.d.cts +2 -2
- package/dist/feeds/json/generate/index.d.ts +2 -2
- package/dist/feeds/json/generate/index.js +6 -4
- package/dist/feeds/json/generate/utils.cjs +9 -6
- package/dist/feeds/json/generate/utils.js +9 -6
- package/dist/feeds/json/parse/index.cjs +8 -9
- 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 +4 -5
- package/dist/feeds/json/parse/utils.cjs +6 -8
- package/dist/feeds/json/parse/utils.js +5 -7
- 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 +7 -7
- package/dist/feeds/rdf/detect/index.js +5 -5
- package/dist/feeds/rdf/parse/config.cjs +6 -4
- package/dist/feeds/rdf/parse/config.js +5 -4
- package/dist/feeds/rdf/parse/index.cjs +15 -11
- 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 +13 -9
- package/dist/feeds/rdf/parse/utils.cjs +47 -46
- package/dist/feeds/rdf/parse/utils.js +30 -29
- package/dist/feeds/rss/common/types.d.cts +76 -74
- package/dist/feeds/rss/common/types.d.ts +76 -74
- package/dist/feeds/rss/detect/index.cjs +8 -7
- package/dist/feeds/rss/detect/index.js +7 -6
- package/dist/feeds/rss/generate/config.cjs +3 -6
- package/dist/feeds/rss/generate/config.js +1 -3
- package/dist/feeds/rss/generate/index.cjs +7 -8
- 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 +3 -4
- package/dist/feeds/rss/generate/utils.cjs +57 -59
- package/dist/feeds/rss/generate/utils.js +11 -13
- package/dist/feeds/rss/parse/config.cjs +30 -25
- package/dist/feeds/rss/parse/config.js +29 -25
- package/dist/feeds/rss/parse/index.cjs +15 -11
- 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 +13 -9
- package/dist/feeds/rss/parse/utils.cjs +214 -106
- package/dist/feeds/rss/parse/utils.js +181 -73
- package/dist/index.cjs +21 -16
- package/dist/index.d.cts +37 -16
- package/dist/index.d.ts +37 -16
- package/dist/index.js +2 -2
- package/dist/namespaces/acast/common/config.cjs +18 -0
- package/dist/namespaces/acast/common/config.js +17 -0
- package/dist/namespaces/acast/generate/utils.cjs +2 -4
- package/dist/namespaces/acast/generate/utils.js +1 -3
- package/dist/namespaces/acast/parse/utils.cjs +10 -12
- package/dist/namespaces/acast/parse/utils.js +9 -11
- package/dist/namespaces/admin/common/config.cjs +11 -0
- package/dist/namespaces/admin/common/config.js +10 -0
- package/dist/namespaces/admin/generate/utils.cjs +2 -4
- package/dist/namespaces/admin/generate/utils.js +1 -3
- package/dist/namespaces/admin/parse/utils.cjs +4 -6
- package/dist/namespaces/admin/parse/utils.js +3 -5
- package/dist/namespaces/app/common/config.cjs +11 -0
- package/dist/namespaces/app/common/config.js +10 -0
- package/dist/namespaces/app/common/types.d.cts +1 -3
- package/dist/namespaces/app/common/types.d.ts +1 -3
- package/dist/namespaces/app/generate/utils.cjs +2 -4
- package/dist/namespaces/app/generate/utils.js +1 -3
- package/dist/namespaces/app/parse/utils.cjs +5 -7
- package/dist/namespaces/app/parse/utils.js +4 -6
- package/dist/namespaces/arxiv/common/config.cjs +16 -0
- package/dist/namespaces/arxiv/common/config.js +15 -0
- package/dist/namespaces/arxiv/generate/utils.cjs +2 -4
- package/dist/namespaces/arxiv/generate/utils.js +1 -3
- package/dist/namespaces/arxiv/parse/utils.cjs +6 -8
- package/dist/namespaces/arxiv/parse/utils.js +5 -7
- package/dist/namespaces/atom/common/config.cjs +11 -0
- package/dist/namespaces/atom/common/config.js +11 -0
- package/dist/namespaces/atom/common/types.d.cts +3 -3
- package/dist/namespaces/atom/common/types.d.ts +3 -3
- package/dist/namespaces/atom/generate/utils.cjs +2 -4
- package/dist/namespaces/atom/generate/utils.js +1 -3
- package/dist/namespaces/atom/parse/utils.cjs +6 -6
- package/dist/namespaces/atom/parse/utils.js +5 -5
- package/dist/namespaces/blogchannel/common/config.cjs +15 -0
- package/dist/namespaces/blogchannel/common/config.js +14 -0
- package/dist/namespaces/blogchannel/generate/utils.cjs +2 -4
- package/dist/namespaces/blogchannel/generate/utils.js +1 -3
- package/dist/namespaces/blogchannel/parse/utils.cjs +5 -7
- package/dist/namespaces/blogchannel/parse/utils.js +4 -6
- package/dist/namespaces/cc/common/config.cjs +25 -0
- package/dist/namespaces/cc/common/config.js +24 -0
- package/dist/namespaces/cc/generate/utils.cjs +2 -4
- package/dist/namespaces/cc/generate/utils.js +1 -3
- package/dist/namespaces/cc/parse/utils.cjs +13 -15
- package/dist/namespaces/cc/parse/utils.js +12 -14
- package/dist/namespaces/content/common/config.cjs +11 -0
- package/dist/namespaces/content/common/config.js +10 -0
- package/dist/namespaces/content/generate/utils.cjs +2 -4
- package/dist/namespaces/content/generate/utils.js +1 -3
- package/dist/namespaces/content/parse/utils.cjs +3 -5
- package/dist/namespaces/content/parse/utils.js +2 -4
- package/dist/namespaces/creativecommons/common/config.cjs +15 -0
- package/dist/namespaces/creativecommons/common/config.js +14 -0
- package/dist/namespaces/creativecommons/generate/utils.cjs +2 -4
- package/dist/namespaces/creativecommons/generate/utils.js +1 -3
- package/dist/namespaces/creativecommons/parse/utils.cjs +3 -5
- package/dist/namespaces/creativecommons/parse/utils.js +2 -4
- package/dist/namespaces/dc/common/config.cjs +35 -0
- package/dist/namespaces/dc/common/config.js +34 -0
- package/dist/namespaces/dc/common/types.d.cts +4 -19
- package/dist/namespaces/dc/common/types.d.ts +4 -19
- package/dist/namespaces/dc/generate/utils.cjs +17 -19
- package/dist/namespaces/dc/generate/utils.js +17 -19
- package/dist/namespaces/dc/parse/utils.cjs +18 -33
- package/dist/namespaces/dc/parse/utils.js +18 -33
- package/dist/namespaces/dcterms/common/config.cjs +75 -0
- package/dist/namespaces/dcterms/common/config.js +74 -0
- package/dist/namespaces/dcterms/common/types.d.cts +23 -59
- package/dist/namespaces/dcterms/common/types.d.ts +23 -59
- package/dist/namespaces/dcterms/generate/utils.cjs +57 -59
- package/dist/namespaces/dcterms/generate/utils.js +57 -59
- package/dist/namespaces/dcterms/parse/utils.cjs +58 -94
- package/dist/namespaces/dcterms/parse/utils.js +58 -94
- package/dist/namespaces/feedpress/common/config.cjs +25 -0
- package/dist/namespaces/feedpress/common/config.js +24 -0
- package/dist/namespaces/feedpress/generate/utils.cjs +2 -4
- package/dist/namespaces/feedpress/generate/utils.js +1 -3
- package/dist/namespaces/feedpress/parse/utils.cjs +7 -9
- package/dist/namespaces/feedpress/parse/utils.js +6 -8
- package/dist/namespaces/geo/common/config.cjs +10 -0
- package/dist/namespaces/geo/common/config.js +9 -0
- package/dist/namespaces/geo/generate/utils.cjs +2 -4
- package/dist/namespaces/geo/generate/utils.js +1 -3
- package/dist/namespaces/geo/parse/utils.cjs +5 -7
- package/dist/namespaces/geo/parse/utils.js +4 -6
- package/dist/namespaces/georss/common/config.cjs +22 -0
- package/dist/namespaces/georss/common/config.js +21 -0
- 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 +4 -6
- package/dist/namespaces/georss/generate/utils.js +3 -5
- package/dist/namespaces/georss/parse/utils.cjs +10 -11
- package/dist/namespaces/georss/parse/utils.js +9 -10
- package/dist/namespaces/googleplay/common/config.cjs +22 -0
- package/dist/namespaces/googleplay/common/config.js +21 -0
- package/dist/namespaces/googleplay/common/types.d.cts +9 -7
- package/dist/namespaces/googleplay/common/types.d.ts +9 -7
- package/dist/namespaces/googleplay/generate/utils.cjs +2 -4
- package/dist/namespaces/googleplay/generate/utils.js +1 -3
- package/dist/namespaces/googleplay/parse/utils.cjs +10 -12
- package/dist/namespaces/googleplay/parse/utils.js +9 -11
- package/dist/namespaces/itunes/common/config.cjs +24 -0
- package/dist/namespaces/itunes/common/config.js +23 -0
- package/dist/namespaces/itunes/common/types.d.cts +9 -5
- package/dist/namespaces/itunes/common/types.d.ts +9 -5
- package/dist/namespaces/itunes/generate/utils.cjs +2 -4
- package/dist/namespaces/itunes/generate/utils.js +1 -3
- package/dist/namespaces/itunes/parse/utils.cjs +29 -30
- package/dist/namespaces/itunes/parse/utils.js +28 -29
- package/dist/namespaces/media/common/config.cjs +49 -0
- package/dist/namespaces/media/common/config.js +48 -0
- package/dist/namespaces/media/common/types.d.cts +85 -84
- package/dist/namespaces/media/common/types.d.ts +85 -84
- package/dist/namespaces/media/generate/utils.cjs +3 -5
- package/dist/namespaces/media/generate/utils.js +3 -5
- package/dist/namespaces/media/parse/utils.cjs +22 -25
- package/dist/namespaces/media/parse/utils.js +21 -24
- package/dist/namespaces/opensearch/common/config.cjs +17 -0
- package/dist/namespaces/opensearch/common/config.js +16 -0
- package/dist/namespaces/opensearch/common/types.d.cts +7 -5
- package/dist/namespaces/opensearch/common/types.d.ts +7 -5
- package/dist/namespaces/opensearch/generate/utils.cjs +2 -4
- package/dist/namespaces/opensearch/generate/utils.js +1 -3
- package/dist/namespaces/opensearch/parse/utils.cjs +5 -7
- package/dist/namespaces/opensearch/parse/utils.js +4 -6
- package/dist/namespaces/pingback/common/config.cjs +15 -0
- package/dist/namespaces/pingback/common/config.js +14 -0
- package/dist/namespaces/pingback/generate/utils.cjs +2 -4
- package/dist/namespaces/pingback/generate/utils.js +1 -3
- package/dist/namespaces/pingback/parse/utils.cjs +5 -7
- package/dist/namespaces/pingback/parse/utils.js +4 -6
- package/dist/namespaces/podcast/common/config.cjs +28 -0
- package/dist/namespaces/podcast/common/config.js +27 -0
- package/dist/namespaces/podcast/common/types.d.cts +136 -142
- package/dist/namespaces/podcast/common/types.d.ts +136 -142
- package/dist/namespaces/podcast/generate/utils.cjs +8 -10
- package/dist/namespaces/podcast/generate/utils.js +8 -10
- package/dist/namespaces/podcast/parse/utils.cjs +21 -27
- package/dist/namespaces/podcast/parse/utils.js +20 -26
- package/dist/namespaces/prism/common/config.cjs +138 -0
- package/dist/namespaces/prism/common/config.js +137 -0
- package/dist/namespaces/prism/common/types.d.cts +2 -4
- package/dist/namespaces/prism/common/types.d.ts +2 -4
- package/dist/namespaces/prism/generate/utils.cjs +2 -4
- package/dist/namespaces/prism/generate/utils.js +1 -3
- package/dist/namespaces/prism/parse/utils.cjs +141 -143
- package/dist/namespaces/prism/parse/utils.js +140 -142
- package/dist/namespaces/psc/common/config.cjs +9 -0
- package/dist/namespaces/psc/common/config.js +9 -0
- package/dist/namespaces/psc/common/types.d.cts +8 -6
- package/dist/namespaces/psc/common/types.d.ts +8 -6
- package/dist/namespaces/psc/generate/utils.cjs +2 -4
- package/dist/namespaces/psc/generate/utils.js +1 -3
- package/dist/namespaces/psc/parse/utils.cjs +2 -4
- package/dist/namespaces/psc/parse/utils.js +1 -3
- package/dist/namespaces/rawvoice/common/config.cjs +29 -0
- package/dist/namespaces/rawvoice/common/config.js +28 -0
- package/dist/namespaces/rawvoice/common/types.d.cts +24 -24
- package/dist/namespaces/rawvoice/common/types.d.ts +24 -24
- package/dist/namespaces/rawvoice/generate/utils.cjs +2 -4
- package/dist/namespaces/rawvoice/generate/utils.js +1 -3
- package/dist/namespaces/rawvoice/parse/utils.cjs +16 -18
- package/dist/namespaces/rawvoice/parse/utils.js +15 -17
- package/dist/namespaces/rdf/common/config.cjs +6 -0
- package/dist/namespaces/rdf/common/config.js +5 -0
- package/dist/namespaces/rdf/parse/utils.cjs +2 -4
- package/dist/namespaces/rdf/parse/utils.js +1 -3
- package/dist/namespaces/rss/common/config.cjs +9 -0
- package/dist/namespaces/rss/common/config.js +9 -0
- package/dist/namespaces/slash/common/config.cjs +16 -0
- package/dist/namespaces/slash/common/config.js +15 -0
- package/dist/namespaces/slash/generate/utils.cjs +2 -4
- package/dist/namespaces/slash/generate/utils.js +1 -3
- package/dist/namespaces/slash/parse/utils.cjs +6 -8
- package/dist/namespaces/slash/parse/utils.js +5 -7
- package/dist/namespaces/source/common/config.cjs +25 -0
- package/dist/namespaces/source/common/config.js +24 -0
- package/dist/namespaces/source/common/types.d.cts +20 -18
- package/dist/namespaces/source/common/types.d.ts +20 -18
- package/dist/namespaces/source/generate/utils.cjs +2 -4
- package/dist/namespaces/source/generate/utils.js +1 -3
- package/dist/namespaces/source/parse/utils.cjs +13 -15
- package/dist/namespaces/source/parse/utils.js +12 -14
- package/dist/namespaces/spotify/common/config.cjs +11 -0
- package/dist/namespaces/spotify/common/config.js +10 -0
- package/dist/namespaces/spotify/common/types.d.cts +22 -20
- package/dist/namespaces/spotify/common/types.d.ts +22 -20
- package/dist/namespaces/spotify/generate/utils.cjs +2 -4
- package/dist/namespaces/spotify/generate/utils.js +1 -3
- package/dist/namespaces/spotify/parse/utils.cjs +3 -5
- package/dist/namespaces/spotify/parse/utils.js +2 -4
- package/dist/namespaces/sy/common/config.cjs +15 -0
- package/dist/namespaces/sy/common/config.js +14 -0
- package/dist/namespaces/sy/common/types.d.cts +1 -3
- package/dist/namespaces/sy/common/types.d.ts +1 -3
- package/dist/namespaces/sy/generate/utils.cjs +2 -4
- package/dist/namespaces/sy/generate/utils.js +1 -3
- package/dist/namespaces/sy/parse/utils.cjs +6 -8
- package/dist/namespaces/sy/parse/utils.js +5 -7
- package/dist/namespaces/thr/common/config.cjs +15 -0
- package/dist/namespaces/thr/common/config.js +14 -0
- package/dist/namespaces/thr/common/types.d.cts +7 -7
- package/dist/namespaces/thr/common/types.d.ts +7 -7
- package/dist/namespaces/thr/generate/utils.cjs +2 -4
- package/dist/namespaces/thr/generate/utils.js +1 -3
- package/dist/namespaces/thr/parse/utils.cjs +5 -7
- package/dist/namespaces/thr/parse/utils.js +4 -6
- package/dist/namespaces/trackback/common/config.cjs +11 -0
- package/dist/namespaces/trackback/common/config.js +10 -0
- package/dist/namespaces/trackback/generate/utils.cjs +2 -4
- package/dist/namespaces/trackback/generate/utils.js +1 -3
- package/dist/namespaces/trackback/parse/utils.cjs +4 -6
- package/dist/namespaces/trackback/parse/utils.js +3 -5
- package/dist/namespaces/wfw/common/config.cjs +11 -0
- package/dist/namespaces/wfw/common/config.js +10 -0
- package/dist/namespaces/wfw/generate/utils.cjs +2 -4
- package/dist/namespaces/wfw/generate/utils.js +1 -3
- package/dist/namespaces/wfw/parse/utils.cjs +4 -6
- package/dist/namespaces/wfw/parse/utils.js +3 -5
- package/dist/namespaces/xml/common/types.d.cts +11 -0
- package/dist/namespaces/xml/common/types.d.ts +11 -0
- package/dist/namespaces/xml/generate/utils.cjs +13 -0
- package/dist/namespaces/xml/generate/utils.js +13 -0
- package/dist/namespaces/xml/parse/utils.cjs +13 -0
- package/dist/namespaces/xml/parse/utils.js +13 -0
- package/dist/namespaces/yt/common/config.cjs +15 -0
- package/dist/namespaces/yt/common/config.js +14 -0
- package/dist/namespaces/yt/generate/utils.cjs +2 -4
- package/dist/namespaces/yt/generate/utils.js +1 -3
- package/dist/namespaces/yt/parse/utils.cjs +6 -8
- package/dist/namespaces/yt/parse/utils.js +5 -7
- package/dist/opml/common/types.d.cts +18 -13
- package/dist/opml/common/types.d.ts +18 -13
- package/dist/opml/generate/config.cjs +3 -6
- package/dist/opml/generate/config.js +1 -3
- package/dist/opml/generate/index.cjs +7 -8
- package/dist/opml/generate/index.d.cts +3 -3
- package/dist/opml/generate/index.d.ts +3 -3
- package/dist/opml/generate/index.js +3 -4
- package/dist/opml/generate/utils.cjs +2 -4
- package/dist/opml/generate/utils.js +1 -3
- package/dist/opml/parse/config.cjs +3 -6
- package/dist/opml/parse/config.js +2 -5
- package/dist/opml/parse/index.cjs +13 -8
- package/dist/opml/parse/index.d.cts +2 -3
- package/dist/opml/parse/index.d.ts +2 -3
- package/dist/opml/parse/index.js +10 -5
- package/dist/opml/parse/utils.cjs +20 -22
- package/dist/opml/parse/utils.js +19 -21
- package/package.json +8 -25
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +0 -7
- package/dist/types.d.ts +0 -7
- package/dist/types.js +0 -1
package/dist/common/types.d.cts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
//#region src/common/types.d.ts
|
|
2
|
-
type
|
|
3
|
-
type
|
|
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]> }>;
|
|
4
12
|
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 RemoveUndefined<T> = T extends undefined ? never : T;
|
|
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;
|
|
7
13
|
type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K> }, Exclude<keyof T, K>> : T;
|
|
8
|
-
type
|
|
14
|
+
type Requirable<T> = T | {
|
|
15
|
+
__requirable: T;
|
|
16
|
+
};
|
|
17
|
+
type DateLike = Date | string;
|
|
18
|
+
type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
|
|
19
|
+
type ParseMainOptions<TDate> = {
|
|
9
20
|
maxItems?: number;
|
|
21
|
+
parseDateFn?: (raw: string) => TDate;
|
|
10
22
|
};
|
|
11
23
|
type XmlStylesheet = {
|
|
12
24
|
type: string;
|
|
@@ -16,14 +28,14 @@ type XmlStylesheet = {
|
|
|
16
28
|
charset?: string;
|
|
17
29
|
alternate?: boolean;
|
|
18
30
|
};
|
|
19
|
-
type
|
|
20
|
-
|
|
31
|
+
type GenerateMainXmlOptions<O, S extends boolean> = O & {
|
|
32
|
+
strict?: S;
|
|
21
33
|
stylesheets?: Array<XmlStylesheet>;
|
|
22
34
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
35
|
+
type GenerateMainXml<LV, SV, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? SV : LV, options?: GenerateMainXmlOptions<O, S>) => string;
|
|
36
|
+
type GenerateMainJsonOptions<O, S extends boolean> = O & {
|
|
37
|
+
strict?: S;
|
|
25
38
|
};
|
|
26
|
-
type
|
|
27
|
-
type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
|
|
39
|
+
type GenerateMainJson<LV, SV, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? SV : LV, options?: GenerateMainJsonOptions<O, S>) => unknown;
|
|
28
40
|
//#endregion
|
|
29
|
-
export { DateLike, DeepOmit,
|
|
41
|
+
export { DateLike, DeepOmit, ExtraFields, GenerateMainJson, GenerateMainXml, GenerateMainXmlOptions, ParseMainOptions, Requirable, Strict, XmlStylesheet };
|
package/dist/common/types.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
//#region src/common/types.d.ts
|
|
2
|
-
type
|
|
3
|
-
type
|
|
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]> }>;
|
|
4
12
|
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 RemoveUndefined<T> = T extends undefined ? never : T;
|
|
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;
|
|
7
13
|
type DeepOmit<T, K extends string> = T extends Array<infer U> ? Array<DeepOmit<U, K>> : IsPlainObject<T> extends true ? Pick<{ [P in keyof T]: DeepOmit<T[P], K> }, Exclude<keyof T, K>> : T;
|
|
8
|
-
type
|
|
14
|
+
type Requirable<T> = T | {
|
|
15
|
+
__requirable: T;
|
|
16
|
+
};
|
|
17
|
+
type DateLike = Date | string;
|
|
18
|
+
type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
|
|
19
|
+
type ParseMainOptions<TDate> = {
|
|
9
20
|
maxItems?: number;
|
|
21
|
+
parseDateFn?: (raw: string) => TDate;
|
|
10
22
|
};
|
|
11
23
|
type XmlStylesheet = {
|
|
12
24
|
type: string;
|
|
@@ -16,14 +28,14 @@ type XmlStylesheet = {
|
|
|
16
28
|
charset?: string;
|
|
17
29
|
alternate?: boolean;
|
|
18
30
|
};
|
|
19
|
-
type
|
|
20
|
-
|
|
31
|
+
type GenerateMainXmlOptions<O, S extends boolean> = O & {
|
|
32
|
+
strict?: S;
|
|
21
33
|
stylesheets?: Array<XmlStylesheet>;
|
|
22
34
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
35
|
+
type GenerateMainXml<LV, SV, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? SV : LV, options?: GenerateMainXmlOptions<O, S>) => string;
|
|
36
|
+
type GenerateMainJsonOptions<O, S extends boolean> = O & {
|
|
37
|
+
strict?: S;
|
|
25
38
|
};
|
|
26
|
-
type
|
|
27
|
-
type JsonGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: JsonGenerateOptions<O, F>) => unknown;
|
|
39
|
+
type GenerateMainJson<LV, SV, O = Record<string, unknown>> = <S extends boolean = false>(value: S extends true ? SV : LV, options?: GenerateMainJsonOptions<O, S>) => unknown;
|
|
28
40
|
//#endregion
|
|
29
|
-
export { DateLike, DeepOmit,
|
|
41
|
+
export { DateLike, DeepOmit, ExtraFields, GenerateMainJson, GenerateMainXml, GenerateMainXmlOptions, ParseMainOptions, Requirable, Strict, XmlStylesheet };
|
package/dist/common/utils.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
let entities = require("entities");
|
|
2
|
-
|
|
3
2
|
//#region src/common/utils.ts
|
|
4
3
|
const isPresent = (value) => {
|
|
5
4
|
return value != null;
|
|
@@ -27,13 +26,19 @@ const retrieveRdfResourceOrText = (value, parse) => {
|
|
|
27
26
|
return parse(retrieveText(value));
|
|
28
27
|
};
|
|
29
28
|
const trimObject = (object) => {
|
|
30
|
-
let
|
|
29
|
+
let hasPresent = false;
|
|
30
|
+
let hasAbsent = false;
|
|
31
|
+
for (const key in object) {
|
|
32
|
+
if (isPresent(object[key])) hasPresent = true;
|
|
33
|
+
else hasAbsent = true;
|
|
34
|
+
if (hasPresent && hasAbsent) break;
|
|
35
|
+
}
|
|
36
|
+
if (!hasPresent) return;
|
|
37
|
+
if (!hasAbsent) return object;
|
|
38
|
+
const result = {};
|
|
31
39
|
for (const key in object) {
|
|
32
40
|
const value = object[key];
|
|
33
|
-
if (isPresent(value))
|
|
34
|
-
if (!result) result = {};
|
|
35
|
-
result[key] = value;
|
|
36
|
-
}
|
|
41
|
+
if (isPresent(value)) result[key] = value;
|
|
37
42
|
}
|
|
38
43
|
return result;
|
|
39
44
|
};
|
|
@@ -41,55 +46,64 @@ const trimArray = (value, parse) => {
|
|
|
41
46
|
if (!Array.isArray(value) || value.length === 0) return;
|
|
42
47
|
if (!parse) {
|
|
43
48
|
let needsTrimming = false;
|
|
44
|
-
for (
|
|
49
|
+
for (const item of value) if (!isPresent(item)) {
|
|
45
50
|
needsTrimming = true;
|
|
46
51
|
break;
|
|
47
52
|
}
|
|
48
53
|
if (!needsTrimming) return value;
|
|
49
54
|
}
|
|
50
55
|
const result = [];
|
|
51
|
-
for (
|
|
52
|
-
const item = parse ? parse(
|
|
56
|
+
for (const element of value) {
|
|
57
|
+
const item = parse ? parse(element) : element;
|
|
53
58
|
if (isPresent(item)) result.push(item);
|
|
54
59
|
}
|
|
55
60
|
return result.length > 0 ? result : void 0;
|
|
56
61
|
};
|
|
57
|
-
const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
|
|
58
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
59
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
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
62
|
const cdataStartTag = "<![CDATA[";
|
|
66
63
|
const cdataEndTag = "]]>";
|
|
64
|
+
const commentStartTag = "<!--";
|
|
65
|
+
const commentEndTag = "-->";
|
|
67
66
|
const hasEntities = (text) => {
|
|
68
67
|
const ampIndex = text.indexOf("&");
|
|
69
68
|
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
70
69
|
};
|
|
70
|
+
const stripComments = (text) => {
|
|
71
|
+
let currentIndex = text.indexOf(commentStartTag);
|
|
72
|
+
if (currentIndex === -1) return text;
|
|
73
|
+
let result = "";
|
|
74
|
+
let lastIndex = 0;
|
|
75
|
+
while (currentIndex !== -1) {
|
|
76
|
+
result += text.slice(lastIndex, currentIndex);
|
|
77
|
+
const endIndex = text.indexOf(commentEndTag, currentIndex + 4);
|
|
78
|
+
if (endIndex === -1) return text;
|
|
79
|
+
lastIndex = endIndex + 3;
|
|
80
|
+
currentIndex = text.indexOf(commentStartTag, lastIndex);
|
|
81
|
+
}
|
|
82
|
+
result += text.slice(lastIndex);
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
71
85
|
const decodeWithCdata = (text) => {
|
|
72
86
|
let currentIndex = text.indexOf(cdataStartTag);
|
|
73
87
|
if (currentIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
|
|
74
88
|
let result = "";
|
|
75
89
|
let lastIndex = 0;
|
|
76
90
|
while (currentIndex !== -1) {
|
|
77
|
-
const textBefore = text.
|
|
91
|
+
const textBefore = text.slice(lastIndex, currentIndex);
|
|
78
92
|
result += hasEntities(textBefore) ? (0, entities.decodeHTML)(textBefore) : textBefore;
|
|
79
93
|
const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
|
|
80
94
|
if (endIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
|
|
81
|
-
result += text.
|
|
95
|
+
result += text.slice(currentIndex + 9, endIndex);
|
|
82
96
|
lastIndex = endIndex + 3;
|
|
83
97
|
currentIndex = text.indexOf(cdataStartTag, lastIndex);
|
|
84
98
|
}
|
|
85
|
-
const textAfter = text.
|
|
99
|
+
const textAfter = text.slice(lastIndex);
|
|
86
100
|
result += hasEntities(textAfter) ? (0, entities.decodeHTML)(textAfter) : textAfter;
|
|
87
101
|
return result;
|
|
88
102
|
};
|
|
89
103
|
const parseString = (value) => {
|
|
90
104
|
if (typeof value === "string") {
|
|
91
105
|
if (value === "") return;
|
|
92
|
-
return decodeWithCdata(value).trim() || void 0;
|
|
106
|
+
return decodeWithCdata(stripComments(value)).trim() || void 0;
|
|
93
107
|
}
|
|
94
108
|
if (typeof value === "number") return value.toString();
|
|
95
109
|
};
|
|
@@ -115,8 +129,10 @@ const parseYesNoBoolean = (value) => {
|
|
|
115
129
|
if (boolean !== void 0) return boolean;
|
|
116
130
|
if (isNonEmptyString(value)) return yesRegex.test(value);
|
|
117
131
|
};
|
|
118
|
-
const parseDate = (value) => {
|
|
119
|
-
|
|
132
|
+
const parseDate = (value, parseDateFn) => {
|
|
133
|
+
const raw = parseString(value);
|
|
134
|
+
if (raw === void 0) return;
|
|
135
|
+
return parseDateFn ? parseDateFn(raw) : raw;
|
|
120
136
|
};
|
|
121
137
|
const parseArray = (value) => {
|
|
122
138
|
if (Array.isArray(value)) return value;
|
|
@@ -260,7 +276,7 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
260
276
|
}
|
|
261
277
|
return namespaceAttrs;
|
|
262
278
|
};
|
|
263
|
-
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes,
|
|
279
|
+
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespaces) => {
|
|
264
280
|
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
265
281
|
const normalizeNamespaceUri = (uri) => {
|
|
266
282
|
if (typeof uri !== "string") return uri;
|
|
@@ -271,7 +287,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
271
287
|
}
|
|
272
288
|
return normalized;
|
|
273
289
|
};
|
|
274
|
-
const primaryNamespaceUris =
|
|
290
|
+
const primaryNamespaceUris = primaryNamespaces?.length ? primaryNamespaces.flatMap((key) => namespaceUris[key].map(normalizeNamespaceUri)) : void 0;
|
|
275
291
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
276
292
|
const normalizedUri = normalizeNamespaceUri(uri);
|
|
277
293
|
if (primaryNamespaceUris?.includes(normalizedUri)) return localName;
|
|
@@ -284,7 +300,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
284
300
|
if (isObject(element)) {
|
|
285
301
|
for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
|
|
286
302
|
else if (key.indexOf("@xmlns:") === 0) {
|
|
287
|
-
const prefix = key.
|
|
303
|
+
const prefix = key.slice(7);
|
|
288
304
|
declarations[prefix] = normalizeNamespaceUri(element[key]);
|
|
289
305
|
}
|
|
290
306
|
}
|
|
@@ -296,14 +312,14 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
296
312
|
if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
|
|
297
313
|
return name;
|
|
298
314
|
}
|
|
299
|
-
const prefix = name.
|
|
300
|
-
const unprefixedName = name.
|
|
315
|
+
const prefix = name.slice(0, colonIndex);
|
|
316
|
+
const unprefixedName = name.slice(colonIndex + 1);
|
|
301
317
|
const uri = context[prefix];
|
|
302
318
|
if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
|
|
303
319
|
return name;
|
|
304
320
|
};
|
|
305
321
|
const normalizeKey = (key, context) => {
|
|
306
|
-
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.
|
|
322
|
+
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.slice(1), context, false)}`;
|
|
307
323
|
return normalizeWithContext(key, context, true);
|
|
308
324
|
};
|
|
309
325
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
@@ -336,9 +352,40 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
336
352
|
}
|
|
337
353
|
return normalizedObject;
|
|
338
354
|
};
|
|
355
|
+
const needsNormalization = (object) => {
|
|
356
|
+
const check = (value) => {
|
|
357
|
+
if (Array.isArray(value)) {
|
|
358
|
+
for (const item of value) if (check(item)) return true;
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
if (!isObject(value)) return false;
|
|
362
|
+
for (const key in value) {
|
|
363
|
+
if (key[0] === "@") {
|
|
364
|
+
if (key === "@xmlns") {
|
|
365
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
366
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) continue;
|
|
367
|
+
if (namespacePrefixes[normalizedUri]) return true;
|
|
368
|
+
} else if (key.startsWith("@xmlns:")) {
|
|
369
|
+
const prefix = key.slice(7);
|
|
370
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
371
|
+
const standardPrefix = namespacePrefixes[normalizedUri];
|
|
372
|
+
if (standardPrefix) {
|
|
373
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) return true;
|
|
374
|
+
if (standardPrefix !== prefix) return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (key[0] === "#") continue;
|
|
380
|
+
if (check(value[key])) return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
};
|
|
384
|
+
return check(object);
|
|
385
|
+
};
|
|
339
386
|
const normalizeRoot = (object) => {
|
|
340
387
|
if (!isObject(object)) return object;
|
|
341
|
-
if (
|
|
388
|
+
if (!needsNormalization(object)) return object;
|
|
342
389
|
const normalizedObject = {};
|
|
343
390
|
for (const key in object) {
|
|
344
391
|
const value = object[key];
|
|
@@ -350,21 +397,21 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
350
397
|
};
|
|
351
398
|
return normalizeRoot;
|
|
352
399
|
};
|
|
400
|
+
const startsWithBraceRegex = /^\s*\{/;
|
|
401
|
+
const endsWithBraceRegex = /\}\s*$/;
|
|
353
402
|
const parseJsonObject = (value) => {
|
|
354
403
|
if (isObject(value)) return value;
|
|
355
404
|
if (!isNonEmptyString(value) || value.length < 2) return;
|
|
356
|
-
const startsWithBrace = value.charAt(0) === "{" ||
|
|
357
|
-
const endsWithBrace = value.charAt(value.length - 1) === "}" ||
|
|
405
|
+
const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
|
|
406
|
+
const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
|
|
358
407
|
if (!startsWithBrace || !endsWithBrace) return;
|
|
359
408
|
try {
|
|
360
409
|
return JSON.parse(value);
|
|
361
410
|
} catch {}
|
|
362
411
|
};
|
|
363
|
-
|
|
364
412
|
//#endregion
|
|
365
413
|
exports.createNamespaceNormalizator = createNamespaceNormalizator;
|
|
366
414
|
exports.detectNamespaces = detectNamespaces;
|
|
367
|
-
exports.generateArrayOrSingular = generateArrayOrSingular;
|
|
368
415
|
exports.generateBoolean = generateBoolean;
|
|
369
416
|
exports.generateCdataString = generateCdataString;
|
|
370
417
|
exports.generateCsvOf = generateCsvOf;
|
|
@@ -374,7 +421,6 @@ exports.generatePlainString = generatePlainString;
|
|
|
374
421
|
exports.generateRdfResource = generateRdfResource;
|
|
375
422
|
exports.generateRfc3339Date = generateRfc3339Date;
|
|
376
423
|
exports.generateRfc822Date = generateRfc822Date;
|
|
377
|
-
exports.generateSingularOrArray = generateSingularOrArray;
|
|
378
424
|
exports.generateTextOrCdataString = generateTextOrCdataString;
|
|
379
425
|
exports.generateXml = generateXml;
|
|
380
426
|
exports.generateYesNoBoolean = generateYesNoBoolean;
|
|
@@ -395,4 +441,4 @@ exports.parseYesNoBoolean = parseYesNoBoolean;
|
|
|
395
441
|
exports.retrieveRdfResourceOrText = retrieveRdfResourceOrText;
|
|
396
442
|
exports.retrieveText = retrieveText;
|
|
397
443
|
exports.trimArray = trimArray;
|
|
398
|
-
exports.trimObject = trimObject;
|
|
444
|
+
exports.trimObject = trimObject;
|
package/dist/common/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { decodeHTML } from "entities";
|
|
2
|
-
|
|
3
2
|
//#region src/common/utils.ts
|
|
4
3
|
const isPresent = (value) => {
|
|
5
4
|
return value != null;
|
|
@@ -27,13 +26,19 @@ const retrieveRdfResourceOrText = (value, parse) => {
|
|
|
27
26
|
return parse(retrieveText(value));
|
|
28
27
|
};
|
|
29
28
|
const trimObject = (object) => {
|
|
30
|
-
let
|
|
29
|
+
let hasPresent = false;
|
|
30
|
+
let hasAbsent = false;
|
|
31
|
+
for (const key in object) {
|
|
32
|
+
if (isPresent(object[key])) hasPresent = true;
|
|
33
|
+
else hasAbsent = true;
|
|
34
|
+
if (hasPresent && hasAbsent) break;
|
|
35
|
+
}
|
|
36
|
+
if (!hasPresent) return;
|
|
37
|
+
if (!hasAbsent) return object;
|
|
38
|
+
const result = {};
|
|
31
39
|
for (const key in object) {
|
|
32
40
|
const value = object[key];
|
|
33
|
-
if (isPresent(value))
|
|
34
|
-
if (!result) result = {};
|
|
35
|
-
result[key] = value;
|
|
36
|
-
}
|
|
41
|
+
if (isPresent(value)) result[key] = value;
|
|
37
42
|
}
|
|
38
43
|
return result;
|
|
39
44
|
};
|
|
@@ -41,55 +46,64 @@ const trimArray = (value, parse) => {
|
|
|
41
46
|
if (!Array.isArray(value) || value.length === 0) return;
|
|
42
47
|
if (!parse) {
|
|
43
48
|
let needsTrimming = false;
|
|
44
|
-
for (
|
|
49
|
+
for (const item of value) if (!isPresent(item)) {
|
|
45
50
|
needsTrimming = true;
|
|
46
51
|
break;
|
|
47
52
|
}
|
|
48
53
|
if (!needsTrimming) return value;
|
|
49
54
|
}
|
|
50
55
|
const result = [];
|
|
51
|
-
for (
|
|
52
|
-
const item = parse ? parse(
|
|
56
|
+
for (const element of value) {
|
|
57
|
+
const item = parse ? parse(element) : element;
|
|
53
58
|
if (isPresent(item)) result.push(item);
|
|
54
59
|
}
|
|
55
60
|
return result.length > 0 ? result : void 0;
|
|
56
61
|
};
|
|
57
|
-
const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
|
|
58
|
-
if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
|
|
59
|
-
if (isPresent(singularValue)) return generator(singularValue);
|
|
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
62
|
const cdataStartTag = "<![CDATA[";
|
|
66
63
|
const cdataEndTag = "]]>";
|
|
64
|
+
const commentStartTag = "<!--";
|
|
65
|
+
const commentEndTag = "-->";
|
|
67
66
|
const hasEntities = (text) => {
|
|
68
67
|
const ampIndex = text.indexOf("&");
|
|
69
68
|
return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
|
|
70
69
|
};
|
|
70
|
+
const stripComments = (text) => {
|
|
71
|
+
let currentIndex = text.indexOf(commentStartTag);
|
|
72
|
+
if (currentIndex === -1) return text;
|
|
73
|
+
let result = "";
|
|
74
|
+
let lastIndex = 0;
|
|
75
|
+
while (currentIndex !== -1) {
|
|
76
|
+
result += text.slice(lastIndex, currentIndex);
|
|
77
|
+
const endIndex = text.indexOf(commentEndTag, currentIndex + 4);
|
|
78
|
+
if (endIndex === -1) return text;
|
|
79
|
+
lastIndex = endIndex + 3;
|
|
80
|
+
currentIndex = text.indexOf(commentStartTag, lastIndex);
|
|
81
|
+
}
|
|
82
|
+
result += text.slice(lastIndex);
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
71
85
|
const decodeWithCdata = (text) => {
|
|
72
86
|
let currentIndex = text.indexOf(cdataStartTag);
|
|
73
87
|
if (currentIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
|
|
74
88
|
let result = "";
|
|
75
89
|
let lastIndex = 0;
|
|
76
90
|
while (currentIndex !== -1) {
|
|
77
|
-
const textBefore = text.
|
|
91
|
+
const textBefore = text.slice(lastIndex, currentIndex);
|
|
78
92
|
result += hasEntities(textBefore) ? decodeHTML(textBefore) : textBefore;
|
|
79
93
|
const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
|
|
80
94
|
if (endIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
|
|
81
|
-
result += text.
|
|
95
|
+
result += text.slice(currentIndex + 9, endIndex);
|
|
82
96
|
lastIndex = endIndex + 3;
|
|
83
97
|
currentIndex = text.indexOf(cdataStartTag, lastIndex);
|
|
84
98
|
}
|
|
85
|
-
const textAfter = text.
|
|
99
|
+
const textAfter = text.slice(lastIndex);
|
|
86
100
|
result += hasEntities(textAfter) ? decodeHTML(textAfter) : textAfter;
|
|
87
101
|
return result;
|
|
88
102
|
};
|
|
89
103
|
const parseString = (value) => {
|
|
90
104
|
if (typeof value === "string") {
|
|
91
105
|
if (value === "") return;
|
|
92
|
-
return decodeWithCdata(value).trim() || void 0;
|
|
106
|
+
return decodeWithCdata(stripComments(value)).trim() || void 0;
|
|
93
107
|
}
|
|
94
108
|
if (typeof value === "number") return value.toString();
|
|
95
109
|
};
|
|
@@ -115,8 +129,10 @@ const parseYesNoBoolean = (value) => {
|
|
|
115
129
|
if (boolean !== void 0) return boolean;
|
|
116
130
|
if (isNonEmptyString(value)) return yesRegex.test(value);
|
|
117
131
|
};
|
|
118
|
-
const parseDate = (value) => {
|
|
119
|
-
|
|
132
|
+
const parseDate = (value, parseDateFn) => {
|
|
133
|
+
const raw = parseString(value);
|
|
134
|
+
if (raw === void 0) return;
|
|
135
|
+
return parseDateFn ? parseDateFn(raw) : raw;
|
|
120
136
|
};
|
|
121
137
|
const parseArray = (value) => {
|
|
122
138
|
if (Array.isArray(value)) return value;
|
|
@@ -260,7 +276,7 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
260
276
|
}
|
|
261
277
|
return namespaceAttrs;
|
|
262
278
|
};
|
|
263
|
-
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes,
|
|
279
|
+
const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNamespaces) => {
|
|
264
280
|
const normalizedUriCache = /* @__PURE__ */ new Map();
|
|
265
281
|
const normalizeNamespaceUri = (uri) => {
|
|
266
282
|
if (typeof uri !== "string") return uri;
|
|
@@ -271,7 +287,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
271
287
|
}
|
|
272
288
|
return normalized;
|
|
273
289
|
};
|
|
274
|
-
const primaryNamespaceUris =
|
|
290
|
+
const primaryNamespaceUris = primaryNamespaces?.length ? primaryNamespaces.flatMap((key) => namespaceUris[key].map(normalizeNamespaceUri)) : void 0;
|
|
275
291
|
const resolveNamespacePrefix = (uri, localName, fallback) => {
|
|
276
292
|
const normalizedUri = normalizeNamespaceUri(uri);
|
|
277
293
|
if (primaryNamespaceUris?.includes(normalizedUri)) return localName;
|
|
@@ -284,7 +300,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
284
300
|
if (isObject(element)) {
|
|
285
301
|
for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
|
|
286
302
|
else if (key.indexOf("@xmlns:") === 0) {
|
|
287
|
-
const prefix = key.
|
|
303
|
+
const prefix = key.slice(7);
|
|
288
304
|
declarations[prefix] = normalizeNamespaceUri(element[key]);
|
|
289
305
|
}
|
|
290
306
|
}
|
|
@@ -296,14 +312,14 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
296
312
|
if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
|
|
297
313
|
return name;
|
|
298
314
|
}
|
|
299
|
-
const prefix = name.
|
|
300
|
-
const unprefixedName = name.
|
|
315
|
+
const prefix = name.slice(0, colonIndex);
|
|
316
|
+
const unprefixedName = name.slice(colonIndex + 1);
|
|
301
317
|
const uri = context[prefix];
|
|
302
318
|
if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
|
|
303
319
|
return name;
|
|
304
320
|
};
|
|
305
321
|
const normalizeKey = (key, context) => {
|
|
306
|
-
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.
|
|
322
|
+
if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.slice(1), context, false)}`;
|
|
307
323
|
return normalizeWithContext(key, context, true);
|
|
308
324
|
};
|
|
309
325
|
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
@@ -336,9 +352,40 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
336
352
|
}
|
|
337
353
|
return normalizedObject;
|
|
338
354
|
};
|
|
355
|
+
const needsNormalization = (object) => {
|
|
356
|
+
const check = (value) => {
|
|
357
|
+
if (Array.isArray(value)) {
|
|
358
|
+
for (const item of value) if (check(item)) return true;
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
if (!isObject(value)) return false;
|
|
362
|
+
for (const key in value) {
|
|
363
|
+
if (key[0] === "@") {
|
|
364
|
+
if (key === "@xmlns") {
|
|
365
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
366
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) continue;
|
|
367
|
+
if (namespacePrefixes[normalizedUri]) return true;
|
|
368
|
+
} else if (key.startsWith("@xmlns:")) {
|
|
369
|
+
const prefix = key.slice(7);
|
|
370
|
+
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
371
|
+
const standardPrefix = namespacePrefixes[normalizedUri];
|
|
372
|
+
if (standardPrefix) {
|
|
373
|
+
if (primaryNamespaceUris?.includes(normalizedUri)) return true;
|
|
374
|
+
if (standardPrefix !== prefix) return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (key[0] === "#") continue;
|
|
380
|
+
if (check(value[key])) return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
};
|
|
384
|
+
return check(object);
|
|
385
|
+
};
|
|
339
386
|
const normalizeRoot = (object) => {
|
|
340
387
|
if (!isObject(object)) return object;
|
|
341
|
-
if (
|
|
388
|
+
if (!needsNormalization(object)) return object;
|
|
342
389
|
const normalizedObject = {};
|
|
343
390
|
for (const key in object) {
|
|
344
391
|
const value = object[key];
|
|
@@ -350,16 +397,17 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
|
|
|
350
397
|
};
|
|
351
398
|
return normalizeRoot;
|
|
352
399
|
};
|
|
400
|
+
const startsWithBraceRegex = /^\s*\{/;
|
|
401
|
+
const endsWithBraceRegex = /\}\s*$/;
|
|
353
402
|
const parseJsonObject = (value) => {
|
|
354
403
|
if (isObject(value)) return value;
|
|
355
404
|
if (!isNonEmptyString(value) || value.length < 2) return;
|
|
356
|
-
const startsWithBrace = value.charAt(0) === "{" ||
|
|
357
|
-
const endsWithBrace = value.charAt(value.length - 1) === "}" ||
|
|
405
|
+
const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
|
|
406
|
+
const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
|
|
358
407
|
if (!startsWithBrace || !endsWithBrace) return;
|
|
359
408
|
try {
|
|
360
409
|
return JSON.parse(value);
|
|
361
410
|
} catch {}
|
|
362
411
|
};
|
|
363
|
-
|
|
364
412
|
//#endregion
|
|
365
|
-
export { createNamespaceNormalizator, detectNamespaces,
|
|
413
|
+
export { createNamespaceNormalizator, detectNamespaces, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateTextOrCdataString, generateXml, generateYesNoBoolean, isNonEmptyString, isNonEmptyStringOrNumber, isObject, isPresent, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
|