@dereekb/util 13.0.7 → 13.2.0

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 (143) hide show
  1. package/fetch/package.json +2 -2
  2. package/index.cjs.js +4107 -1516
  3. package/index.esm.js +4107 -1516
  4. package/package.json +1 -2
  5. package/src/lib/array/array.d.ts +92 -47
  6. package/src/lib/array/array.find.d.ts +14 -18
  7. package/src/lib/array/array.index.d.ts +43 -14
  8. package/src/lib/array/array.indexed.d.ts +66 -17
  9. package/src/lib/array/array.limit.d.ts +11 -0
  10. package/src/lib/array/array.make.d.ts +9 -3
  11. package/src/lib/array/array.map.d.ts +20 -8
  12. package/src/lib/array/array.number.d.ts +63 -5
  13. package/src/lib/array/array.random.d.ts +12 -9
  14. package/src/lib/array/array.set.d.ts +24 -1
  15. package/src/lib/array/array.string.d.ts +104 -0
  16. package/src/lib/array/array.unique.d.ts +60 -8
  17. package/src/lib/array/array.value.d.ts +20 -11
  18. package/src/lib/assertion/assertion.d.ts +30 -2
  19. package/src/lib/assertion/assertion.generic.d.ts +8 -0
  20. package/src/lib/assertion/assertion.number.d.ts +16 -0
  21. package/src/lib/auth/auth.role.claims.d.ts +14 -8
  22. package/src/lib/boolean.d.ts +54 -1
  23. package/src/lib/contact/domain.d.ts +22 -4
  24. package/src/lib/contact/random.d.ts +24 -0
  25. package/src/lib/date/date.d.ts +8 -13
  26. package/src/lib/date/hour.d.ts +51 -32
  27. package/src/lib/date/minute.d.ts +4 -4
  28. package/src/lib/date/time.d.ts +12 -3
  29. package/src/lib/date/week.d.ts +77 -10
  30. package/src/lib/error/error.d.ts +54 -3
  31. package/src/lib/error/error.server.d.ts +25 -2
  32. package/src/lib/filter/filter.d.ts +12 -7
  33. package/src/lib/function/function.boolean.d.ts +4 -4
  34. package/src/lib/function/function.d.ts +2 -5
  35. package/src/lib/function/function.forward.d.ts +19 -3
  36. package/src/lib/getter/getter.cache.d.ts +9 -5
  37. package/src/lib/getter/getter.d.ts +39 -22
  38. package/src/lib/getter/getter.map.d.ts +10 -4
  39. package/src/lib/getter/getter.util.d.ts +3 -3
  40. package/src/lib/grouping.d.ts +98 -31
  41. package/src/lib/hash.d.ts +15 -8
  42. package/src/lib/iterable/iterable.d.ts +62 -50
  43. package/src/lib/iterable/iterable.map.d.ts +4 -4
  44. package/src/lib/iterate.d.ts +17 -1
  45. package/src/lib/key.d.ts +32 -10
  46. package/src/lib/lifecycle.d.ts +10 -1
  47. package/src/lib/map/map.d.ts +17 -16
  48. package/src/lib/map/map.intersection.d.ts +5 -4
  49. package/src/lib/map/map.key.d.ts +16 -15
  50. package/src/lib/misc/host.d.ts +6 -3
  51. package/src/lib/model/id.batch.d.ts +7 -3
  52. package/src/lib/model/id.factory.d.ts +16 -1
  53. package/src/lib/model/model.conversion.d.ts +49 -6
  54. package/src/lib/model/model.conversion.field.d.ts +13 -3
  55. package/src/lib/model/model.copy.d.ts +11 -0
  56. package/src/lib/model/model.d.ts +174 -1
  57. package/src/lib/model/model.modify.d.ts +24 -5
  58. package/src/lib/nodejs/stream.d.ts +8 -6
  59. package/src/lib/number/bitwise.dencoder.d.ts +43 -3
  60. package/src/lib/number/bound.d.ts +34 -5
  61. package/src/lib/number/dollar.d.ts +13 -6
  62. package/src/lib/number/factory.d.ts +11 -3
  63. package/src/lib/number/number.d.ts +55 -32
  64. package/src/lib/number/random.d.ts +13 -3
  65. package/src/lib/number/round.d.ts +47 -26
  66. package/src/lib/number/sort.d.ts +7 -1
  67. package/src/lib/number/transform.d.ts +16 -0
  68. package/src/lib/object/object.array.d.ts +16 -2
  69. package/src/lib/object/object.array.delta.d.ts +6 -2
  70. package/src/lib/object/object.d.ts +33 -5
  71. package/src/lib/object/object.empty.d.ts +4 -2
  72. package/src/lib/object/object.equal.d.ts +21 -4
  73. package/src/lib/object/object.filter.tuple.d.ts +105 -3
  74. package/src/lib/object/object.key.d.ts +13 -6
  75. package/src/lib/object/object.map.d.ts +30 -19
  76. package/src/lib/page/page.d.ts +21 -0
  77. package/src/lib/page/page.filter.d.ts +16 -9
  78. package/src/lib/path/path.d.ts +101 -14
  79. package/src/lib/path/path.tree.d.ts +16 -0
  80. package/src/lib/promise/callback.d.ts +18 -0
  81. package/src/lib/promise/is.d.ts +10 -3
  82. package/src/lib/promise/map.d.ts +5 -3
  83. package/src/lib/promise/poll.d.ts +14 -4
  84. package/src/lib/promise/promise.d.ts +84 -18
  85. package/src/lib/promise/promise.factory.d.ts +18 -2
  86. package/src/lib/promise/promise.limit.d.ts +22 -2
  87. package/src/lib/promise/promise.loop.d.ts +69 -1
  88. package/src/lib/promise/promise.ref.d.ts +14 -2
  89. package/src/lib/promise/promise.task.d.ts +8 -4
  90. package/src/lib/promise/promise.type.d.ts +4 -4
  91. package/src/lib/promise/use.d.ts +6 -4
  92. package/src/lib/promise/wait.d.ts +5 -2
  93. package/src/lib/relation/relation.d.ts +98 -0
  94. package/src/lib/service/handler.config.d.ts +47 -9
  95. package/src/lib/service/handler.d.ts +43 -1
  96. package/src/lib/service/typed.service.d.ts +21 -2
  97. package/src/lib/set/set.allowed.d.ts +6 -4
  98. package/src/lib/set/set.d.ts +174 -46
  99. package/src/lib/set/set.decision.d.ts +4 -2
  100. package/src/lib/set/set.delta.d.ts +16 -3
  101. package/src/lib/set/set.hashset.d.ts +43 -0
  102. package/src/lib/set/set.selection.d.ts +7 -3
  103. package/src/lib/sort.d.ts +36 -16
  104. package/src/lib/string/char.d.ts +48 -34
  105. package/src/lib/string/dencoder.d.ts +84 -13
  106. package/src/lib/string/factory.d.ts +13 -4
  107. package/src/lib/string/html.d.ts +7 -6
  108. package/src/lib/string/mimetype.d.ts +65 -1
  109. package/src/lib/string/prefix.d.ts +21 -7
  110. package/src/lib/string/record.d.ts +7 -4
  111. package/src/lib/string/replace.d.ts +77 -33
  112. package/src/lib/string/search.d.ts +19 -9
  113. package/src/lib/string/sort.d.ts +10 -1
  114. package/src/lib/string/string.d.ts +74 -21
  115. package/src/lib/string/transform.d.ts +7 -0
  116. package/src/lib/string/tree.d.ts +91 -29
  117. package/src/lib/string/url.d.ts +148 -63
  118. package/src/lib/tree/tree.explore.d.ts +84 -17
  119. package/src/lib/tree/tree.flatten.d.ts +44 -7
  120. package/src/lib/type.d.ts +15 -12
  121. package/src/lib/value/address.d.ts +66 -17
  122. package/src/lib/value/bound.d.ts +253 -17
  123. package/src/lib/value/build.d.ts +30 -5
  124. package/src/lib/value/comparator.d.ts +53 -25
  125. package/src/lib/value/cron.d.ts +14 -6
  126. package/src/lib/value/decision.d.ts +57 -13
  127. package/src/lib/value/equal.d.ts +44 -13
  128. package/src/lib/value/indexed.d.ts +253 -82
  129. package/src/lib/value/label.d.ts +16 -5
  130. package/src/lib/value/map.d.ts +77 -20
  131. package/src/lib/value/maybe.d.ts +47 -49
  132. package/src/lib/value/modifier.d.ts +82 -27
  133. package/src/lib/value/point.d.ts +248 -54
  134. package/src/lib/value/url.d.ts +10 -3
  135. package/src/lib/value/use.d.ts +99 -8
  136. package/src/lib/value/vector.d.ts +71 -9
  137. package/test/index.cjs.js +86 -23
  138. package/test/index.esm.js +86 -23
  139. package/test/package.json +2 -2
  140. package/test/src/lib/shared/shared.d.ts +31 -5
  141. package/test/src/lib/shared/shared.fail.d.ts +72 -9
  142. package/test/src/lib/shared/shared.function.d.ts +40 -2
  143. package/test/src/lib/shared/shared.wrap.d.ts +20 -1
