@rzl-zone/utils-js 3.0.1-beta.0 → 3.1.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 (152) hide show
  1. package/dist/assertions/index.cjs +1 -1
  2. package/dist/assertions/index.d.ts +96 -116
  3. package/dist/assertions/index.js +1 -1
  4. package/dist/chunk-25G6B35W.js +1 -0
  5. package/dist/chunk-2AUUPGMN.js +1 -0
  6. package/dist/chunk-2JQQQ625.js +1 -0
  7. package/dist/chunk-445TAVT4.cjs +1 -0
  8. package/dist/chunk-467VEMJH.js +1 -0
  9. package/dist/chunk-6Q4I2RPC.cjs +1 -0
  10. package/dist/chunk-6SMJMZ7G.cjs +1 -0
  11. package/dist/chunk-BLCANGFS.js +1 -0
  12. package/dist/chunk-CK3BZGEU.js +1 -0
  13. package/dist/{chunk-JWHM3WZQ.cjs → chunk-D43GV6EF.cjs} +1 -1
  14. package/dist/chunk-DFSTVQFI.cjs +1 -0
  15. package/dist/chunk-DYRDBYPF.cjs +1 -0
  16. package/dist/chunk-EXXLUO7L.cjs +1 -0
  17. package/dist/chunk-G72VSVGO.js +1 -0
  18. package/dist/chunk-GAJTFCUA.js +1 -0
  19. package/dist/chunk-GOJNH55O.cjs +1 -0
  20. package/dist/chunk-HXST7RJB.js +1 -0
  21. package/dist/{chunk-BYZAD3XN.cjs → chunk-HXTACM3O.cjs} +1 -1
  22. package/dist/chunk-IJTZWWRJ.cjs +1 -0
  23. package/dist/chunk-ISJ33O2J.cjs +1 -0
  24. package/dist/chunk-JISH2VGG.js +1 -0
  25. package/dist/{chunk-FF76ISQ2.js → chunk-JQZUWBIX.js} +1 -1
  26. package/dist/{chunk-XH6MCRLP.js → chunk-K4PLGD7C.js} +1 -1
  27. package/dist/chunk-KZQB7H4E.cjs +1 -0
  28. package/dist/chunk-LUVV5KSD.cjs +2 -0
  29. package/dist/chunk-LVUSFXQS.cjs +1 -0
  30. package/dist/chunk-ME5OV5HN.js +1 -0
  31. package/dist/chunk-MF5Y5K4N.cjs +1 -0
  32. package/dist/chunk-MJAW5RAK.js +1 -0
  33. package/dist/chunk-MWLEM7ED.js +1 -0
  34. package/dist/chunk-NSVLG7NY.js +4 -0
  35. package/dist/chunk-NUHOOAUN.cjs +1 -0
  36. package/dist/chunk-NUVGETPD.js +2 -0
  37. package/dist/chunk-O5VXBNUQ.cjs +4 -0
  38. package/dist/chunk-O7SJR4CY.cjs +1 -0
  39. package/dist/chunk-OX6RLS2F.cjs +1 -0
  40. package/dist/chunk-PFLNHD4B.cjs +1 -0
  41. package/dist/chunk-PSWITZK5.js +1 -0
  42. package/dist/chunk-PYUVKHUF.cjs +1 -0
  43. package/dist/chunk-REFMEB4A.js +1 -0
  44. package/dist/chunk-RHE3M2NJ.cjs +1 -0
  45. package/dist/chunk-RHIBYOFQ.js +1 -0
  46. package/dist/chunk-S7GMG4TB.js +1 -0
  47. package/dist/chunk-TQMZ2LPI.js +1 -0
  48. package/dist/{chunk-RN3TP3S3.js → chunk-U4TZO7WV.js} +1 -1
  49. package/dist/chunk-UUMKL74S.js +1 -0
  50. package/dist/{chunk-EXZ47NOW.js → chunk-VQLAPEL3.js} +1 -1
  51. package/dist/chunk-VTR75UID.cjs +1 -0
  52. package/dist/chunk-XFCJDSB2.cjs +1 -0
  53. package/dist/chunk-XOYX4PLZ.cjs +1 -0
  54. package/dist/chunk-Z6FLCEN6.js +1 -0
  55. package/dist/chunk-ZO5364A6.cjs +1 -0
  56. package/dist/conversions/index.cjs +1 -1
  57. package/dist/conversions/index.d.ts +396 -593
  58. package/dist/conversions/index.js +1 -1
  59. package/dist/env/index.d.ts +5 -8
  60. package/dist/events/index.cjs +1 -1
  61. package/dist/events/index.d.ts +80 -77
  62. package/dist/events/index.js +1 -1
  63. package/dist/{array-CIZRbqTF.d.ts → extends-Bk_SBGdT.d.ts} +145 -1
  64. package/dist/formatting/index.cjs +1 -1
  65. package/dist/formatting/index.d.ts +478 -440
  66. package/dist/formatting/index.js +1 -1
  67. package/dist/generator/index.cjs +1 -1
  68. package/dist/generator/index.d.ts +135 -112
  69. package/dist/generator/index.js +1 -1
  70. package/dist/index.cjs +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/index.js +1 -1
  73. package/dist/{is-array-Ckm_47hw.d.ts → is-array--YjXV-Wx.d.ts} +2 -352
  74. package/dist/{isPlainObject-BKYaI6a8.d.ts → isPlainObject-BVhBAPHX.d.ts} +49 -62
  75. package/dist/next/index.cjs +6 -6
  76. package/dist/next/index.d.ts +125 -105
  77. package/dist/next/index.js +5 -5
  78. package/dist/next/server/index.cjs +1 -1
  79. package/dist/next/server/index.d.ts +8 -22
  80. package/dist/next/server/index.js +1 -1
  81. package/dist/operations/index.cjs +1 -1
  82. package/dist/operations/index.d.ts +72 -127
  83. package/dist/operations/index.js +1 -1
  84. package/dist/parsers/index.cjs +1 -1
  85. package/dist/parsers/index.d.ts +26 -27
  86. package/dist/parsers/index.js +1 -1
  87. package/dist/predicates/index.cjs +1 -1
  88. package/dist/predicates/index.d.ts +686 -660
  89. package/dist/predicates/index.js +1 -1
  90. package/dist/promise/index.cjs +1 -1
  91. package/dist/promise/index.d.ts +14 -23
  92. package/dist/promise/index.js +1 -1
  93. package/dist/rzl-utils.global.js +3 -3
  94. package/dist/string-XA-til3C.d.ts +351 -0
  95. package/dist/strings/index.cjs +1 -1
  96. package/dist/strings/index.d.ts +301 -376
  97. package/dist/strings/index.js +1 -1
  98. package/dist/stylings/index.cjs +1 -1
  99. package/dist/stylings/index.d.ts +15 -23
  100. package/dist/stylings/index.js +1 -1
  101. package/dist/types/index.d.ts +1 -1
  102. package/dist/urls/index.cjs +1 -1
  103. package/dist/urls/index.d.ts +279 -302
  104. package/dist/urls/index.js +1 -1
  105. package/package.json +53 -11
  106. package/dist/chunk-2TRAPBZ7.cjs +0 -1
  107. package/dist/chunk-4DK3RCC4.js +0 -2
  108. package/dist/chunk-4JOQ45HL.js +0 -1
  109. package/dist/chunk-55CZALRS.js +0 -1
  110. package/dist/chunk-62HX5Z45.cjs +0 -1
  111. package/dist/chunk-7NA6DUHR.cjs +0 -2
  112. package/dist/chunk-BVPMMWDL.cjs +0 -1
  113. package/dist/chunk-CEFYHEM4.cjs +0 -1
  114. package/dist/chunk-CN53M4QZ.cjs +0 -1
  115. package/dist/chunk-D47MHBSD.cjs +0 -1
  116. package/dist/chunk-DGH75GJD.js +0 -1
  117. package/dist/chunk-E5NUI7PN.js +0 -1
  118. package/dist/chunk-FDITZ5C6.cjs +0 -1
  119. package/dist/chunk-FSSV24W7.cjs +0 -1
  120. package/dist/chunk-GCGU2WB7.js +0 -1
  121. package/dist/chunk-GECI2YBP.js +0 -1
  122. package/dist/chunk-GQE4OVHC.cjs +0 -1
  123. package/dist/chunk-GRVZXQXL.cjs +0 -1
  124. package/dist/chunk-I4AVNHPA.cjs +0 -1
  125. package/dist/chunk-KBKYG3IY.cjs +0 -1
  126. package/dist/chunk-KCQDDZJE.cjs +0 -1
  127. package/dist/chunk-LVKAYEZ4.js +0 -1
  128. package/dist/chunk-MBDWTK54.cjs +0 -1
  129. package/dist/chunk-MNGGDB2G.js +0 -1
  130. package/dist/chunk-MY7BA4GI.cjs +0 -1
  131. package/dist/chunk-N2IJPIND.cjs +0 -1
  132. package/dist/chunk-NIMNTEGV.js +0 -1
  133. package/dist/chunk-POCPQYZS.js +0 -1
  134. package/dist/chunk-PVJF2JHM.js +0 -1
  135. package/dist/chunk-QCFXEUKL.js +0 -1
  136. package/dist/chunk-QFCGBBSY.js +0 -1
  137. package/dist/chunk-QQYAUPSK.cjs +0 -1
  138. package/dist/chunk-TC4VBE4Y.cjs +0 -1
  139. package/dist/chunk-TUXDINHF.cjs +0 -1
  140. package/dist/chunk-U5Y2FXMN.cjs +0 -1
  141. package/dist/chunk-UUPQI6ND.cjs +0 -1
  142. package/dist/chunk-VYCGZ2S6.js +0 -1
  143. package/dist/chunk-W5EDKJK3.js +0 -1
  144. package/dist/chunk-WHAVUFEU.js +0 -1
  145. package/dist/chunk-X3GTRVVK.cjs +0 -4
  146. package/dist/chunk-XCFIOTCV.js +0 -1
  147. package/dist/chunk-XE27XPJR.js +0 -1
  148. package/dist/chunk-XVB3ZZEB.js +0 -1
  149. package/dist/chunk-YEERJDOF.js +0 -4
  150. package/dist/chunk-ZBSIGJFO.cjs +0 -1
  151. package/dist/chunk-ZYAML74V.js +0 -1
  152. package/dist/extends-Mp81Hq9-.d.ts +0 -145
