feedsmith 2.9.2 → 3.0.0-beta.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.
Files changed (156) hide show
  1. package/README.md +3 -9
  2. package/dist/common/config.cjs +2 -1
  3. package/dist/common/config.js +2 -1
  4. package/dist/common/errors.cjs +30 -0
  5. package/dist/common/errors.d.cts +15 -0
  6. package/dist/common/errors.d.ts +15 -0
  7. package/dist/common/errors.js +27 -0
  8. package/dist/common/parse.cjs +2 -1
  9. package/dist/common/parse.d.cts +10 -11
  10. package/dist/common/parse.d.ts +10 -11
  11. package/dist/common/parse.js +2 -1
  12. package/dist/common/types.d.cts +24 -12
  13. package/dist/common/types.d.ts +24 -12
  14. package/dist/common/utils.cjs +6 -14
  15. package/dist/common/utils.js +7 -13
  16. package/dist/feeds/atom/common/types.d.cts +65 -52
  17. package/dist/feeds/atom/common/types.d.ts +65 -52
  18. package/dist/feeds/atom/generate/index.cjs +2 -1
  19. package/dist/feeds/atom/generate/index.d.cts +2 -2
  20. package/dist/feeds/atom/generate/index.d.ts +2 -2
  21. package/dist/feeds/atom/generate/index.js +2 -1
  22. package/dist/feeds/atom/generate/utils.cjs +23 -6
  23. package/dist/feeds/atom/generate/utils.js +20 -3
  24. package/dist/feeds/atom/parse/index.cjs +10 -3
  25. package/dist/feeds/atom/parse/index.d.cts +2 -2
  26. package/dist/feeds/atom/parse/index.d.ts +2 -2
  27. package/dist/feeds/atom/parse/index.js +10 -3
  28. package/dist/feeds/atom/parse/utils.cjs +61 -31
  29. package/dist/feeds/atom/parse/utils.js +59 -29
  30. package/dist/feeds/json/common/types.d.cts +19 -19
  31. package/dist/feeds/json/common/types.d.ts +19 -19
  32. package/dist/feeds/json/generate/index.cjs +5 -1
  33. package/dist/feeds/json/generate/index.d.cts +2 -2
  34. package/dist/feeds/json/generate/index.d.ts +2 -2
  35. package/dist/feeds/json/generate/index.js +5 -1
  36. package/dist/feeds/json/generate/utils.cjs +7 -2
  37. package/dist/feeds/json/generate/utils.js +8 -3
  38. package/dist/feeds/json/parse/index.cjs +3 -2
  39. package/dist/feeds/json/parse/index.d.cts +2 -2
  40. package/dist/feeds/json/parse/index.d.ts +2 -2
  41. package/dist/feeds/json/parse/index.js +3 -2
  42. package/dist/feeds/json/parse/utils.cjs +4 -4
  43. package/dist/feeds/json/parse/utils.js +4 -4
  44. package/dist/feeds/rdf/common/types.d.cts +31 -28
  45. package/dist/feeds/rdf/common/types.d.ts +31 -28
  46. package/dist/feeds/rdf/parse/index.cjs +10 -3
  47. package/dist/feeds/rdf/parse/index.d.cts +2 -2
  48. package/dist/feeds/rdf/parse/index.d.ts +2 -2
  49. package/dist/feeds/rdf/parse/index.js +10 -3
  50. package/dist/feeds/rdf/parse/utils.cjs +23 -20
  51. package/dist/feeds/rdf/parse/utils.js +15 -12
  52. package/dist/feeds/rss/common/types.d.cts +76 -74
  53. package/dist/feeds/rss/common/types.d.ts +76 -74
  54. package/dist/feeds/rss/generate/index.cjs +2 -1
  55. package/dist/feeds/rss/generate/index.d.cts +2 -2
  56. package/dist/feeds/rss/generate/index.d.ts +2 -2
  57. package/dist/feeds/rss/generate/index.js +2 -1
  58. package/dist/feeds/rss/generate/utils.cjs +36 -36
  59. package/dist/feeds/rss/generate/utils.js +10 -10
  60. package/dist/feeds/rss/parse/index.cjs +10 -3
  61. package/dist/feeds/rss/parse/index.d.cts +2 -2
  62. package/dist/feeds/rss/parse/index.d.ts +2 -2
  63. package/dist/feeds/rss/parse/index.js +10 -3
  64. package/dist/feeds/rss/parse/utils.cjs +138 -38
  65. package/dist/feeds/rss/parse/utils.js +119 -19
  66. package/dist/index.cjs +5 -0
  67. package/dist/index.d.cts +37 -16
  68. package/dist/index.d.ts +37 -16
  69. package/dist/index.js +2 -1
  70. package/dist/namespaces/app/common/types.d.cts +1 -3
  71. package/dist/namespaces/app/common/types.d.ts +1 -3
  72. package/dist/namespaces/app/parse/utils.cjs +2 -2
  73. package/dist/namespaces/app/parse/utils.js +2 -2
  74. package/dist/namespaces/atom/common/types.d.cts +3 -3
  75. package/dist/namespaces/atom/common/types.d.ts +3 -3
  76. package/dist/namespaces/atom/parse/utils.cjs +4 -2
  77. package/dist/namespaces/atom/parse/utils.js +4 -2
  78. package/dist/namespaces/dc/common/types.d.cts +4 -19
  79. package/dist/namespaces/dc/common/types.d.ts +4 -19
  80. package/dist/namespaces/dc/generate/utils.cjs +15 -15
  81. package/dist/namespaces/dc/generate/utils.js +16 -16
  82. package/dist/namespaces/dc/parse/utils.cjs +4 -17
  83. package/dist/namespaces/dc/parse/utils.js +5 -18
  84. package/dist/namespaces/dcterms/common/types.d.cts +23 -59
  85. package/dist/namespaces/dcterms/common/types.d.ts +23 -59
  86. package/dist/namespaces/dcterms/generate/utils.cjs +55 -55
  87. package/dist/namespaces/dcterms/generate/utils.js +56 -56
  88. package/dist/namespaces/dcterms/parse/utils.cjs +23 -57
  89. package/dist/namespaces/dcterms/parse/utils.js +24 -58
  90. package/dist/namespaces/georss/common/types.d.cts +21 -19
  91. package/dist/namespaces/georss/common/types.d.ts +21 -19
  92. package/dist/namespaces/georss/generate/utils.cjs +2 -2
  93. package/dist/namespaces/georss/generate/utils.js +2 -2
  94. package/dist/namespaces/googleplay/common/types.d.cts +9 -7
  95. package/dist/namespaces/googleplay/common/types.d.ts +9 -7
  96. package/dist/namespaces/itunes/common/types.d.cts +9 -5
  97. package/dist/namespaces/itunes/common/types.d.ts +9 -5
  98. package/dist/namespaces/media/common/types.d.cts +85 -84
  99. package/dist/namespaces/media/common/types.d.ts +85 -84
  100. package/dist/namespaces/media/generate/utils.cjs +1 -1
  101. package/dist/namespaces/media/generate/utils.js +2 -2
  102. package/dist/namespaces/media/parse/utils.cjs +1 -2
  103. package/dist/namespaces/media/parse/utils.js +1 -2
  104. package/dist/namespaces/opensearch/common/types.d.cts +7 -5
  105. package/dist/namespaces/opensearch/common/types.d.ts +7 -5
  106. package/dist/namespaces/podcast/common/types.d.cts +136 -142
  107. package/dist/namespaces/podcast/common/types.d.ts +136 -142
  108. package/dist/namespaces/podcast/generate/utils.cjs +6 -6
  109. package/dist/namespaces/podcast/generate/utils.js +7 -7
  110. package/dist/namespaces/podcast/parse/utils.cjs +13 -19
  111. package/dist/namespaces/podcast/parse/utils.js +13 -19
  112. package/dist/namespaces/prism/common/types.d.cts +2 -4
  113. package/dist/namespaces/prism/common/types.d.ts +2 -4
  114. package/dist/namespaces/prism/parse/utils.cjs +19 -19
  115. package/dist/namespaces/prism/parse/utils.js +19 -19
  116. package/dist/namespaces/psc/common/types.d.cts +8 -6
  117. package/dist/namespaces/psc/common/types.d.ts +8 -6
  118. package/dist/namespaces/rawvoice/common/types.d.cts +24 -24
  119. package/dist/namespaces/rawvoice/common/types.d.ts +24 -24
  120. package/dist/namespaces/rawvoice/parse/utils.cjs +7 -7
  121. package/dist/namespaces/rawvoice/parse/utils.js +7 -7
  122. package/dist/namespaces/source/common/types.d.cts +20 -18
  123. package/dist/namespaces/source/common/types.d.ts +20 -18
  124. package/dist/namespaces/spotify/common/types.d.cts +22 -20
  125. package/dist/namespaces/spotify/common/types.d.ts +22 -20
  126. package/dist/namespaces/sy/common/types.d.cts +1 -3
  127. package/dist/namespaces/sy/common/types.d.ts +1 -3
  128. package/dist/namespaces/sy/parse/utils.cjs +2 -2
  129. package/dist/namespaces/sy/parse/utils.js +2 -2
  130. package/dist/namespaces/thr/common/types.d.cts +7 -7
  131. package/dist/namespaces/thr/common/types.d.ts +7 -7
  132. package/dist/namespaces/thr/parse/utils.cjs +2 -2
  133. package/dist/namespaces/thr/parse/utils.js +2 -2
  134. package/dist/namespaces/xml/common/types.d.cts +11 -0
  135. package/dist/namespaces/xml/common/types.d.ts +11 -0
  136. package/dist/namespaces/xml/generate/utils.cjs +13 -0
  137. package/dist/namespaces/xml/generate/utils.js +13 -0
  138. package/dist/namespaces/xml/parse/utils.cjs +13 -0
  139. package/dist/namespaces/xml/parse/utils.js +13 -0
  140. package/dist/opml/common/types.d.cts +18 -13
  141. package/dist/opml/common/types.d.ts +18 -13
  142. package/dist/opml/generate/index.cjs +2 -1
  143. package/dist/opml/generate/index.d.cts +3 -3
  144. package/dist/opml/generate/index.d.ts +3 -3
  145. package/dist/opml/generate/index.js +2 -1
  146. package/dist/opml/parse/index.cjs +9 -2
  147. package/dist/opml/parse/index.d.cts +2 -3
  148. package/dist/opml/parse/index.d.ts +2 -3
  149. package/dist/opml/parse/index.js +9 -2
  150. package/dist/opml/parse/utils.cjs +5 -5
  151. package/dist/opml/parse/utils.js +5 -5
  152. package/package.json +2 -19
  153. package/dist/types.cjs +0 -0
  154. package/dist/types.d.cts +0 -7
  155. package/dist/types.d.ts +0 -7
  156. package/dist/types.js +0 -1