@@ -10,13 +10,17 @@ import { type Maybe } from '../value/maybe.type';
10
10
  * I.E. http, https, etc.
11
11
  */
12
12
  export type WebsiteProtocol = string;
13
+ /** The HTTP protocol string literal type. */
13
14
  export type HttpWebsiteProtocol = 'http';
15
+ /** The HTTPS protocol string literal type. */
14
16
  export type HttpsWebsiteProtocol = 'https';
17
+ /** Known HTTP protocols: `"http"` or `"https"`. */
15
18
  export type KnownHttpWebsiteProtocol = HttpWebsiteProtocol | HttpsWebsiteProtocol;
16
19
  /**
17
- * Returns true if the input string is a KnownHttpWebsiteProtocol.
20
+ * Returns true if the input string is a known HTTP protocol (`"http"` or `"https"`).
18
21
  *
19
- * @param input
22
+ * @param input - The protocol string to check.
23
+ * @returns Whether the input is `"http"` or `"https"`.
20
24
  */
21
25
  export declare function isKnownHttpWebsiteProtocol(input: string): input is KnownHttpWebsiteProtocol;
22
26
  /**
@@ -32,7 +36,7 @@ export type WebsiteDomain = string;
32
36
  */
33
37
  export declare const HAS_WEBSITE_DOMAIN_NAME_REGEX: RegExp;