@@ -1,24 +1,22 @@
1
1
  /** ----------------------------------------------------------
2
- * * ***Represents a non-empty array of key–value pairs.***
2
+ * * ***Type-Utility: `QueryParamPairs`.***
3
3
  * ----------------------------------------------------------
4
- *
4
+ * **Represents a non-empty array of key–value pairs.**
5
+ * @description
5
6
  * Type for `queryParams` parameter, the second parameter of **{@link constructURL}**.
6
- *
7
- * - Each inner tuple strictly follows the `[string, string | number]` shape.
8
- * - Ensures the outer array contains **at least one pair** (non-empty).
9
- * - Commonly used for URL construction parameters,
10
- * query string segments, or other key–value structured data.
11
- *
7
+ * - **Behavior:**
8
+ * - Each inner tuple strictly follows the `[string, string | number]` shape.
9
+ * - Ensures the outer array contains **at least one pair** (non-empty).
10
+ * - Commonly used for URL construction parameters,
11
+ * query string segments, or other key–value structured data.
12
12
  * @example
13
13
  * // ✅ valid usage
14
14
  * const params: QueryParamPairs = [
15
15
  * ["foo", 1],
16
16
  * ["bar", "baz"]
17
17
  * ];
18
- *
19
18
  * constructURL("https://example.com", params);
20
19
  *
21
- * @example
22
20
  * // ❌ invalid: must contain at least one item
23
21
  * const empty: QueryParamPairs = [];
24
22
  *
@@ -27,354 +25,335 @@
27
25
  */