package/README.md CHANGED
@@ -18,13 +18,6 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
18
18
 
19
19
  ---
20
20
 
21
- > [!IMPORTANT]
22
- > **Feedsmith 3.x is in final stages of development.** Check out the [v3.x guide](https://v3.feedsmith.dev/migration/v2-to-v3) to explore new features and learn how to upgrade. Install it with:
23
- >
24
- > `npm install feedsmith@next`
25
-
26
- ---
27
-
28
21
  ## Features
29
22
 
30
23
  ### Core
@@ -53,7 +46,7 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
53
46
 
54
47
  ## Supported Formats
55
48
 
56
- Feedsmith aims to fully support all major feed formats and namespaces in complete alignment with their specifications.
49
+ Feedsmith aims to fully support all major feed formats and namespaces in complete alignment with their specs.
57
50
 
58
51
  ✅ Available
59
52
    ·  
@@ -112,6 +105,7 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
112
105
  | [W3C Basic Geo](https://feedsmith.dev/reference/namespaces/geo) | `<geo:*>` | RSS, Atom | ✅ | ✅ |
113
106
  | [GeoRSS Simple](https://feedsmith.dev/reference/namespaces/georss) | `<georss:*>` | RSS, Atom, RDF | ✅ | ✅ |
114
107
  | [RDF](https://feedsmith.dev/reference/namespaces/rdf) | `<rdf:*>` | RDF | ✅ | ✅ |
108
+ | [XML](https://feedsmith.dev/reference/namespaces/xml) | `<xml:*>` | RSS, Atom, RDF | ✅ | ✅ |
115
109
 
116
110
  ## Quick Start
117
111
 
@@ -231,7 +225,7 @@ try {
231
225
  Feedsmith provides comprehensive TypeScript types for all feed formats:
232
226
 
233
227
  ```typescript
234
- import type { Rss, Atom, Json, Opml } from 'feedsmith/types'
228
+ import type { Rss, Atom, Json, Opml } from 'feedsmith'
235
229
 
236
230
  // Access all types for a format
237
231
  type Feed = Rss.Feed
@@ -62,7 +62,8 @@ const locales = {
62
62
  invalidOpmlFormat: "Invalid OPML format",
63
63
  invalidInputOpml: "Invalid input OPML",
64
64
  invalidInputAtom: "Invalid input Atom",
65
- invalidInputRss: "Invalid input RSS"
65
+ invalidInputRss: "Invalid input RSS",
66
+ invalidInputJson: "Invalid input JSON"
66
67
  };
67
68
  const namespaceUris = {
68
69
  admin: require_config$1.uris,
@@ -62,7 +62,8 @@ const locales = {
62
62
  invalidOpmlFormat: "Invalid OPML format",
63
63
  invalidInputOpml: "Invalid input OPML",
64
64
  invalidInputAtom: "Invalid input Atom",
65
- invalidInputRss: "Invalid input RSS"
65
+ invalidInputRss: "Invalid input RSS",
66
+ invalidInputJson: "Invalid input JSON"
66
67
  };
67
68
  const namespaceUris = {
68
69
  admin: uris$1,
@@ -0,0 +1,30 @@
1
+ //#region src/common/errors.ts
2
+ var DetectError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "DetectError";
6
+ }
7
+ };
8
+ var GenerateError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "GenerateError";
12
+ }
13
+ };
14
+ var MalformedError = class extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "MalformedError";
18
+ }
19
+ };
20
+ var ParseError = class extends Error {
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = "ParseError";
24
+ }
25
+ };
26
+ //#endregion
27
+ exports.DetectError = DetectError;
28
+ exports.GenerateError = GenerateError;
29
+ exports.MalformedError = MalformedError;
30
+ exports.ParseError = ParseError;
@@ -0,0 +1,15 @@
1
+ //#region src/common/errors.d.ts
2
+ declare class DetectError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ declare class GenerateError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ declare class MalformedError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ declare class ParseError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ //#endregion
15
+ export { DetectError, GenerateError, MalformedError, ParseError };
@@ -0,0 +1,15 @@
1
+ //#region src/common/errors.d.ts
2
+ declare class DetectError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ declare class GenerateError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ declare class MalformedError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ declare class ParseError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ //#endregion
15
+ export { DetectError, GenerateError, MalformedError, ParseError };
@@ -0,0 +1,27 @@
1
+ //#region src/common/errors.ts
2
+ var DetectError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "DetectError";
6
+ }
7
+ };
8
+ var GenerateError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "GenerateError";
12
+ }
13
+ };
14
+ var MalformedError = class extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "MalformedError";
18
+ }
19
+ };
20
+ var ParseError = class extends Error {
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = "ParseError";
24
+ }
25
+ };
26
+ //#endregion
27
+ export { DetectError, GenerateError, MalformedError, ParseError };
@@ -1,3 +1,4 @@
1
+ const require_errors = require("./errors.cjs");
1
2
  const require_config = require("./config.cjs");
2
3
  const require_utils = require("./utils.cjs");
3
4
  const require_index = require("../feeds/atom/detect/index.cjs");
@@ -27,7 +28,7 @@ const parse = (value, options) => {
27
28
  format: "json",
28
29
  feed: require_index$3.parse(json, options)
29
30
  };
30
- throw new Error(require_config.locales.unrecognizedFeedFormat);
31
+ throw new require_errors.DetectError(require_config.locales.unrecognizedFeedFormat);
31
32
  };
32
33
  //#endregion
33
34
  exports.parse = parse;
@@ -1,23 +1,22 @@
1
- import { DeepPartial, ParseOptions } from "./types.cjs";
1
+ import { ParseMainOptions } 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";
5
5
  import { Rss } from "../feeds/rss/common/types.cjs";
6
6
 
7
7
  //#region src/common/parse.d.ts
8
- type Parse = (value: unknown, options?: ParseOptions) => {
9
- format: 'rss';
10
- feed: DeepPartial<Rss.Feed<string>>;
8
+ declare const parse: <TDate = string>(value: unknown, options?: ParseMainOptions<TDate>) => {
9
+ format: "rss";
10
+ feed: Rss.Feed<TDate>;
11
11
  } | {
12
- format: 'atom';
13
- feed: DeepPartial<Atom.Feed<string>>;
12
+ format: "atom";
13
+ feed: Atom.Feed<TDate>;
14
14
  } | {
15
- format: 'rdf';
16
- feed: DeepPartial<Rdf.Feed<string>>;
15
+ format: "rdf";
16
+ feed: Rdf.Feed<TDate>;
17
17
  } | {
18
- format: 'json';
19
- feed: DeepPartial<Json.Feed<string>>;
18
+ format: "json";
19
+ feed: Json.Feed<TDate>;
20
20
  };
21
- declare const parse: Parse;
22
21
  //#endregion
23
22
  export { parse };
@@ -1,23 +1,22 @@
1
- import { DeepPartial, ParseOptions } from "./types.js";
1
+ import { ParseMainOptions } 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";
5
5
  import { Rss } from "../feeds/rss/common/types.js";
6
6
 
7
7
  //#region src/common/parse.d.ts
8
- type Parse = (value: unknown, options?: ParseOptions) => {
9
- format: 'rss';
10
- feed: DeepPartial<Rss.Feed<string>>;
8
+ declare const parse: <TDate = string>(value: unknown, options?: ParseMainOptions<TDate>) => {
9
+ format: "rss";
10
+ feed: Rss.Feed<TDate>;
11
11
  } | {
12
- format: 'atom';
13
- feed: DeepPartial<Atom.Feed<string>>;
12
+ format: "atom";
13
+ feed: Atom.Feed<TDate>;
14
14
  } | {
15
- format: 'rdf';
16
- feed: DeepPartial<Rdf.Feed<string>>;
15
+ format: "rdf";
16
+ feed: Rdf.Feed<TDate>;
17
17
  } | {
18
- format: 'json';
19
- feed: DeepPartial<Json.Feed<string>>;
18
+ format: "json";
19
+ feed: Json.Feed<TDate>;
20
20
  };
21
- declare const parse: Parse;
22
21
  //#endregion
23
22
  export { parse };
@@ -1,3 +1,4 @@
1
+ import { DetectError } from "./errors.js";
1
2
  import { locales } from "./config.js";
2
3
  import { parseJsonObject } from "./utils.js";
3
4
  import { detect } from "../feeds/atom/detect/index.js";
@@ -27,7 +28,7 @@ const parse = (value, options) => {
27
28
  format: "json",
28
29
  feed: parse$2(json, options)
29
30
  };
30
- throw new Error(locales.unrecognizedFeedFormat);
31
+ throw new DetectError(locales.unrecognizedFeedFormat);
31
32
  };
32
33
  //#endregion
33
34
  export { parse };
@@ -1,12 +1,24 @@
1
1
  //#region src/common/types.d.ts
2
- type DateLike = Date | string;
3
- type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
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 ParseOptions = {
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 XmlGenerateOptions<O, F extends boolean = false> = O & {
20
- lenient?: F;
31
+ type GenerateMainXmlOptions<O, S extends boolean> = O & {
32
+ strict?: S;
21
33
  stylesheets?: Array<XmlStylesheet>;
22
34
  };
23
- type JsonGenerateOptions<O, F extends boolean = false> = O & {
24
- lenient?: F;
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 XmlGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: XmlGenerateOptions<O, F>) => string;
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, DeepPartial, ExtraFields, JsonGenerateMain, ParseOptions, XmlGenerateMain, XmlGenerateOptions };
41
+ export { DateLike, DeepOmit, ExtraFields, GenerateMainJson, GenerateMainXml, GenerateMainXmlOptions, ParseMainOptions, Requirable, Strict, XmlStylesheet };
@@ -1,12 +1,24 @@
1
1
  //#region src/common/types.d.ts
2
- type DateLike = Date | string;
3
- type ExtraFields<F extends ReadonlyArray<string>, V = unknown> = { [K in F[number]]?: V };
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 ParseOptions = {
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 XmlGenerateOptions<O, F extends boolean = false> = O & {
20
- lenient?: F;
31
+ type GenerateMainXmlOptions<O, S extends boolean> = O & {
32
+ strict?: S;
21
33
  stylesheets?: Array<XmlStylesheet>;
22
34
  };
23
- type JsonGenerateOptions<O, F extends boolean = false> = O & {
24
- lenient?: F;
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 XmlGenerateMain<S, L, O = Record<string, unknown>> = <F extends boolean = false>(value: F extends true ? L : S, options?: XmlGenerateOptions<O, F>) => string;
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, DeepPartial, ExtraFields, JsonGenerateMain, ParseOptions, XmlGenerateMain, XmlGenerateOptions };
41
+ export { DateLike, DeepOmit, ExtraFields, GenerateMainJson, GenerateMainXml, GenerateMainXmlOptions, ParseMainOptions, Requirable, Strict, XmlStylesheet };
@@ -59,18 +59,10 @@ const trimArray = (value, parse) => {
59
59
  }
60
60
  return result.length > 0 ? result : void 0;
61
61
  };
62
- const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
63
- if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
64
- if (isPresent(singularValue)) return generator(singularValue);
65
- };
66
- const generateSingularOrArray = (singularValue, pluralValues, generator) => {
67
- if (isPresent(singularValue)) return generator(singularValue);
68
- if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
69
- };
70
- const commentStartTag = "<!--";
71
- const commentEndTag = "-->";
72
62
  const cdataStartTag = "<![CDATA[";
73
63
  const cdataEndTag = "]]>";
64
+ const commentStartTag = "<!--";
65
+ const commentEndTag = "-->";
74
66
  const hasEntities = (text) => {
75
67
  const ampIndex = text.indexOf("&");
76
68
  return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
@@ -137,8 +129,10 @@ const parseYesNoBoolean = (value) => {
137
129
  if (boolean !== void 0) return boolean;
138
130
  if (isNonEmptyString(value)) return yesRegex.test(value);
139
131
  };
140
- const parseDate = (value) => {
141
- return parseString(value);
132
+ const parseDate = (value, parseDateFn) => {
133
+ const raw = parseString(value);
134
+ if (raw === void 0) return;
135
+ return parseDateFn ? parseDateFn(raw) : raw;
142
136
  };
143
137
  const parseArray = (value) => {
144
138
  if (Array.isArray(value)) return value;
@@ -439,7 +433,6 @@ const expandStopNodes = (stopNodes, feedContainerPaths) => {
439
433
  exports.createNamespaceNormalizator = createNamespaceNormalizator;
440
434
  exports.detectNamespaces = detectNamespaces;
441
435
  exports.expandStopNodes = expandStopNodes;
442
- exports.generateArrayOrSingular = generateArrayOrSingular;
443
436
  exports.generateBoolean = generateBoolean;
444
437
  exports.generateCdataString = generateCdataString;
445
438
  exports.generateCsvOf = generateCsvOf;
@@ -449,7 +442,6 @@ exports.generatePlainString = generatePlainString;
449
442
  exports.generateRdfResource = generateRdfResource;
450
443
  exports.generateRfc3339Date = generateRfc3339Date;
451
444
  exports.generateRfc822Date = generateRfc822Date;
452
- exports.generateSingularOrArray = generateSingularOrArray;
453
445
  exports.generateTextOrCdataString = generateTextOrCdataString;
454
446
  exports.generateXml = generateXml;
455
447
  exports.generateYesNoBoolean = generateYesNoBoolean;
@@ -59,18 +59,10 @@ const trimArray = (value, parse) => {
59
59
  }
60
60
  return result.length > 0 ? result : void 0;
61
61
  };
62
- const generateArrayOrSingular = (pluralValues, singularValue, generator) => {
63
- if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
64
- if (isPresent(singularValue)) return generator(singularValue);
65
- };
66
- const generateSingularOrArray = (singularValue, pluralValues, generator) => {
67
- if (isPresent(singularValue)) return generator(singularValue);
68
- if (isPresent(pluralValues)) return trimArray(pluralValues.map(generator));
69
- };
70
- const commentStartTag = "<!--";
71
- const commentEndTag = "-->";
72
62
  const cdataStartTag = "<![CDATA[";
73
63
  const cdataEndTag = "]]>";
64
+ const commentStartTag = "<!--";
65
+ const commentEndTag = "-->";
74
66
  const hasEntities = (text) => {
75
67
  const ampIndex = text.indexOf("&");
76
68
  return ampIndex !== -1 && text.indexOf(";", ampIndex) !== -1;
@@ -137,8 +129,10 @@ const parseYesNoBoolean = (value) => {
137
129
  if (boolean !== void 0) return boolean;
138
130
  if (isNonEmptyString(value)) return yesRegex.test(value);
139
131
  };
140
- const parseDate = (value) => {
141
- return parseString(value);
132
+ const parseDate = (value, parseDateFn) => {
133
+ const raw = parseString(value);
134
+ if (raw === void 0) return;
135
+ return parseDateFn ? parseDateFn(raw) : raw;
142
136
  };
143
137
  const parseArray = (value) => {
144
138
  if (Array.isArray(value)) return value;
@@ -436,4 +430,4 @@ const expandStopNodes = (stopNodes, feedContainerPaths) => {
436
430
  return [...set];
437
431
  };
438
432
  //#endregion
439
- export { createNamespaceNormalizator, detectNamespaces, expandStopNodes, generateArrayOrSingular, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateSingularOrArray, generateTextOrCdataString, generateXml, generateYesNoBoolean, isNonEmptyString, isNonEmptyStringOrNumber, isObject, isPresent, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
433
+ export { createNamespaceNormalizator, detectNamespaces, expandStopNodes, 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 { Requirable, Strict } from "../../../common/types.cjs";
2
2
  import { AdminNs } from "../../../namespaces/admin/common/types.cjs";
3
3
  import { AppNs } from "../../../namespaces/app/common/types.cjs";
4
4
  import { ArxivNs } from "../../../namespaces/arxiv/common/types.cjs";
@@ -19,111 +19,124 @@ import { SyNs } from "../../../namespaces/sy/common/types.cjs";
19
19
  import { ThrNs } from "../../../namespaces/thr/common/types.cjs";
20
20
  import { TrackbackNs } from "../../../namespaces/trackback/common/types.cjs";
21
21
  import { WfwNs } from "../../../namespaces/wfw/common/types.cjs";
22
+ import { XmlNs } from "../../../namespaces/xml/common/types.cjs";
22
23
  import { YtNs } from "../../../namespaces/yt/common/types.cjs";
23
24
 
24
25
  //#region src/feeds/atom/common/types.d.ts
25
26
  declare namespace Atom {
26
- type Text = string;
27
- type Link<TDate extends DateLike> = {
28
- href: string;
27
+ type Text = {
28
+ value: string;
29
+ type?: string;
30
+ xml?: XmlNs.ItemOrFeed;
31
+ };
32
+ type Content = {
33
+ value?: string;
34
+ type?: string;
35
+ src?: string;
36
+ xml?: XmlNs.ItemOrFeed;
37
+ };
38
+ type Link<TDate, TStrict extends boolean = false> = Strict<{
39
+ href: Requirable<string>;
29
40
  rel?: string;
30
41
  type?: string;
31
42
  hreflang?: string;
32
43
  title?: string;
33
44
  length?: number;
34
45
  thr?: ThrNs.Link<TDate>;
35
- };
36
- type Person = {
37
- name: string;
46
+ }, TStrict>;
47
+ type Person<TStrict extends boolean = false> = Strict<{
48
+ name: Requirable<string>;
38
49
  uri?: string;
39
50
  email?: string;
40
51
  arxiv?: ArxivNs.Author;
41
- };
42
- type Category = {
43
- term: string;
52
+ }, TStrict>;
53
+ type Category<TStrict extends boolean = false> = Strict<{
54
+ term: Requirable<string>;
44
55
  scheme?: string;
45
56
  label?: string;
46
- };
47
- type Generator = {
48
- text: string;
57
+ }, TStrict>;
58
+ type Generator<TStrict extends boolean = false> = Strict<{
59
+ text: Requirable<string>;
49
60
  uri?: string;
50
61
  version?: string;
51
- };
52
- type Source<TDate extends DateLike> = {
53
- authors?: Array<Person>;
54
- categories?: Array<Category>;
55
- contributors?: Array<Person>;
56
- generator?: Generator;
62
+ }, TStrict>;
63
+ type Source<TDate, TStrict extends boolean = false> = {
64
+ authors?: Array<Person<TStrict>>;
65
+ categories?: Array<Category<TStrict>>;
66
+ contributors?: Array<Person<TStrict>>;
67
+ generator?: Generator<TStrict>;
57
68
  icon?: string;
58
69
  id?: string;
59
- links?: Array<Link<TDate>>;
70
+ links?: Array<Link<TDate, TStrict>>;
60
71
  logo?: string;
61
72
  rights?: Text;
62
73
  subtitle?: Text;
63
74
  title?: Text;
64
75
  updated?: TDate;
65
76
  };
66
- type Entry<TDate extends DateLike> = {
67
- authors?: Array<Person>;
68
- categories?: Array<Category>;
69
- content?: Text;
70
- contributors?: Array<Person>;
71
- id: string;
72
- links?: Array<Link<TDate>>;
77
+ type Entry<TDate, TStrict extends boolean = false> = Strict<{
78
+ authors?: Array<Person<TStrict>>;
79
+ categories?: Array<Category<TStrict>>;
80
+ content?: Content;
81
+ contributors?: Array<Person<TStrict>>;
82
+ id: Requirable<string>;
83
+ links?: Array<Link<TDate, TStrict>>;
73
84
  published?: TDate;
74
85
  rights?: Text;
75
- source?: Source<TDate>;
86
+ source?: Source<TDate, TStrict>;
76
87
  summary?: Text;
77
- title: Text;
78
- updated: TDate;
88
+ title: Requirable<Text>;
89
+ updated: Requirable<TDate>;
79
90
  app?: AppNs.Entry<TDate>;
80
91
  arxiv?: ArxivNs.Entry;
81
92
  cc?: CcNs.ItemOrFeed;
82
93
  dc?: DcNs.ItemOrFeed<TDate>;
83
94
  slash?: SlashNs.Item;
84
95
  itunes?: ItunesNs.Item;
85
- googleplay?: GooglePlayNs.Item;
86
- psc?: PscNs.Item;
87
- media?: MediaNs.ItemOrFeed;
88
- georss?: GeoRssNs.ItemOrFeed;
96
+ googleplay?: GooglePlayNs.Item<TStrict>;
97
+ psc?: PscNs.Item<TStrict>;
98
+ media?: MediaNs.ItemOrFeed<TStrict>;
99
+ georss?: GeoRssNs.ItemOrFeed<TStrict>;
89
100
  geo?: GeoNs.ItemOrFeed;
90
- thr?: ThrNs.Item;
101
+ thr?: ThrNs.Item<TStrict>;
91
102
  dcterms?: DcTermsNs.ItemOrFeed<TDate>;
92
103
  creativeCommons?: CreativeCommonsNs.ItemOrFeed;
93
104
  wfw?: WfwNs.Item;
94
105
  yt?: YtNs.Item;
95
106
  pingback?: PingbackNs.Item;
96
107
  trackback?: TrackbackNs.Item;
97
- };
98
- type Feed<TDate extends DateLike> = {
99
- authors?: Array<Person>;
100
- categories?: Array<Category>;
101
- contributors?: Array<Person>;
102
- generator?: Generator;
108
+ xml?: XmlNs.ItemOrFeed;
109
+ }, TStrict>;
110
+ type Feed<TDate, TStrict extends boolean = false> = Strict<{
111
+ authors?: Array<Person<TStrict>>;
112
+ categories?: Array<Category<TStrict>>;
113
+ contributors?: Array<Person<TStrict>>;
114
+ generator?: Generator<TStrict>;
103
115
  icon?: string;
104
- id: string;
105
- links?: Array<Link<TDate>>;
116
+ id: Requirable<string>;
117
+ links?: Array<Link<TDate, TStrict>>;
106
118
  logo?: string;
107
119
  rights?: Text;
108
120
  subtitle?: Text;
109
- title: Text;
110
- updated: TDate;
111
- entries?: Array<Entry<TDate>>;
121
+ title: Requirable<Text>;
122
+ updated: Requirable<TDate>;
123
+ entries?: Array<Entry<TDate, TStrict>>;
112
124
  cc?: CcNs.ItemOrFeed;
113
125
  dc?: DcNs.ItemOrFeed<TDate>;
114
126
  sy?: SyNs.Feed<TDate>;
115
- itunes?: ItunesNs.Feed;
116
- googleplay?: GooglePlayNs.Feed;
117
- media?: MediaNs.ItemOrFeed;
118
- georss?: GeoRssNs.ItemOrFeed;
127
+ itunes?: ItunesNs.Feed<TStrict>;
128
+ googleplay?: GooglePlayNs.Feed<TStrict>;
129
+ media?: MediaNs.ItemOrFeed<TStrict>;
130
+ georss?: GeoRssNs.ItemOrFeed<TStrict>;
119
131
  geo?: GeoNs.ItemOrFeed;
120
132
  dcterms?: DcTermsNs.ItemOrFeed<TDate>;
121
133
  creativeCommons?: CreativeCommonsNs.ItemOrFeed;
122
- opensearch?: OpenSearchNs.Feed;
134
+ opensearch?: OpenSearchNs.Feed<TStrict>;
123
135
  yt?: YtNs.Feed;
124
136
  admin?: AdminNs.Feed;
125
137
  pingback?: PingbackNs.Feed;
126
- };
138
+ xml?: XmlNs.ItemOrFeed;
139
+ }, TStrict>;
127
140
  }
128
141
  //#endregion
129
142
  export { Atom };