34
38
  /**
35
- * Returns true if the input probably has a website domain in it.
39
+ * Returns true if the input probably contains a website domain (has at least one period separating parts).
36
40
  *
37
41
  * Examples where it will return true:
38
42
  * - dereekb.com
@@ -41,8 +45,8 @@ export declare const HAS_WEBSITE_DOMAIN_NAME_REGEX: RegExp;
41
45
  * - https://components.dereekb.com/
42
46
  * - https://components.dereekb.com/doc/home
43
47
  *
44
- * @param input
45
- * @returns
48
+ * @param input - The string to check for a domain.
49
+ * @returns Whether the input appears to contain a website domain.
46
50
  */
47
51
  export declare function hasWebsiteDomain(input: string): input is WebsiteDomain;
48
52
  /**
@@ -62,10 +66,13 @@ export declare const WEBSITE_TLD_DETECTION_REGEX: RegExp;
62
66
  * Returns true if the input url has a website top level domain.
63
67
  *
64
68
  * It does not check whether or not the tld is a recognized tld.
69
+ *
70
+ * @param input - The URL string to check.
71
+ * @returns Whether the input appears to have a top-level domain.
65
72
  */
66
73
  export declare function hasWebsiteTopLevelDomain(input: string): boolean;
67
74
  /**
68
- * Simple website domain regex that looks for a period in the string between the domain and the tld
75
+ * Regex that matches a colon followed by digits, used to detect port numbers in URLs.
69
76
  */
70
77
  export declare const HAS_PORT_NUMBER_REGEX: RegExp;
71
78
  /**
@@ -77,7 +84,7 @@ export declare const HAS_PORT_NUMBER_REGEX: RegExp;
77
84
  */
78
85
  export type PortNumber = number;
79
86
  /**
80
- * Returns true if the input has a port number attached to it
87
+ * Returns true if the input string contains a port number (e.g., `:8080`).
81
88
  *
82
89
  * Examples where it will return true:
83
90
  * - localhost:8080
@@ -86,14 +93,15 @@ export type PortNumber = number;
86
93
  * - https://components.dereekb.com:8080/
87
94
  * - https://components.dereekb.com:8080/doc/home
88
95
  *
89
- * @param input
90
- * @returns
96
+ * @param input - The string to check for a port number.
97
+ * @returns Whether the input contains a port number.
91
98
  */
92
99
  export declare function hasPortNumber(input: string): boolean;
93
100
  /**
94
- * Reads the port number from the input, if possible.
101
+ * Extracts the port number from the input string, if one is present.
95
102
  *
96
- * @param input
103
+ * @param input - The string to extract a port number from.
104
+ * @returns The port number, or `undefined` if none is found.
97
105
  */
98
106
  export declare function readPortNumber(input: string): Maybe<PortNumber>;
99
107
  /**
@@ -107,10 +115,12 @@ export type BaseWebsiteUrl<D extends WebsiteDomain = WebsiteDomain> = `http://${
107
115
  */
108
116
  export type BaseWebsiteUrlInput = string | WebsiteUrl | WebsiteDomain;
109
117
  /**
110
- * Creates a base website url from the input domain or url.
118
+ * Creates a base website URL (with `http://` or `https://` prefix) from the input domain or URL.
119
+ * If the input lacks a TLD and port, the default TLD is appended.
111
120
  *
112
- * @param input
113
- * @returns
121
+ * @param input - A domain, URL, or partial URL string.
122
+ * @param defaultTld - The TLD to append if none is detected. Defaults to `"com"`.
123
+ * @returns A fully-qualified base website URL.
114
124
  */
115
125
  export declare function baseWebsiteUrl(input: BaseWebsiteUrlInput, defaultTld?: string): BaseWebsiteUrl;
116
126
  /**
@@ -125,32 +135,42 @@ export declare function baseWebsiteUrl(input: BaseWebsiteUrlInput, defaultTld?:
125
135
  */
126
136
  export type WebsiteUrl = string;
127
137
  /**
128
- * Returns true if the input string is probably a website url.
138
+ * Returns true if the input string is probably a website URL.
139
+ *
140
+ * Checks that it has a domain and the path is a valid slash path. Query parameters are ignored.
129
141
  *
130
- * Checks that it has the http/https prefix, has a domain, and the path is a slash path. The query parameters are ignored.
142
+ * @param input - The string to check.
143
+ * @returns Whether the input appears to be a valid website URL.
131
144
  */
132
145
  export declare function isWebsiteUrl(input: string): input is WebsiteUrl;
133
146
  /**
134
- * Details about an input string.
135
- *
136
- * Is tested if it is a website url.
147
+ * Detailed analysis of whether an input string is a valid website URL, including its parsed components.
137
148
  */
138
149
  export interface WebsiteUrlDetails {
150
+ /** The original input string. */
139
151
  readonly input: string;
152
+ /** Whether the input is a valid website URL. */
140
153
  readonly isWebsiteUrl: boolean;
154
+ /** Whether the input has an `http://` or `https://` prefix. */
141
155
  readonly hasHttpPrefix: boolean;
156
+ /** Whether the input contains a website domain. */
142
157
  readonly hasWebsiteDomain: boolean;
158
+ /** The domain and path split pair. */
143
159
  readonly splitPair: WebsiteDomainAndPathPair;
160
+ /** The extracted domain. */
144
161
  readonly domain: WebsiteDomain;
162
+ /** The full website path including query string. */
145
163
  readonly websitePath: WebsitePath;
164
+ /** The path portion without query parameters. */
146
165
  readonly path: string;
166
+ /** The query string portion, or undefined if none. */
147
167
  readonly query: string | undefined;
148
168
  }