28
26
  type QueryParamPairs=[[string,string|number],...[string,string|number][]];
29
27
  /** ---------------------------------
30
- * * ***Constructs a valid URL with optional query parameters and allows selective removal of duplicate parameters.***
28
+ * * ***Utility: `constructURL`.***
31
29
  * ---------------------------------
32
- *
33
- * @param {string | URL} baseUrl
34
- * The base URL to build upon. Must include protocol (e.g., "https://"),
35
- * domain, and may include port and existing query parameters.
36
- *
37
- * @param {Iterable<[string, string]>|URLSearchParamsIterator<[string, string]>} [queryParams]
30
+ * **Constructs a valid URL with optional query parameters and allows selective removal of duplicate parameters.**
31
+ * @param {string | URL} baseUrl The base URL to build upon. Must include protocol (e.g., `"https://"`), `domain`, and may include port and existing query parameters.
32
+ * @param {Iterable<[string, string]> | URLSearchParamsIterator<[string, string]> | QueryParamPairs} [queryParams]
38
33
  * Additional query parameters to append or overwrite on the URL.
39
- * Accepts any iterable of key-value pairs (like `new URLSearchParams().entries()` and `[[string, string | number]...]`).
40
- *
34
+ * - Accepts any iterable of key-value pairs (like `new URLSearchParams().entries()` and `[[string, string | number]...]`).
41
35
  * @param {string[]} [removeParams]
42
- * A list of query parameter keys to remove from the final URL,
43
- * whether they were in the base URL or provided queryParams.
44
- *
45
- * @returns {URL}
46
- * A new URL object representing the constructed URL with merged
47
- * and cleaned query parameters.
48
- *
49
- * @throws {TypeError}
50
- * Throws if `baseUrl` is not a valid non-empty string or URL object,
51
- * or if `queryParams` is not iterable, or if `removeParams` is not an array of strings.
52
- *
36
+ * A list of query parameter keys to remove from the final URL, whether they were in the base URL or provided queryParams.
37
+ * @returns {URL} A new URL object representing the constructed URL with merged and cleaned query parameters.
38
+ * @throws {TypeError} Throws if `baseUrl` is not a valid non-empty string or URL object, or if `queryParams` is not iterable, or if `removeParams` is not an array of strings.
53
39
  * @example
54
- * // Basic usage
55
- * constructURL("https://example.com/path", new URLSearchParams({ a: "1", b: "2" }).entries());
56
- * // ➔ URL { href: "https://example.com/path?a=1&b=2", ... }
57
- *
58
- * @example
59
- * // Remove parameters from base and added
60
- *
61
- * // with new URLSearchParams({ ... }).entries();
62
- * constructURL("https://example.com/path?foo=1&bar=2", new URLSearchParams({ bar: "ignored", baz: "3" }).entries(), ["bar"]);
63
- * // ➔ URL { href: "https://example.com/path?foo=1&baz=3", ... }
64
- *
65
- * // with [[string, string | number]...]
66
- * constructURL("https://example.com/path?foo=1&bar=2", [["bar", "ignored"],["baz", 3]], ["bar"]);
67
- * // URL { href: "https://example.com/path?foo=1&baz=3", ... }
68
- *
69
- * const params: QueryParamPairs = [
70
- * ["foo", 1],
71
- * ["bar", 2],
72
- * ["baz", 3]
73
- * ];
74
- *
75
- * constructURL("https://example.com", params, ["bar"]);
76
- * // ➔ URL { href: "https://example.com/?foo=1&baz=3", ... }
40
+ * 1. #### Basic Usage:
41
+ * ```ts
42
+ * constructURL(
43
+ * "https://example.com/path",
44
+ * new URLSearchParams({ a: "1", b: "2" }).entries()
45
+ * );
46
+ * // ➔ URL { href: "https://example.com/path?a=1&b=2", ... }
47
+ * ```
48
+ * 2. #### Remove parameters from Base and Added:
49
+ * ```ts
50
+ * // with new URLSearchParams({ ... }).entries();
51
+ * constructURL(
52
+ * "https://example.com/path?foo=1&bar=2",
53
+ * new URLSearchParams({ bar: "ignored", baz: "3" }).entries(),
54
+ * ["bar"]
55
+ * );
56
+ * // ➔ URL { href: "https://example.com/path?foo=1&baz=3", ... }
57
+ *
58
+ * // with [[string, string | number]...]
59
+ * constructURL(
60
+ * "https://example.com/path?foo=1&bar=2",
61
+ * [["bar", "ignored"],["baz", 3]],
62
+ * ["bar"]
63
+ * );
64
+ * // ➔ URL { href: "https://example.com/path?foo=1&baz=3", ... }
65
+ *
66
+ * const params: QueryParamPairs = [
67
+ * ["foo", 1],
68
+ * ["bar", 2],
69
+ * ["baz", 3]
70
+ * ];
71
+ *
72
+ * constructURL("https://example.com", params, ["bar"]);
73
+ * // ➔ URL { href: "https://example.com/?foo=1&baz=3", ... }
74
+ * ```
77
75
  */
78
76
  declare const constructURL:(baseUrl:string|URL,queryParams?:URLSearchParamsIterator<[string,string|number]>|QueryParamPairs,removeParams?:string[])=>URL;
79
77
  /** ---------------------------------
80
- * * ***Extracts all valid URLs from a given string.***
78
+ * * ***Utility: `extractURLs`.***
81
79
  * ---------------------------------
82
- *
80
+ * **Extracts all valid URLs from a given string.**
81
+ * @description
83
82
  * This function scans the input url and returns an array of URLs
84
83
  * that match a valid `http` or `https` format.
85
- *
86
- * Supports:
87
- * - Internationalized domain names (IDN), e.g. `https://münich.de`
88
- * - Unicode & emoji paths, e.g. `https://example.com/🎉/page`
89
- * - Long URLs with multiple queries & fragments, e.g. `https://example.com/path?foo=1#hash`
90
- *
91
- * Ignores:
92
- * - Non-string inputs
93
- * - Empty or whitespace-only strings
94
- * - Non-HTTP(S) protocols (ftp, mailto, etc)
95
- *
96
- * @param {string|null|undefined} [url] - The input string containing potential URLs.
84
+ * - **Supports:**
85
+ * - Internationalized domain names (IDN), e.g. `https://münich.de`
86
+ * - Unicode & emoji paths, e.g. `https://example.com/🎉/page`
87
+ * - Long URLs with multiple queries & fragments, e.g. `https://example.com/path?foo=1#hash`
88
+ * - **Ignores:**
89
+ * - Non-string inputs
90
+ * - Empty or whitespace-only strings
91
+ * - Non-HTTP(S) protocols (ftp, mailto, etc)
92
+ * @param {string | null | undefined} url - The input string containing potential URLs.
97
93
  * @returns {string[] | null} An array of extracted URLs or `null` if no URLs are found.
98
94
  * @example
99
95
  * extractURLs("Visit https://example.com and https://例子.公司");
100
96
  * // ➔ ["https://example.com", "https://例子.公司"]
101
- *
102
- * @example
103
97
  * extractURLs("Here: https://example.com/🎉/page");
104
98
  * // ➔ ["https://example.com/🎉/page"]
105
- *
106
- * @example
107
99
  * extractURLs("ftp://example.com http://example.com");
108
100
  * // ➔ ["http://example.com"]
109
101
  */