149
169
  /**
150
- * Returns details about the input string, considering it a WebsiteUrl and returning details.
170
+ * Parses the input string as a website URL and returns detailed information about its components.
151
171
  *
152
- * @param input string to test
153
- * @returns WebsiteUrlDetails
172
+ * @param input - The string to analyze as a URL.
173
+ * @returns An object containing parsed URL components and validation flags.
154
174
  */
155
175
  export declare function websiteUrlDetails(input: string): WebsiteUrlDetails;
156
176
  /**
@@ -158,9 +178,10 @@ export declare function websiteUrlDetails(input: string): WebsiteUrlDetails;
158
178
  */
159
179
  export type WebsiteUrlWithPrefix = string;
160
180
  /**
161
- * Returns true if the input string is probably a website url.
181
+ * Returns true if the input string is probably a website URL and has an `http://` or `https://` prefix.
162
182
  *
163
- * Checks that it has the http/https prefix, has a domain, and the path is a slash path. The query parameters are ignored.
183
+ * @param input - The string to check.
184
+ * @returns Whether the input is a website URL with an HTTP prefix.
164
185
  */
165
186
  export declare function isWebsiteUrlWithPrefix(input: string): input is WebsiteUrl;
166
187
  /**
@@ -181,9 +202,10 @@ export declare function isWebsiteUrlWithPrefix(input: string): input is WebsiteU
181
202
  */
182
203
  export type StandardInternetAccessibleWebsiteUrl = string;
183
204
  /**
184
- * Returns true if the input is a StandardInternetAccessibleWebsiteUrl.
205
+ * Returns true if the input is a standard internet-accessible website URL with a recognized TLD and optionally an HTTP/HTTPS protocol.
185
206
  *
186
- * @param input
207
+ * @param input - The string to check.
208
+ * @returns Whether the input is a standard internet-accessible website URL.
187
209
  */
188
210
  export declare function isStandardInternetAccessibleWebsiteUrl(input: string): input is StandardInternetAccessibleWebsiteUrl;
189
211
  /**
@@ -205,10 +227,12 @@ export type WebsiteDomainAndPath = string;
205
227
  */
206
228
  export type WebsitePath = `/${string}`;
207
229
  /**
208
- * Creates a WebsiteUrl from the input
209
- * @param basePath
210
- * @param paths
211
- * @returns
230
+ * Creates a {@link WebsiteUrl} by merging the base path with additional path segments, preserving the original protocol.
231
+ *
232
+ * @param basePath - The base URL or domain to build upon.
233
+ * @param paths - One or more path segments to append.
234
+ * @param defaultProtocol - Optional protocol to use if the base path has none.
235
+ * @returns The constructed website URL.
212
236
  */
213
237
  export declare function websiteUrlFromPaths(basePath: BaseWebsiteUrlInput, paths: ArrayOrValue<Maybe<WebsitePath>>, defaultProtocol?: WebsiteProtocol): WebsiteUrl;
214
238
  /**
@@ -216,9 +240,12 @@ export declare function websiteUrlFromPaths(basePath: BaseWebsiteUrlInput, paths
216
240
  */
217
241
  export type WebsiteQueryString = `?${string}`;
218
242
  /**
219
- * Maps the input WebsitePath to remove the configured base path.
243
+ * Function that extracts and isolates a specific path portion from a website URL, domain-and-path, or path string.
220
244
  */
221
245
  export type IsolateWebsitePathFunction = MapFunction<WebsitePath | WebsiteDomainAndPath | WebsiteUrl, WebsitePath>;