110
- declare const extractURLs:(url?:string|null)=>string[]|null;
111
- /** --------------------------------------------------------
112
- * * ***Get Prefix from URL with Optional Base or Auto-detection (Supports String or Array of URLs).***
113
- * --------------------------------------------------------
114
- *
115
- * @description
116
- * This function extracts the prefix from one or more URLs. It can either:
117
- * - Use a provided `base` string or an array of strings to check and return the matching prefix.
118
- * - Automatically detect the prefix if no `base` is provided by analyzing the first part of the URL.
119
- *
120
- * The function is flexible and can handle both scenarios:
121
- * 1. **When the base is provided as a single string or an array of strings**: The function will check if the URL starts with one of the provided base(s) and return the matching base.
122
- * 2. **When the base is not provided**: The function will automatically detect the prefix by splitting the URL or using a regex.
123
- *
124
- * **Important Notes**:
125
- * - If a base (or an array of bases) is provided, the URL must start with one of the given base(s).
126
- * - If no base is provided, the function will attempt to detect the prefix automatically.
127
- * - The `url` parameter can be either a string or an array of strings.
128
- * - Supports deduplication of results (enabled by default).
129
- * - Automatically returns a single string if only one unique result exists after processing.
130
- *
131
- * ---
102
+ declare const extractURLs:(url:string|null|undefined)=>string[]|null;type GetPrefixPathnameOptions={
103
+ /** The number of levels to include in the prefix (default is `1`). For example, with `levels = 2`, the function will return the first two parts of the URL.
132
104
  *
133
- * @param {string|string[]} url The full URL(s) from which the prefix should be extracted. Can be a string or an array of strings.
134
- * @param {string|string[]|null} [base=null] The base URL(s) (e.g., "/settings"). It can be a string, an array of strings, or `null`. If provided, it will be used to check the URL(s). If not provided, the prefix will be auto-detected.
135
- * @param {{ levels?: number; removeDuplicates?: boolean }} [options] Additional options object:
136
- * - `levels` (default `1`): The number of segments to include when auto-detecting the prefix (e.g. `/foo/bar` for `levels: 2`).
137
- * - `removeDuplicates` (default `true`): Whether to remove duplicate prefixes from the final array result.
138
- *
139
- * @returns {string|string[]|null}
140
- * Returns one of:
141
- * - A single string if only one unique prefix/base is found.
142
- * - An array of strings if multiple different prefixes/bases are found.
143
- * - `null` if no matching base is found when using `base`.
144
- *
145
- * ---
146
- *
147
- * @throws {TypeError}
148
- * Throws if:
149
- * - `url` is not a string or an array of strings.
150
- * - `base` is not a string, array of strings, or `null`.
151
- * - `options` is not an object.
152
- * - `levels` is not a number.
153
- * - `removeDuplicates` is not a boolean.
154
- *
155
- * ---
156
- *
157
- * ### **🔹 Usage Examples**
105
+ * @default 1
106
+ */
107
+ levels?:number;
108
+ /** Whether to remove duplicates from the result if multiple URLs are passed (default is `true`).
158
109
  *
159
- * #### ✅ **Correct Usage (With an Array of URLs and Base)**
110
+ * @default true
111
+ */
112
+ removeDuplicates?:boolean;};
113
+ /** --------------------------------------------------------
114
+ * * ***Utility: `getPrefixPathname`.***
115
+ * --------------------------------------------------------
116
+ * **Get Prefix from URL with Optional Base or Auto-detection (Supports String or Array of URLs).**
117
+ * - **This function extracts the prefix from one or more URLs. It can either:**
118
+ * - Use a provided `base` string or an array of strings to check and return the matching prefix.
119
+ * - Automatically detect the prefix if no `base` is provided by analyzing the first part of the URL.
120
+ * - **The function is flexible and can handle both scenarios:**
121
+ * 1. **When the base is provided as a single string or an array of strings**:
122
+ * - The function will check if the URL starts with one of the provided base(s) and return the matching base.
123
+ * 2. **When the base is not provided**:
124
+ * - The function will automatically detect the prefix by splitting the URL or using a regex.
125
+ * - **Important Notes**:
126
+ * - If a base (or an array of bases) is provided, the URL must start with one of the given base(s).
127
+ * - If no base is provided, the function will attempt to detect the prefix automatically.
128
+ * - The `url` parameter can be either a string or an array of strings.
129
+ * - Supports deduplication of results (enabled by default).
130
+ * - Automatically returns a single string if only one unique result exists after processing.
131
+ * @param {string|string[]} url The full URL(s) from which the prefix should be extracted.
132
+ * - Can be a `string` or an `array of strings`.
133
+ * @param {string|string[]|null} [base=null] The base URL(s) (e.g., `"/settings"`).
134
+ * - It can be a `string`, an `array of strings`, or `null`.
135
+ * - If `provided`, it will be used to check the URL(s).
136
+ * - If `not provided`, the prefix will be auto-detected.
137
+ * @param {GetPrefixPathnameOptions} [options] Additional options object:
138
+ * - `levels` (default `1`): The number of segments to include when auto-detecting the prefix (e.g. `/foo/bar` for `levels: 2`).
139
+ * - `removeDuplicates` (default `true`): Whether to remove duplicate prefixes from the final array result.
140
+ * @returns {string|string[]|null} Returns one of:
141
+ * - A single string if only one unique prefix/base is found.
142
+ * - An array of strings if multiple different prefixes/bases are found.
143
+ * - `null` if no matching base is found when using `base`.
144
+ * @throws {TypeError} Throws if:
145
+ * - `url` is `not a string` or `not an array of strings`.
146
+ * - `base` is `not a string`, `array of strings`, or `null`.
147
+ * - `options` is `not an object`.
148
+ * - `levels` is `not a number`.
149
+ * - `removeDuplicates` is `not a boolean`.
150
+ * @example
151
+ * - #### ✅ **Correct Usage (With an Array of URLs and Base):**
160
152
  * ```ts
161
- * const routes = [
162
- * "/settings/profile",
163
- * "/settings/password",
164
- * "/settings/other-path",
165
- * "/other-path/xyz",
166
- * ];
167
- *
168
- * // With base provided as a string
169
- * routes.forEach(route => {
170
- * console.log(getPrefixPathname(route, '/settings'));
171
- * // ➔ "/settings"
172
- * });
173
- *
174
- * // With base provided as an array
175
- * routes.forEach(route => {
176
- * console.log(getPrefixPathname(route, ['/settings', '/admin']));
177
- * // ➔ "/settings" or "/admin" depending on the current URL.
178
- * });
153
+ * const routes = [
154
+ * "/settings/profile",
155
+ * "/settings/password",
156
+ * "/settings/other-path",
157
+ * "/other-path/xyz",
158
+ * ];
159
+ *
160
+ * // With base provided as a string
161
+ * routes.forEach(route => {
162
+ * console.log(getPrefixPathname(route, '/settings'));
163
+ * // ➔ "/settings"
164
+ * });
165
+ *
166
+ * // With base provided as an array
167
+ * routes.forEach(route => {
168
+ * console.log(getPrefixPathname(route, ['/settings', '/admin']));
169
+ * // ➔ "/settings" or "/admin" depending on the current URL.
170
+ * });
179
171
  * ```
180
- *
181
- * #### ✅ **Correct Usage (With Single URL and Single Base)**
172
+ * - #### ✅ **Correct Usage (With Single URL and Single Base):**
182
173
  * ```ts
183
- * const result = getPrefixPathname("/settings/profile", "/settings");
184
- * console.log(result); // ➔ "/settings"
174
+ * const result = getPrefixPathname("/settings/profile", "/settings");
175
+ * console.log(result); // ➔ "/settings"
185
176
  * ```
186
- *
187
- * #### ✅ **Correct Usage (With Multiple URLs and Single Base)**
177
+ * - #### ✅ **Correct Usage (With Multiple URLs and Single Base):**
188
178
  * ```ts
189
- * const result = getPrefixPathname(["/settings/profile", "/settings/password"], "/settings");
190
- * console.log(result); // ➔ "/settings"
191
- *
192
- * const result2 = getPrefixPathname(["/settings/profile", "/other/password"], "/other");
193
- * console.log(result2); // ➔ "/other"
179
+ * const result = getPrefixPathname(
180
+ * ["/settings/profile", "/settings/password"],
181
+ * "/settings"
182
+ * );
183
+ * console.log(result); // ➔ "/settings"
184
+ *
185
+ * const result2 = getPrefixPathname(
186
+ * ["/settings/profile", "/other/password"],
187
+ * "/other"
188
+ * );
189
+ * console.log(result2); // ➔ "/other"
194
190
  * ```
195
- *
196
- * #### ✅ **Correct Usage (With Multiple URLs and Multiple Bases)**
191
+ * - #### ✅ **Correct Usage (With Multiple URLs and Multiple Bases)**
197
192
  * ```ts
198
- * const result = getPrefixPathname(["/settings/profile", "/admin/password"], ["/settings", "/admin"]);
199
- * console.log(result); // ➔ ["/settings", "/admin"]
193
+ * const result = getPrefixPathname(
194
+ * ["/settings/profile", "/admin/password"],
195
+ * ["/settings", "/admin"]
196
+ * );
197
+ * console.log(result); // ➔ ["/settings", "/admin"]
200
198
  * ```
201
- *
202
- * #### ✅ **Auto-detection of Prefix**
199
+ * - #### ✅ **Auto-detection of Prefix**
203
200
  * ```ts
204
- * const result = getPrefixPathname("/settings/profile");
205
- * console.log(result); // ➔ "/settings"
206
- *
207
- * const result2 = getPrefixPathname("/settings/profile/info", null, { levels: 2 });
208
- * console.log(result2); // ➔ "/settings/profile"
201
+ * const result = getPrefixPathname("/settings/profile");
202
+ * console.log(result); // ➔ "/settings"
203
+ *
204
+ * const result2 = getPrefixPathname(
205
+ * "/settings/profile/info",
206
+ * null,
207
+ * { levels: 2 }
208
+ * );
209
+ * console.log(result2); // ➔ "/settings/profile"
209
210
  * ```
210
- *
211
- * #### ✅ **Multiple URLs with Auto-detection**
211
+ * - #### ✅ **Multiple URLs with Auto-detection**
212
212
  * ```ts
213
- * const result = getPrefixPathname(["/admin/profile", "/settings/password"]);
214
- * console.log(result); // ➔ ["/admin", "/settings"]
213
+ * const result = getPrefixPathname(["/admin/profile", "/settings/password"]);
214
+ * console.log(result); // ➔ ["/admin", "/settings"]
215
215
  * ```
216
- *
217
- * #### ✅ **Handling Duplicates**
216
+ * - #### ✅ **Handling Duplicates**
218
217
  * ```ts
219
- * const result = getPrefixPathname(["/settings/profile", "/settings/password"], "/settings");
220
- * console.log(result); // ➔ "/settings" (deduped to single string)
221
- *
222
- * const result2 = getPrefixPathname(["/settings/profile", "/settings/profile"], "/settings", { removeDuplicates: false });
223
- * console.log(result2); // ➔ ["/settings", "/settings"]
218
+ * const result = getPrefixPathname(
219
+ * ["/settings/profile", "/settings/password"],
220
+ * "/settings"
221
+ * );
222
+ * console.log(result); // ➔ "/settings" (deduped to single string)
223
+ *
224
+ * const result2 = getPrefixPathname(
225
+ * ["/settings/profile", "/settings/profile"],
226
+ * "/settings",
227
+ * { removeDuplicates: false }
228
+ * );
229
+ * console.log(result2); // ➔ ["/settings", "/settings"]
224
230
  * ```
225
- *
226
- * #### ❌ **Incorrect Usage (URL Does Not Match Base)**
231
+ * - #### ❌ **Incorrect Usage (URL Does Not Match Base)**
227
232
  * ```ts
228
- * const result = getPrefixPathname("/other-path/profile", "/settings");
229
- * console.log(result); // ➔ null
233
+ * const result = getPrefixPathname("/other-path/profile", "/settings");
234
+ * console.log(result); // ➔ null
230
235
  * ```
231
236
  */
232
- declare const getPrefixPathname:(url:string|string[],base?:string|string[]|null,options?:{
233
- /** The number of levels to include in the prefix (default is 1). For example, with `levels = 2`, the function will return the first two parts of the URL. */
234
- levels?:number;
235
- /** Whether to remove duplicates from the result if multiple URLs are passed (default is `true`). */
236
- removeDuplicates?:boolean;})=>string|string[]|null;
237
+ declare const getPrefixPathname:(url:string|string[],base?:string|string[]|null,options?:GetPrefixPathnameOptions)=>string|string[]|null;
237
238
  /** --------------------------------------------------------
238
- * * ***Extract First Valid Prefix from Path Array or String.***
239
+ * * ***Utility: `getFirstPrefixPathname`.***
239
240
  * --------------------------------------------------------
240
- *
241
- * ### 🚀 **Main Purpose:**
242
- * This function helps extract the first valid URL prefix from various possible inputs.
243
- * It is especially useful in routing systems, middleware, or frontend apps that
244
- * need to decide layout, active navigation, or permissions based on the first
245
- * segment (or prefix) of a pathname.
246
- *
247
- * Typical uses include:
248
- * - Determining which layout to render (e.g., `/admin` vs `/dashboard` vs `/`).
249
- * - Highlighting the active menu item in a sidebar based on the current URL.
250
- * - Enforcing route guards or access controls depending on the URL prefix.
251
- * - Parsing multi-level route prefixes and selecting the most relevant one.
252
- *
253
- * ---
254
- *
255
- * ### 🔍 Behavior:
256
- * It works as follows:
257
- * - If `result` is an array of strings, it normalizes each element and returns
258
- * the first non-root path (i.e., not just `"/"`). If all items normalize to `"/"`,
259
- * it returns the `defaultValue` (normalized).
260
- * - If `result` is a single string, it normalizes it and returns it if valid,
261
- * otherwise falls back to the normalized `defaultValue`.
262
- * - If `result` is `null` or `undefined`, it returns the normalized `defaultValue`.
263
- *
264
- * ---
265
- *
266
- * ### 🔍 Validation & Errors:
267
- *
268
- * - Throws a `TypeError` if:
269
- * - `defaultValue` is not a non-empty string.
270
- * - `result` is an array that contains non-string elements.
271
- * - `result` is a value that is neither `string`, `string[]`, nor `null`.
272
- *
273
- * ---
274
- *
275
- * ### 🛠 Usage Examples:
276
- *
277
- * 1. #### For React: *Determining layout*
241
+ * **Extract First Valid Prefix from Path Array or String.**
242
+ * - **Main Purpose:**
243
+ * - This function helps extract the first valid URL prefix from various possible inputs.
244
+ * - It is especially useful in routing systems, middleware, or frontend apps that need to
245
+ * decide layout, active navigation, or permissions based on the first segment (or prefix) of a pathname.
246
+ * - **Typical uses include:**
247
+ * - Determining which layout to render (e.g., `/admin` vs `/dashboard` vs `/`).
248
+ * - Highlighting the active menu item in a sidebar based on the current URL.
249
+ * - Enforcing route guards or access controls depending on the URL prefix.
250
+ * - Parsing multi-level route prefixes and selecting the most relevant one.
251
+ * - **Behavior:**
252
+ * - It works as follows:
253
+ * - If `result` is an array of strings, it normalizes each element and returns
254
+ * the first non-root path (i.e., not just `"/"`).
255
+ * - If all items normalize to `"/"`,
256
+ * it returns the `defaultValue` (normalized).
257
+ * - If `result` is a single string, it normalizes it and returns it if valid,
258
+ * otherwise falls back to the normalized `defaultValue`.
259
+ * - If `result` is `null` or `undefined`, it returns the normalized `defaultValue`.
260
+ * - **Validation & Errors:**
261
+ * - Throws a `TypeError` if:
262
+ * - `defaultValue` is not a string or empty-string.
263
+ * - `result` is an array that contains non-string elements.
264
+ * - `result` is a value that is neither `string`, `string[]`, nor `null`.
265
+ * @example
266
+ * 1. #### For React (*Determining layout*):
278
267
  * ```ts
279
- * const prefix = getFirstPrefixPathname(getPrefixPathname("/admin/settings", ["/admin", "/dashboard"]));
280
- * if (prefix === "/admin") {
281
- * renderAdminLayout();
282
- * }
268
+ * const prefix = getFirstPrefixPathname(
269
+ * getPrefixPathname(
270
+ * "/admin/settings",
271
+ * ["/admin", "/dashboard"]
272
+ * )
273
+ * );
274
+ *
275
+ * if (prefix === "/admin") {
276
+ * renderAdminLayout();
277
+ * }
283
278
  * ```
284
279
  *
285
- * 2. #### Setting active menu state
280
+ * 2. #### Setting active menu state:
286
281
  * ```ts
287
- * const activeSection = getFirstPrefixPathname(["", "/dashboard", "/profile"]);
288
- * // ➔ "/dashboard"
282
+ * const activeSection = getFirstPrefixPathname(["", "/dashboard", "/profile"]);
283
+ * // ➔ "/dashboard"
289
284
  * ```
290
285
  *
291
- * 3. #### Providing graceful fallback
286
+ * 3. #### Providing graceful fallback:
292
287
  * ```ts
293
- * const section = getFirstPrefixPathname([], "/home");
294
- * // ➔ "/home"
288
+ * const section = getFirstPrefixPathname([], "/home");
289
+ * // ➔ "/home"
295
290
  * ```
296
- * 4. #### ✅ Using with an Array of Pathnames
291
+ * 4. #### ✅ Using with an Array of Pathnames:
297
292
  * ```ts
298
- * const result = getPrefixPathname([" ", "/dashboard", "/settings"]);
299
- * console.log(getFirstPrefixPathname(result));
300
- * // ➔ "/dashboard"
293
+ * const result = getPrefixPathname([" ", "/dashboard", "/settings"]);
294
+ * console.log(getFirstPrefixPathname(result));
295
+ * // ➔ "/dashboard"
301
296
  * ```
302
297
  *
303
- * 5. #### ✅ Using with Single String:
298
+ * 5. #### ✅ Using with Single String:
304
299
  * ```ts
305
- * console.log(getFirstPrefixPathname("/profile/settings"));
306
- * // ➔ "/profile/settings"
307
- * console.log(getFirstPrefixPathname(" "));
308
- * // ➔ "/"
300
+ * console.log(getFirstPrefixPathname("/profile/settings"));
301
+ * // ➔ "/profile/settings"
302
+ * console.log(getFirstPrefixPathname(" "));
303
+ * // ➔ "/"
309
304
  * ```
310
305
  *
311
- * 6. #### ✅ Fallback to Custom Default:
306
+ * 6. #### ✅ Fallback to Custom Default:
312
307
  * ```ts
313
- * console.log(getFirstPrefixPathname([" ", ""], "/home"));
314
- * // ➔ "/home"
315
- * console.log(getFirstPrefixPathname(null, "/dashboard"));
316
- * // ➔ "/dashboard"
308
+ * console.log(getFirstPrefixPathname([" ", ""], "/home"));
309
+ * // ➔ "/home"
310
+ * console.log(getFirstPrefixPathname(null, "/dashboard"));
311
+ * // ➔ "/dashboard"
317
312
  * ```
318
313
  *
319
- * 7. #### ✅ Throws on Invalid Input:
314
+ * 7. #### ✅ Throws on Invalid Input:
320
315
  * ```ts
321
- * getFirstPrefixPathname([1, 2] as any); // ➔ ❌ throws TypeError
322
- * getFirstPrefixPathname({} as any); // ➔ ❌ throws TypeError
323
- * getFirstPrefixPathname(null, " "); // ➔ ❌ throws TypeError
316
+ * getFirstPrefixPathname([1, 2] as any); // ➔ ❌ throws TypeError
317
+ * getFirstPrefixPathname({} as any); // ➔ ❌ throws TypeError
318
+ * getFirstPrefixPathname(null, " "); // ➔ ❌ throws TypeError
324
319
  * ```
325
- *
326
- * ---
327
- *
328
- * @param {string | string[] | null} result
329
- * The pathname(s) to process. Can be:
320
+ * @param {string | string[] | null | undefined} result
321
+ * The pathname(s) to process, can be:
330
322
  * - A string path (e.g. `"/profile"`),
331
323
  * - An array of string paths (e.g. `[" ", "/dashboard"]`),
332
324
  * - Or `null`.
333
- *
334
325
  * @param {string} [defaultValue="/"]
335
326
  * A custom default path to use if `result` is null or no valid prefix is found.
336
- * Must be a non-empty string. Defaults to `"/"`.
337
- *
327
+ * - Must be a string and non-empty string.
328
+ * - Defaults to `"/"`.
338
329
  * @returns {string}
339
330
  * The first valid normalized pathname, or the normalized default.
340
- *
341
331
  * @throws {TypeError}
342
- * If `result` is not a valid type, or `defaultValue` is not a non-empty string.
332
+ * If `result` is not a valid type, or `defaultValue` is not a string or empty-string.
343
333
  */