246
+ /**
247
+ * Configuration for creating an {@link IsolateWebsitePathFunction}.
248
+ */
222
249
  export interface IsolateWebsitePathFunctionConfig {
223
250
  /**
224
251
  * Optional range of paths to isolate.
@@ -245,99 +272,157 @@ export interface IsolateWebsitePathFunctionConfig {
245
272
  readonly removeTrailingSlash?: boolean;
246
273
  }
247
274
  /**
248
- * Creates a new ExcludeBaseWebsitePathFunction that excludes the base path from the input website path if it exists.
275
+ * Creates an {@link IsolateWebsitePathFunction} that extracts and transforms a path from a website URL based on the configuration.
249
276
  *
250
- * @param basePath
277
+ * @param config - Configuration for path isolation, including base path removal, component range, query handling, and trailing slash behavior.
278
+ * @returns A function that isolates the configured portion of a website path.
251
279
  */
252
280
  export declare function isolateWebsitePathFunction(config?: IsolateWebsitePathFunctionConfig): IsolateWebsitePathFunction;
281
+ /**
282
+ * A pair containing the path and optional query string components of a website URL.
283
+ */
253
284
  export interface WebsitePathAndQueryPair {
285
+ /** The path portion of the URL (before the `?`). */
254
286
  path: WebsitePath;
287
+ /** The query string portion of the URL (including the leading `?`), if present. */
255
288
  query?: Maybe<WebsiteQueryString>;
256
289
  }
290
+ /**
291
+ * Splits a website path string into its path and query string components.
292
+ *
293
+ * @param inputPath - The path string to split.
294
+ * @returns A pair containing the path and optional query string.
295
+ */
257
296
  export declare function websitePathAndQueryPair(inputPath: string | WebsitePath): WebsitePathAndQueryPair;
258
297
  /**
259
- * Replaces any extra query parameter "?" characters with an "&" character.
298
+ * Replaces extra `?` characters in a query string with `&` to fix malformed query parameters.
260
299
  *
261
- * Can also choose to replace all instead, incase the input string should be considered the query without.
300
+ * By default, preserves the first `?` and replaces subsequent ones. If `replaceAll` is true, all `?` characters are replaced.
262
301
  *
263
- * @param input
302
+ * @param input - The query string to fix.
303
+ * @param replaceAll - If true, replaces all `?` characters (useful when the input is already past the initial `?`).
304
+ * @returns The fixed query string.
264
305
  */
265
306
  export declare function fixExtraQueryParameters(input: string, replaceAll?: boolean): string;
266
307
  /**
267
- * Reads the website path from the input.
308
+ * Extracts the path component from a website URL, stripping the protocol and domain.
268
309
  *
269
- * @param input
270
- * @returns
310
+ * @param inputUrl - The URL to extract the path from.
311
+ * @returns The website path component.
271
312
  */
272
313
  export declare function websitePathFromWebsiteUrl(inputUrl: WebsiteUrl | WebsiteDomainAndPath): WebsitePath;
314
+ /**
315
+ * Splits a website URL into its domain and path components after removing the protocol prefix.
316
+ *
317
+ * @param inputUrl - The URL to split.
318
+ * @returns A pair containing the domain and path.
319
+ */
273
320
  export declare function websiteDomainAndPathPairFromWebsiteUrl(inputUrl: WebsiteUrl | WebsiteDomainAndPath): WebsiteDomainAndPathPair;
274
321
  /**
275
- * Reads the website path from the input WebsiteDomainAndPath.
322
+ * Extracts the path component from a domain-and-path string.
276
323
  *
277
- * @param input
278
- * @returns
324
+ * @param input - The domain-and-path string to extract the path from.
325
+ * @returns The website path component.
279
326
  */
280
327
  export declare function websitePathFromWebsiteDomainAndPath(input: WebsiteDomainAndPath): WebsitePath;
328
+ /**
329
+ * A pair containing the domain and path components of a website URL.
330
+ */
281
331
  export interface WebsiteDomainAndPathPair {
332
+ /** The domain portion of the URL. */
282
333
  domain: WebsiteDomain;
334
+ /** The path portion of the URL. */
283
335
  path: WebsitePath;
284
336
  }
337
+ /**
338
+ * Splits a domain-and-path string into its domain and path components at the first slash.
339
+ *
340
+ * @param input - The domain-and-path string to split.
341
+ * @returns A pair containing the domain and path.
342
+ */
285
343
  export declare function websiteDomainAndPathPair(input: WebsiteDomainAndPath): WebsiteDomainAndPathPair;
344
+ /**
345
+ * Regex that matches `http://` or `https://` at the start of a string.
346
+ */
286
347
  export declare const HTTP_OR_HTTPS_REGEX: RegExp;
348
+ /**
349
+ * Regex that captures any protocol prefix (e.g., `http`, `https`, `ftp`) before `://`.
350
+ */
287
351
  export declare const WEB_PROTOCOL_PREFIX_REGEX: RegExp;
288
352
  /**
289
353
  * Reads the website protocol from the input string, if it exists.
354
+ * Does not include the `://` separator.
290
355
  *
291
- * Does not include the "://" components.
292
- *
293
- * @param input
356
+ * @param input - The URL string to extract the protocol from.
357
+ * @returns The protocol string (e.g., `"https"`), or `undefined` if no protocol is present.
294
358
  */
295
359
  export declare function readWebsiteProtocol(input: string): Maybe<WebsiteProtocol>;
296
360
  /**
297
- * Removes any existing protocol and sets the protocol to match the input.
361
+ * Replaces the existing protocol prefix with the specified one, or removes it if no protocol is provided.
298
362
  *
299
- * If no protcol is input, then it is removed from the input.
300
- *
301
- * @param url
302
- * @param protocol
363
+ * @param input - The URL string to modify.
364
+ * @param protocol - The protocol to set (e.g., `"https"`), or `undefined`/`null` to remove the protocol.
365
+ * @returns The URL with the updated protocol prefix.
303
366
  */
304
367
  export declare function setWebProtocolPrefix(input: string, protocol?: Maybe<WebsiteProtocol>): string;
305
368
  /**
306
- * Removes any existing protocol prefix from the input.
369
+ * Removes any protocol prefix (e.g., `http://`, `https://`, `ftp://`) from the input string.
307
370
  *
308
- * @param input
371
+ * @param input - The URL string to strip the protocol from.
372
+ * @returns The URL without the protocol prefix.
309
373
  */
310
374
  export declare function removeWebProtocolPrefix(input: string): string;
311
375
  /**
312
- * Adds both https:// to the url.
376
+ * Adds an HTTP or HTTPS protocol prefix to the URL, replacing any existing protocol.
313
377
  *
314
- * @param url
315
- * @returns
378
+ * @param url - The URL or domain string to add the prefix to.
379
+ * @param prefix - The HTTP protocol to use. Defaults to `"https"`.
380
+ * @returns The URL with the specified HTTP protocol prefix.
316
381
  */
317
382
  export declare function addHttpToUrl(url: BaseWebsiteUrl | WebsiteDomainAndPath | string, prefix?: KnownHttpWebsiteProtocol): BaseWebsiteUrl;
318
383
  /**
319
- * Removes the prefixes http:// and https:// from the url. If these protocols are not used, nothing is removed.
384
+ * Removes `http://` or `https://` from the URL. Other protocols are not affected.
320
385
  *
321
- * @param url
322
- * @returns
386
+ * @param url - The URL to strip the HTTP prefix from.
387
+ * @returns The URL without the HTTP/HTTPS prefix.
323
388
  */
324
389
  export declare function removeHttpFromUrl(url: BaseWebsiteUrl | string): WebsiteDomainAndPath;
325
390
  /**
326
- * Returns true if the input string starts with http/https
391
+ * Returns true if the input string starts with `http://` or `https://`.
327
392
  *
328
- * @param input
393
+ * @param input - The string to check.
394
+ * @returns Whether the input has an HTTP/HTTPS prefix.
329
395
  */
330
396
  export declare function hasHttpPrefix(input: string): input is BaseWebsiteUrl;
397
+ /**
398
+ * Object representation of a `mailto:` URL.
399
+ */
331
400
  export interface MailToUrl {
401
+ /** The email address for the mailto link. */
332
402
  email: string;
333
403
  }
404
+ /**
405
+ * Input for creating a mailto URL string. Can be an email address string or a {@link MailToUrl} object.
406
+ */
334
407
  export type MailToUrlInput = EmailAddress | MailToUrl;
408
+ /**
409
+ * Creates a `mailto:` URL string from the input email address or object.
410
+ *
411
+ * @param input - An email address or MailToUrl object.
412
+ * @returns A `mailto:` URL string.
413
+ */
335
414
  export declare function mailToUrlString(input: MailToUrlInput): string;
415
+ /**
416
+ * Creates a `tel:` URL string from a phone number, handling E.164 format and extensions.
417
+ *
418
+ * @param phone - The phone number to create a tel URL for.
419
+ * @returns A `tel:` URL string, with extension appended if present.
420
+ */
336
421
  export declare function telUrlString(phone: PhoneNumber | E164PhoneNumberWithOptionalExtension): string;
337
422
  /**
338
- * Creates a tel url string for the input E164PhoneNumberExtensionPair.
423
+ * Creates a `tel:` URL string for an E.164 phone number with an optional extension.
339
424
  *
340
- * @param pair
341
- * @returns
425
+ * @param pair - The phone number and extension pair.
426
+ * @returns A `tel:` URL string with the extension appended using `;` if present.
342
427
  */
343
428
  export declare function telUrlStringForE164PhoneNumberPair(pair: E164PhoneNumberExtensionPair): string;
@@ -24,56 +24,123 @@ export declare const ExploreTreeVisitNodeDecision: {
24
24
  };
25
25
  export type ExploreTreeVisitNodeDecision = (typeof ExploreTreeVisitNodeDecision)[keyof typeof ExploreTreeVisitNodeDecision];
26
26
  /**
27
- * A function that determines if a node should be visited.
27
+ * Function that determines how a node should be handled during tree exploration.
28
28
  *
29
- * The mapped value is also present.
29
+ * Receives both the original node and its mapped value, allowing filtering decisions
30
+ * based on either the raw tree structure or a transformed representation.
31
+ *
32
+ * @template N - The tree node type.
33
+ * @template V - The mapped value type, defaults to N if no mapping is applied.
30
34
  */
31
35
  export type ExploreTreeVisitNodeDecisionFunction<N extends TreeNode<unknown>, V = N> = (node: N, nodeMappedValue: V) => ExploreTreeVisitNodeDecision;
32
36
  /**
33
- * A function that visits a node.
37
+ * Callback invoked when a node is visited during tree exploration.
38
+ *
39
+ * Receives the mapped value (or the node itself if no mapping) and the original node,
40
+ * allowing side effects such as accumulating results or modifying external state.
41
+ *
42
+ * @template N - The tree node type.
43
+ * @template V - The mapped value type passed to the callback.
34
44
  */
35
45
  export type ExploreTreeVisitNodeFunction<N extends TreeNode<unknown>, V> = (value: V, node: N) => void;
36
46
  /**
37
- * Creates a traversal function that can be used to visit nodes.
47
+ * Factory that creates a traversal strategy for tree exploration.
48
+ *
49
+ * Controls the order in which nodes are visited (e.g., depth-first vs breadth-first).
50
+ * Receives the visit callback and a recursive traversal function, and returns a function
51
+ * that handles a single node based on its visit decision.
52
+ *
53
+ * @template N - The tree node type.
54
+ * @template V - The mapped value type.
38
55
  */
39
56
  export type ExploreTreeTraversalFactoryFunction<N extends TreeNode<unknown>, V> = (visit: ExploreTreeVisitNodeFunction<N, V>, traverseTree: (tree: N) => void) => (node: N, nodeMappedValue: V, visitDecision: ExploreTreeVisitNodeDecision) => void;
57
+ /**
58
+ * Configuration for creating an {@link ExploreTreeFunction}.
59
+ *
60
+ * Allows customizing node mapping, visit filtering, and traversal order.
61
+ * All options can also be overridden at call time.
62
+ *
63
+ * @template N - The tree node type.
64
+ * @template V - The mapped value type, defaults to N.
65
+ */
40
66
  export interface ExploreTreeFunctionConfig<N extends TreeNode<unknown>, V = N> {
41
67
  /**
42
- * A custom traversal function to use instead of the default traversal function.
68
+ * Custom traversal strategy (e.g., breadth-first). Defaults to depth-first.
43
69
  */
44
70
  traverseFunctionFactory?: ExploreTreeTraversalFactoryFunction<N, V>;
45
71
  /**
46
- * A function that maps a node to a specific value before visiting it.
72
+ * Transforms each node into a value before visiting. Defaults to identity.
47
73
  */
48
74
  mapNodeFunction?: (node: N) => V;
49
75
  /**
50
- * A function that determines if a node should be visited.
76
+ * Controls whether each node is visited, skipped, or has only its children visited.
77
+ * Defaults to visiting all nodes.
51
78
  */
52
79
  shouldVisitNodeFunction?: Maybe<ExploreTreeVisitNodeDecisionFunction<N, V>>;
53
80
  }
54
81
  /**
55
- * Explores the input trees.
82
+ * Traverses one or more trees, invoking a visit callback on each node.
83
+ *
84
+ * Supports runtime overrides of mapping, filtering, and traversal strategy.
85
+ *
86
+ * @template N - The tree node type.
87
+ * @template V - The mapped value type passed to the visit callback.
56
88
  */
57
89
  export type ExploreTreeFunction<N extends TreeNode<unknown, N>, V> = (trees: ArrayOrValue<N>, visit: ExploreTreeVisitNodeFunction<N, V>, override?: ExploreTreeFunctionConfig<N, V>) => void;
58
90
  /**
59
- * Convenience function for exploring the input trees
60
-
61
- * @param trees
62
- * @param visitNodeFn
63
- * @returns
91
+ * Creates a reusable tree exploration function with configurable traversal, mapping, and filtering.
92
+ *
93
+ * The returned function traverses one or more trees, applying a visit callback to each node.
94
+ * By default uses depth-first traversal, identity mapping, and visits all nodes. All options
95
+ * can be overridden per-call.
96
+ *
97
+ * @param config - Optional default configuration for mapping, filtering, and traversal strategy.
98
+ * @returns A reusable function that explores trees with the configured behavior.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const exploreFn = exploreTreeFunction<TestNode, string>({
103
+ * mapNodeFunction: (node) => node.value.id
104
+ * });
105
+ * const visited: string[] = [];
106
+ *
107
+ * exploreFn(rootNode, (id) => {
108
+ * visited.push(id);
109
+ * });
110
+ * ```
64
111
  */
65
112
  export declare function exploreTreeFunction<N extends TreeNode<unknown, N>, V>(config?: Maybe<ExploreTreeFunctionConfig<N, V>>): ExploreTreeFunction<N, V>;
66
113
  /**
67
- * A depth-first traversal factory function.
114
+ * Creates a depth-first traversal strategy for tree exploration.
115
+ *
116
+ * Visits each node before its children (pre-order). This is the default traversal
117
+ * strategy used by {@link exploreTreeFunction}.
68
118
  *
69
- * @returns A ExploreTreeTraversalFactoryFunction<N, V>.
119
+ * @returns A traversal factory that processes nodes in depth-first order.
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const exploreFn = exploreTreeFunction<TestNode, TestNode>({
124
+ * traverseFunctionFactory: depthFirstExploreTreeTraversalFactoryFunction()
125
+ * });
126
+ * // Visits: root -> child1 -> leaf1 -> leaf2 -> child2 -> leaf3
127
+ * ```
70
128
  */
71
129
  export declare function depthFirstExploreTreeTraversalFactoryFunction<N extends TreeNode<unknown, N>, V>(): ExploreTreeTraversalFactoryFunction<N, V>;
72
130
  /**
73
- * A breadth-first traversal factory function.
131
+ * Creates a breadth-first traversal strategy for tree exploration.
74
132
  *
75
133
  * Visits nodes level by level, processing all nodes at depth N before moving to depth N+1.
134
+ * Uses an internal queue to defer child processing until the current level is complete.
135
+ *
136
+ * @returns A traversal factory that processes nodes in breadth-first order.
76
137
  *
77
- * @returns A ExploreTreeTraversalFactoryFunction<N, V>.
138
+ * @example
139
+ * ```typescript
140
+ * const exploreFn = exploreTreeFunction<TestNode, TestNode>({
141
+ * traverseFunctionFactory: breadthFirstExploreTreeTraversalFactoryFunction()
142
+ * });
143
+ * // Visits: root -> child1, child2, child3 -> leaf1, leaf2, leaf3
144
+ * ```
78
145
  */
79
146
  export declare function breadthFirstExploreTreeTraversalFactoryFunction<N extends TreeNode<unknown, N>, V>(): ExploreTreeTraversalFactoryFunction<N, V>;
@@ -36,24 +36,61 @@ export declare const FlattenTreeAddNodeDecision: {
36
36
  };
37
37
  export type FlattenTreeAddNodeDecision = ExploreTreeVisitNodeDecision;
38
38
  /**
39
- * A function that determines if a node should be visited.
39
+ * Function that determines whether a node should be included in the flattened output.
40
40
  *
41
- * The mapped value is also present.
41
+ * Alias for {@link ExploreTreeVisitNodeDecisionFunction} in the context of tree flattening.
42
+ * Receives both the original node and its mapped value for filtering decisions.
43
+ *
44
+ * @template N - The tree node type.
45
+ * @template V - The mapped value type, defaults to N.
42
46
  */
43
47
  export type FlattenTreeAddNodeDecisionFunction<N extends TreeNode<unknown>, V = N> = ExploreTreeVisitNodeDecisionFunction<N, V>;
44
48
  /**
45
- * Traverses the tree and flattens it into all tree nodes.
49
+ * Flattens a tree into an array containing all its nodes using depth-first traversal.
50
+ *
51
+ * @param tree - The root node to flatten.
52
+ * @param addNodeFn - Optional filter controlling which nodes and subtrees are included.
53
+ * @returns An array of all nodes in the tree that pass the filter.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const nodes = flattenTree(rootNode);
58
+ * // Returns [root, child1, leaf1, leaf2, child2, leaf3, child3]
59
+ * ```
46
60
  */
47
61
  export declare function flattenTree<N extends TreeNode<unknown> = TreeNode<unknown>>(tree: N, addNodeFn?: Maybe<FlattenTreeAddNodeDecisionFunction<N>>): N[];
48
62
  /**
49
- * Traverses the tree and pushes the nodes into the input array.
63
+ * Flattens a tree and appends the resulting nodes to an existing array.
50
64
  *
51
- * @param tree
52
- * @param array
53
- * @returns
65
+ * Useful for accumulating nodes from multiple trees into a single collection.
66
+ *
67
+ * @param tree - The root node to flatten.
68
+ * @param array - The target array to push flattened nodes into.
69
+ * @param addNodeFn - Optional filter controlling which nodes and subtrees are included.
70
+ * @returns The same array reference, now containing the appended nodes.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const existing: TreeNode[] = [someNode];
75
+ * flattenTreeToArray(rootNode, existing);
76
+ * // existing now contains [someNode, root, child1, ...]
77
+ * ```
54
78
  */
55
79
  export declare function flattenTreeToArray<N extends TreeNode<unknown> = TreeNode<unknown>>(tree: N, array: N[], addNodeFn?: Maybe<FlattenTreeAddNodeDecisionFunction<N>>): N[];
80
+ /**
81
+ * Configuration for creating a {@link FlattenTreeFunction} via {@link flattenTreeToArrayFunction}.
82
+ *
83
+ * Extends the exploration config but replaces `shouldVisitNodeFunction` with `shouldAddNodeFunction`
84
+ * to use flattening-specific terminology.
85
+ *
86
+ * @template N - The tree node type.
87
+ * @template V - The mapped value type collected in the output array.
88
+ */
56
89
  export interface FlattenTreeToArrayFunctionConfig<N extends TreeNode<unknown>, V> extends Omit<ExploreTreeFunctionConfig<N, V>, 'shouldVisitNodeFunction'> {
90
+ /**
91
+ * Controls whether each node's mapped value is added to the output array.
92
+ * Defaults to adding all nodes.
93
+ */
57
94
  readonly shouldAddNodeFunction?: Maybe<FlattenTreeAddNodeDecisionFunction<N, V>>;
58
95
  }
59
96
  /**
package/src/lib/type.d.ts CHANGED
@@ -14,32 +14,35 @@ export type ObjectWithConstructor = {
14
14
  constructor: Function;
15
15
  };
16
16
  /**
17
- * Returns true if the input object is an object with a constructor.
17
+ * Returns true if the input is a function-like value with a prototype and constructor (i.e., a class or named function declaration).
18
+ * Returns false for arrow functions, class instances, plain objects, and primitives.
18
19
  *
19
- * @param obj
20
- * @returns
20
+ * @param obj - The value to check.
21
+ * @returns Whether the value is a function with a constructor.
21
22
  */
22
23
  export declare function isObjectWithConstructor(obj: any): obj is ObjectWithConstructor;
23
24
  /**
24
- * Returns true if the input object is a class type that requires using "new".
25
+ * Returns true if the input is a class (requires `new` to instantiate). Distinguishes classes from regular functions
26
+ * by checking that the prototype is non-writable.
25
27
  *
26
- * @param obj
27
- * @returns
28
+ * @param obj - The value to check.
29
+ * @returns Whether the value is a class type.
28
30
  */
29
31
  export declare function isClassLikeType(obj: unknown): obj is ClassLikeType;
30
32
  export type FunctionType = 'function' | 'class' | 'arrow';
31
33
  /**
32
- * Returns the input value's function type, or null if not a function.
34
+ * Determines the function type of the input value: `'class'`, `'function'`, or `'arrow'`.
35
+ * Returns `null` if the input is not a function.
33
36
  *
34
- * @param x
35
- * @returns
37
+ * @param x - The value to inspect.
38
+ * @returns The {@link FunctionType}, or `null` for non-functions.
36
39
  */
37
40
  export declare function getFunctionType(x: unknown): Maybe<FunctionType>;
38
41
  /**
39
- * Returns true if the input is a non-class function.
42
+ * Returns true if the input is a function but not a class (i.e., a regular function or arrow function).
40
43
  *
41
- * @param x
42
- * @returns
44
+ * @param x - The value to check.
45
+ * @returns Whether the value is a non-class function.
43
46
  */
44
47
  export declare function isNonClassFunction(x: unknown): x is Function;
45
48
  /**