344
- declare const getFirstPrefixPathname:(result?:string|string[]|null,defaultValue?:string)=>string;
334
+ declare const getFirstPrefixPathname:(result:string|string[]|null|undefined,defaultValue?:string)=>string;
345
335
  /** --------------------------------------------------------
346
- * * ***Normalizes a given pathname by ensuring consistent formatting.***
336
+ * * ***Utility: `normalizePathname`.***
347
337
  * --------------------------------------------------------
348
- *
349
- * @description
350
- * This function processes and normalizes a given pathname:
351
- *
352
- * - If `pathname` is `null`, `undefined`, empty, or only whitespace,
353
- * the `defaultPath` will be returned instead.
354
- *
355
- * - If `pathname` is a full URL (starting with `http://` or `https://`),
356
- * it extracts and returns the pathname along with any search parameters and hash.
357
- * Example: `"https://site.com/foo/bar?x=1#sec"` becomes `"/foo/bar?x=1#sec"`.
358
- *
359
- * - All spaces inside the pathname are removed.
360
- *
361
- * - Multiple consecutive slashes (like `"//"` or `"///"`) are collapsed into a single slash `"/"`.
362
- *
363
- * - Ensures the returned string always starts with exactly one `/`.
364
- *
338
+ * **This function processes and normalizes a given pathname.**
339
+ * - **Behavior:**
340
+ * - If `pathname` is `null`, `undefined`, empty, or only whitespace, the `defaultPath` will be returned instead.
341
+ * - If `pathname` is a full URL (starting with `http://` or `https://`), it extracts and returns the pathname along
342
+ * with any search parameters and hash.
343
+ * - Example: `"https://site.com/foo/bar?x=1#sec"` becomes `"/foo/bar?x=1#sec"`.
344
+ * - All spaces inside the pathname are removed.
345
+ * - Multiple consecutive slashes (like `"//"` or `"///"`) are collapsed into a single slash `"/"`.
346
+ * - Ensures the returned string always starts with exactly one `/`.
365
347
  * @param {string | null | undefined} pathname - The pathname to normalize.
366
- * @param {string} [defaultPath="/"] - A fallback value returned if `pathname` is empty or invalid. Must be a non-empty string, default `"/"`.
367
- *
348
+ * @param {string} [defaultPath="/"] - A fallback value returned if `pathname` is empty or invalid.
349
+ * - Must be a string and non-empty string, default `"/"`.
368
350
  * @returns {string} A properly normalized pathname starting with a single `/`,
369
351
  * or the `defaultPath` if the input is invalid or empty.
370
- *
371
- * @throws {TypeError} If `defaultPath` is not a non-empty string.
352
+ * @throws {TypeError} If `defaultPath` is not a string or empty-string.
372
353
  * @throws {NormalizePathnameError} If an unexpected error occurs during normalization (e.g., URL parsing failure).
373
- *
374
354
  * @example
375
355
  * normalizePathname(" /foo//bar ");
376
356
  * // ➔ "/foo/bar"
377
- *
378
357
  * normalizePathname("https://example.com//path///to/resource?x=1#hash");
379
358
  * // ➔ "/path/to/resource?x=1#hash"
380
359
  * normalizePathname(" ");
@@ -383,34 +362,32 @@ declare const getFirstPrefixPathname:(result?:string|string[]|null,defaultValue?
383
362
  * // ➔ "/home"
384
363
  * normalizePathname("/double//slashes");
385
364
  * // ➔ "/double/slashes"
386
- *` normalizePathname(" nested / path / 🚀 ");
365
+ * normalizePathname(" nested / path / 🚀 ");
387
366
  * // ➔ "/nested/path/🚀"
388
367
  */
389
- declare const normalizePathname:(pathname?:string|null,defaultPath?:string)=>string;
368
+ declare const normalizePathname:(pathname:string|null|undefined,defaultPath?:string)=>string;type FormatEnvPortOptions={
369
+ /** Add prefix with a colon, defaultValue: `false`.
370
+ *
371
+ * @default false
372
+ */
373
+ prefixColon?:boolean;};
390
374
  /** -----------------------------------------------
391
- * * ***Retrieves and formats an environment port variable.***
375
+ * * ***Utility: `formatEnvPort`.***
392
376
  * -----------------------------------------------
393
- *
394
- * - Extracts only digits from the input.
395
- * - If no digits found, returns an empty string.
396
- * - By default does NOT prefix with a colon.
397
- * Use `{ prefixColon: true }` to prefix with a colon.
398
- *
399
- * @param envVar The environment variable string.
400
- * @param options Optional object: `{ prefixColon?: boolean }`.
401
- * @returns A string like ":8080" or "8080", or "" if no digits.
402
- *
403
- * @throws TypeError if `options` is not an object or `prefixColon` is not boolean.
404
- *
377
+ * **Retrieves and formats an environment port variable.**
378
+ * - **Behavior:**
379
+ * - Extracts only digits from the input.
380
+ * - If no digits found, returns an empty string.
381
+ * - By default does NOT prefix with a colon.
382
+ * - Use `{ prefixColon: true }` to prefix with a colon.
383
+ * @param {string | null | undefined} envVar The environment variable string.
384
+ * @param {FormatEnvPortOptions} [options] Optional object: `{ prefixColon?: boolean }`.
385
+ * @returns {string} A string like `":8080"` or `"8080"`, or `""` if no digits.
386
+ * @throws {TypeError} If `options` is not an object or `prefixColon` is not boolean.
405
387
  * @example
406
388
  * formatEnvPort("port:8080");
407
389
  * // ➔ "8080"
408
390
  * formatEnvPort("port:8080", { prefixColon: true });
409
391
  * // ➔ ":8080"
410
392
  */
411
- declare const formatEnvPort:(envVar?:string|null,options?:{
412
- /** Add prefix with a colon.
413
- *
414
- * @default false
415
- */
416
- prefixColon?:boolean;})=>string;export{type QueryParamPairs,constructURL,extractURLs,formatEnvPort,getFirstPrefixPathname,getPrefixPathname,normalizePathname};
393
+ declare const formatEnvPort:(envVar:string|null|undefined,options?:FormatEnvPortOptions)=>string;export{type QueryParamPairs,constructURL,extractURLs,formatEnvPort,getFirstPrefixPathname,getPrefixPathname,normalizePathname};