@rzl-zone/utils-js 3.13.0-beta.2 → 3.13.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/.references/index.d.cts +1 -1
- package/dist/.references/index.d.ts +1 -1
- package/dist/{assertIsArray-6BcSdNa-.js → assertIsArray-C2rkhR9M.js} +3 -3
- package/dist/{assertIsArray-6BcSdNa-.js.map → assertIsArray-C2rkhR9M.js.map} +1 -1
- package/dist/{assertIsArray-BqjMoan3.cjs → assertIsArray-DWsgvahU.cjs} +3 -3
- package/dist/{assertIsArray-BqjMoan3.cjs.map → assertIsArray-DWsgvahU.cjs.map} +1 -1
- package/dist/{assertIsBoolean-amRiJHnh.cjs → assertIsBoolean-BKcvET7Z.cjs} +2 -2
- package/dist/{assertIsBoolean-amRiJHnh.cjs.map → assertIsBoolean-BKcvET7Z.cjs.map} +1 -1
- package/dist/{assertIsBoolean-Bv6gL-xe.js → assertIsBoolean-Clc7Vw4v.js} +2 -2
- package/dist/{assertIsBoolean-Bv6gL-xe.js.map → assertIsBoolean-Clc7Vw4v.js.map} +1 -1
- package/dist/{assertIsString-1WiUjgqf.js → assertIsString-Ddz4y81W.js} +3 -3
- package/dist/{assertIsString-1WiUjgqf.js.map → assertIsString-Ddz4y81W.js.map} +1 -1
- package/dist/{assertIsString-C0b28AU1.cjs → assertIsString-DxIqUfF1.cjs} +3 -3
- package/dist/{assertIsString-C0b28AU1.cjs.map → assertIsString-DxIqUfF1.cjs.map} +1 -1
- package/dist/assertions/index.cjs +5 -5
- package/dist/assertions/index.d.cts +2 -2
- package/dist/assertions/index.d.ts +2 -2
- package/dist/assertions/index.js +5 -5
- package/dist/conversions/index.cjs +6 -6
- package/dist/conversions/index.d.cts +2 -2
- package/dist/conversions/index.d.ts +2 -2
- package/dist/conversions/index.js +6 -6
- package/dist/{conversions-lvvAYiZs.cjs → conversions-Bu5c_RZ9.cjs} +12 -12
- package/dist/{conversions-lvvAYiZs.cjs.map → conversions-Bu5c_RZ9.cjs.map} +1 -1
- package/dist/{conversions-BrI0GIOr.js → conversions-DjfhrQE9.js} +12 -12
- package/dist/{conversions-BrI0GIOr.js.map → conversions-DjfhrQE9.js.map} +1 -1
- package/dist/events/index.cjs +4 -4
- package/dist/events/index.d.cts +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +4 -4
- package/dist/formatters/index.cjs +2 -2
- package/dist/formatters/index.d.cts +2 -2
- package/dist/formatters/index.d.ts +2 -2
- package/dist/formatters/index.js +2 -2
- package/dist/{formatters-zDzQvtb4.js → formatters-CidRTj87.js} +10 -10
- package/dist/{formatters-zDzQvtb4.js.map → formatters-CidRTj87.js.map} +1 -1
- package/dist/{formatters-DQr05EUA.cjs → formatters-DF4887ia.cjs} +10 -10
- package/dist/{formatters-DQr05EUA.cjs.map → formatters-DF4887ia.cjs.map} +1 -1
- package/dist/generators/index.cjs +5 -5
- package/dist/generators/index.d.cts +2 -2
- package/dist/generators/index.d.ts +2 -2
- package/dist/generators/index.js +5 -5
- package/dist/{index-Ckao53JY.d.ts → index-BK86Fnvd.d.ts} +2 -2
- package/dist/{index-DxZlGbAH.d.ts → index-BZMwAuLf.d.ts} +1 -1
- package/dist/{index-BXwimNPA.d.cts → index-BbCX319b.d.cts} +2 -2
- package/dist/{index-GSUN6rjA.d.ts → index-C02XatNH.d.ts} +2 -2
- package/dist/{index-3jBnthag.d.cts → index-CHwf6vUh.d.ts} +1 -1
- package/dist/{index-DIeR8qa-.d.ts → index-CIBhF2hQ.d.cts} +1 -1
- package/dist/{index-CLq5kZmQ.d.cts → index-CWgiyaU3.d.cts} +2 -2
- package/dist/{index-z_uCh5KW.d.cts → index-CX8gCrW8.d.ts} +3 -3
- package/dist/{index-_dJhBl1h.d.ts → index-CyZz4BHD.d.cts} +1 -1
- package/dist/{index-DHHrLc0B.d.ts → index-Cyu3Mh3N.d.cts} +3 -3
- package/dist/{index-bMa-0Yr4.d.cts → index-DC7eXTo_.d.cts} +1 -1
- package/dist/{index-DyVWeYP3.d.cts → index-DPBypj6v.d.ts} +1 -1
- package/dist/{index-BlTCrSyc.d.cts → index-Dq5vUFfH.d.ts} +2 -2
- package/dist/{index-CEm8ZOvj.d.ts → index-YeyLvCAr.d.cts} +2 -2
- package/dist/{isBigInt-CIFRnsdx.cjs → isBigInt-BePsmNsm.cjs} +2 -2
- package/dist/{isBigInt-CIFRnsdx.cjs.map → isBigInt-BePsmNsm.cjs.map} +1 -1
- package/dist/{isBigInt-D-Pu9sxp.js → isBigInt-Cx4j_cju.js} +2 -2
- package/dist/{isBigInt-D-Pu9sxp.js.map → isBigInt-Cx4j_cju.js.map} +1 -1
- package/dist/{isEmptyObject-CEySmyHK.cjs → isEmptyObject-DYypq92-.cjs} +3 -3
- package/dist/{isEmptyObject-CEySmyHK.cjs.map → isEmptyObject-DYypq92-.cjs.map} +1 -1
- package/dist/{isEmptyObject-CZ9DLi7R.js → isEmptyObject-Dp4pCGTa.js} +3 -3
- package/dist/{isEmptyObject-CZ9DLi7R.js.map → isEmptyObject-Dp4pCGTa.js.map} +1 -1
- package/dist/{isEmptyString-DFDtBbNr.js → isEmptyString-BXgKFQxw.js} +3 -3
- package/dist/{isEmptyString-DFDtBbNr.js.map → isEmptyString-BXgKFQxw.js.map} +1 -1
- package/dist/{isEmptyString-DI64RQCy.cjs → isEmptyString-CzY-9G-x.cjs} +3 -3
- package/dist/{isEmptyString-DI64RQCy.cjs.map → isEmptyString-CzY-9G-x.cjs.map} +1 -1
- package/dist/{isEmptyValue-aGyeClwA.js → isEmptyValue-B7Zd9DI3.js} +5 -5
- package/dist/{isEmptyValue-aGyeClwA.js.map → isEmptyValue-B7Zd9DI3.js.map} +1 -1
- package/dist/{isEmptyValue-Cw6ovu7z.cjs → isEmptyValue-Ci3kVU4E.cjs} +5 -5
- package/dist/{isEmptyValue-Cw6ovu7z.cjs.map → isEmptyValue-Ci3kVU4E.cjs.map} +1 -1
- package/dist/{isEqual-UsvOwrlY.cjs → isEqual-Bd7mClU4.cjs} +4 -4
- package/dist/{isEqual-UsvOwrlY.cjs.map → isEqual-Bd7mClU4.cjs.map} +1 -1
- package/dist/{isEqual-Dtb2sXUv.js → isEqual-CylDBGUr.js} +4 -4
- package/dist/{isEqual-Dtb2sXUv.js.map → isEqual-CylDBGUr.js.map} +1 -1
- package/dist/{isFinite-Cz_IFXuV.js → isFinite-CZ-Aiy4T.js} +3 -3
- package/dist/{isFinite-Cz_IFXuV.js.map → isFinite-CZ-Aiy4T.js.map} +1 -1
- package/dist/{isFinite-uukWvxJh.cjs → isFinite-D8jhlqPf.cjs} +3 -3
- package/dist/{isFinite-uukWvxJh.cjs.map → isFinite-D8jhlqPf.cjs.map} +1 -1
- package/dist/{isInteger-DPYjliLZ.cjs → isInteger-CCJhQ1Mx.cjs} +2 -2
- package/dist/{isInteger-DPYjliLZ.cjs.map → isInteger-CCJhQ1Mx.cjs.map} +1 -1
- package/dist/{isInteger-DZ163OQg.js → isInteger-DK_0nvNU.js} +2 -2
- package/dist/{isInteger-DZ163OQg.js.map → isInteger-DK_0nvNU.js.map} +1 -1
- package/dist/{isPlainObject-CBABRyEX.d.cts → isPlainObject-BGg8uHeL.d.cts} +1 -1
- package/dist/{isPlainObject-Dr8gi89U.d.ts → isPlainObject-DtduwtUp.d.ts} +1 -1
- package/dist/{isServer-BDShLyVJ.js → isServer-C2YtJlD1.js} +2 -2
- package/dist/{isServer-BDShLyVJ.js.map → isServer-C2YtJlD1.js.map} +1 -1
- package/dist/{isServer-BzDeYuGg.cjs → isServer-CT9EkFKG.cjs} +2 -2
- package/dist/{isServer-BzDeYuGg.cjs.map → isServer-CT9EkFKG.cjs.map} +1 -1
- package/dist/{isTypedArray-DaYAkyrt.cjs → isTypedArray-BT7YP1S9.cjs} +3 -3
- package/dist/{isTypedArray-DaYAkyrt.cjs.map → isTypedArray-BT7YP1S9.cjs.map} +1 -1
- package/dist/{isTypedArray-DuUUA4CL.js → isTypedArray-hcngU0pK.js} +3 -3
- package/dist/{isTypedArray-DuUUA4CL.js.map → isTypedArray-hcngU0pK.js.map} +1 -1
- package/dist/{isValidDomain-CTw5vZFY.js → isValidDomain-BCN5-tj9.js} +5 -5
- package/dist/{isValidDomain-CTw5vZFY.js.map → isValidDomain-BCN5-tj9.js.map} +1 -1
- package/dist/{isValidDomain-BxyToAlh.cjs → isValidDomain-CXWNcRo6.cjs} +5 -5
- package/dist/{isValidDomain-BxyToAlh.cjs.map → isValidDomain-CXWNcRo6.cjs.map} +1 -1
- package/dist/{noop-DGg9vMSD.js → noop-BDfC9Zq4.js} +2 -2
- package/dist/{noop-DGg9vMSD.js.map → noop-BDfC9Zq4.js.map} +1 -1
- package/dist/{noop-7KrqC9DC.cjs → noop-D4tT7tWN.cjs} +2 -2
- package/dist/{noop-7KrqC9DC.cjs.map → noop-D4tT7tWN.cjs.map} +1 -1
- package/dist/{normalizeSpaces-C1eLwykD.js → normalizeSpaces-B289eKyK.js} +3 -3
- package/dist/{normalizeSpaces-C1eLwykD.js.map → normalizeSpaces-B289eKyK.js.map} +1 -1
- package/dist/{normalizeSpaces-B6ZQOZRX.cjs → normalizeSpaces-BTXDP8vZ.cjs} +3 -3
- package/dist/{normalizeSpaces-B6ZQOZRX.cjs.map → normalizeSpaces-BTXDP8vZ.cjs.map} +1 -1
- package/dist/operations/index.cjs +7 -7
- package/dist/operations/index.d.cts +1 -1
- package/dist/operations/index.d.ts +1 -1
- package/dist/operations/index.js +7 -7
- package/dist/parsers/index.cjs +2 -2
- package/dist/parsers/index.d.cts +1 -1
- package/dist/parsers/index.d.ts +1 -1
- package/dist/parsers/index.js +2 -2
- package/dist/{parsers-DEFpCYhw.cjs → parsers-5G1Lface.cjs} +4 -4
- package/dist/{parsers-DEFpCYhw.cjs.map → parsers-5G1Lface.cjs.map} +1 -1
- package/dist/{parsers-bQQ9mStV.js → parsers-CNag9LsX.js} +4 -4
- package/dist/{parsers-bQQ9mStV.js.map → parsers-CNag9LsX.js.map} +1 -1
- package/dist/{parsing-lI5EN4LY.cjs → parsing-B6vxp2h8.cjs} +3 -3
- package/dist/{parsing-lI5EN4LY.cjs.map → parsing-B6vxp2h8.cjs.map} +1 -1
- package/dist/{parsing-BngARhmu.js → parsing-CobzHooQ.js} +3 -3
- package/dist/{parsing-BngARhmu.js.map → parsing-CobzHooQ.js.map} +1 -1
- package/dist/predicates/index.cjs +14 -14
- package/dist/predicates/index.d.cts +3 -3
- package/dist/predicates/index.d.ts +3 -3
- package/dist/predicates/index.js +14 -14
- package/dist/{predicates-CMmP3fPJ.cjs → predicates-DlID4Pks.cjs} +11 -11
- package/dist/{predicates-CMmP3fPJ.cjs.map → predicates-DlID4Pks.cjs.map} +1 -1
- package/dist/{predicates-V87QD8hs.js → predicates-DvLryz_b.js} +11 -11
- package/dist/{predicates-V87QD8hs.js.map → predicates-DvLryz_b.js.map} +1 -1
- package/dist/promises/index.cjs +4 -4
- package/dist/promises/index.d.cts +1 -1
- package/dist/promises/index.d.ts +1 -1
- package/dist/promises/index.js +4 -4
- package/dist/{punyCode-DmTsB7q_.cjs → punyCode-DaBFrfga.cjs} +4 -4
- package/dist/{punyCode-DmTsB7q_.cjs.map → punyCode-DaBFrfga.cjs.map} +1 -1
- package/dist/{punyCode-BeFYDjj0.js → punyCode-GakZYPCT.js} +4 -4
- package/dist/{punyCode-BeFYDjj0.js.map → punyCode-GakZYPCT.js.map} +1 -1
- package/dist/{removeSpaces-B96axxP6.js → removeSpaces-BJ-zNnJq.js} +3 -3
- package/dist/{removeSpaces-B96axxP6.js.map → removeSpaces-BJ-zNnJq.js.map} +1 -1
- package/dist/{removeSpaces-C8mu_yp3.cjs → removeSpaces-DhJ1haaH.cjs} +3 -3
- package/dist/{removeSpaces-C8mu_yp3.cjs.map → removeSpaces-DhJ1haaH.cjs.map} +1 -1
- package/dist/rzl-utils.global.js +1 -1
- package/dist/{safeJsonParse-BXbtX_j7.cjs → safeJsonParse-DiWBPfaE.cjs} +6 -6
- package/dist/{safeJsonParse-BXbtX_j7.cjs.map → safeJsonParse-DiWBPfaE.cjs.map} +1 -1
- package/dist/{safeJsonParse-DyCsTXlU.js → safeJsonParse-bcBYPjeb.js} +6 -6
- package/dist/{safeJsonParse-DyCsTXlU.js.map → safeJsonParse-bcBYPjeb.js.map} +1 -1
- package/dist/{safeStableStringify-BrOcdX9n.js → safeStableStringify-C1SA52w7.js} +4 -4
- package/dist/{safeStableStringify-BrOcdX9n.js.map → safeStableStringify-C1SA52w7.js.map} +1 -1
- package/dist/{safeStableStringify-DRYQ56Dg.cjs → safeStableStringify-DSwcrPll.cjs} +4 -4
- package/dist/{safeStableStringify-DRYQ56Dg.cjs.map → safeStableStringify-DSwcrPll.cjs.map} +1 -1
- package/dist/strings/index.cjs +5 -5
- package/dist/strings/index.d.cts +2 -2
- package/dist/strings/index.d.ts +2 -2
- package/dist/strings/index.js +5 -5
- package/dist/tailwind/index.cjs +2 -2
- package/dist/tailwind/index.d.cts +2 -2
- package/dist/tailwind/index.d.ts +2 -2
- package/dist/tailwind/index.js +2 -2
- package/dist/{tailwind-BZ2_MeNX.js → tailwind-D62asDBR.js} +5 -5
- package/dist/{tailwind-BZ2_MeNX.js.map → tailwind-D62asDBR.js.map} +1 -1
- package/dist/{tailwind-C1YtxJ-K.cjs → tailwind-DMPTwJ0X.cjs} +5 -5
- package/dist/{tailwind-C1YtxJ-K.cjs.map → tailwind-DMPTwJ0X.cjs.map} +1 -1
- package/dist/{toStringArrayUnRecursive-tHp2a7KR.js → toStringArrayUnRecursive-DBicbWv8.js} +6 -6
- package/dist/{toStringArrayUnRecursive-tHp2a7KR.js.map → toStringArrayUnRecursive-DBicbWv8.js.map} +1 -1
- package/dist/{toStringArrayUnRecursive-D1mPM4wg.cjs → toStringArrayUnRecursive-DJ8JBO3N.cjs} +6 -6
- package/dist/{toStringArrayUnRecursive-D1mPM4wg.cjs.map → toStringArrayUnRecursive-DJ8JBO3N.cjs.map} +1 -1
- package/dist/urls/index.cjs +3 -3
- package/dist/urls/index.d.cts +1 -1
- package/dist/urls/index.d.ts +1 -1
- package/dist/urls/index.js +3 -3
- package/dist/{urls-DCyx8Wpk.cjs → urls-DCjjZNTH.cjs} +11 -11
- package/dist/{urls-DCyx8Wpk.cjs.map → urls-DCjjZNTH.cjs.map} +1 -1
- package/dist/{urls-CoxDAoki.js → urls-DTndjYDD.js} +11 -11
- package/dist/{urls-CoxDAoki.js.map → urls-DTndjYDD.js.map} +1 -1
- package/package.json +1 -1
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
|
-
import { E as isNull, F as isBoolean, M as isArray, N as isNil, T as assertIsPlainObject, b as hasOwnProp, k as isString, t as assertIsBoolean } from "./assertIsBoolean-
|
|
11
|
-
import { t as isBigInt } from "./isBigInt-
|
|
12
|
-
import { n as isEmptyArray } from "./isEmptyObject-
|
|
13
|
-
import { t as isFinite } from "./isFinite-
|
|
10
|
+
import { E as isNull, F as isBoolean, M as isArray, N as isNil, T as assertIsPlainObject, b as hasOwnProp, k as isString, t as assertIsBoolean } from "./assertIsBoolean-Clc7Vw4v.js";
|
|
11
|
+
import { t as isBigInt } from "./isBigInt-Cx4j_cju.js";
|
|
12
|
+
import { n as isEmptyArray } from "./isEmptyObject-Dp4pCGTa.js";
|
|
13
|
+
import { t as isFinite } from "./isFinite-CZ-Aiy4T.js";
|
|
14
14
|
function filterNilArray(input) {
|
|
15
15
|
if (isNil(input)) return void 0;
|
|
16
16
|
if (!isArray(input)) return [];
|
|
@@ -36,4 +36,4 @@ function toStringArrayUnRecursive(array, options = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export { filterNilArray as n, toStringArrayUnRecursive as t };
|
|
39
|
-
//# sourceMappingURL=toStringArrayUnRecursive-
|
|
39
|
+
//# sourceMappingURL=toStringArrayUnRecursive-DBicbWv8.js.map
|
package/dist/{toStringArrayUnRecursive-tHp2a7KR.js.map → toStringArrayUnRecursive-DBicbWv8.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toStringArrayUnRecursive-
|
|
1
|
+
{"version":3,"file":"toStringArrayUnRecursive-DBicbWv8.js","names":[],"sources":["../src/conversions/arrays/transforms/filterNilArray.ts","../src/conversions/arrays/casts/toStringArrayUnRecursive.ts"],"sourcesContent":["import type {\n FilterNilArray,\n FilterNilArrayFromTuple,\n PreserveMutability\n} from \"./_private/filterNilArray.types\";\n\nimport { isNil } from \"@/predicates/is/isNil\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isEmptyArray } from \"@/predicates/is/isEmptyArray\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `filterNilArray`.***\n * ---------------------------------------------\n * **Removes `null` and `undefined` values from an array, including nested arrays.**\n * - **Behavior:**\n * - Returns `undefined` if the input is explicitly `undefined` or `null`.\n * - Returns `[]` if input is empty or all elements are removed after filtering.\n * - Recursively filters nested arrays while preserving structure.\n * - Ensures proper type inference for safer downstream operations.\n * @template A - The type of elements in the array.\n * @param {T[]|null|undefined} input - The array to be filtered.\n * @returns {T[] | undefined} A new array with `null` and `undefined` values removed,\n * or `undefined` if the input is explicitly `undefined` or `null`.\n * @example\n * ```ts\n * filterNilArray([1, null, 2, undefined, 3]);\n * // ➔ [1, 2, 3]\n * filterNilArray([null, undefined]);\n * // ➔ []\n * filterNilArray(undefined);\n * // ➔ undefined\n * filterNilArray(null);\n * // ➔ undefined\n * filterNilArray([]); // or\n * filterNilArray([[[]]]); // or\n * filterNilArray([[[],undefined,null]]);\n * // ➔ []\n * filterNilArray([1, [null, 2, [undefined, 3]]]);\n * // ➔ [1, [2, [3]]]\n * ```\n */\nexport function filterNilArray(input: null | undefined): undefined;\nexport function filterNilArray<A extends readonly unknown[]>(\n input: A\n): PreserveMutability<A, FilterNilArrayFromTuple<A>>;\nexport function filterNilArray<A extends readonly unknown[]>(\n input: A | null | undefined\n): PreserveMutability<A, FilterNilArrayFromTuple<A>> | undefined;\nexport function filterNilArray<A>(\n input: (A | null | undefined)[] | null | undefined\n): FilterNilArray<A> | undefined;\nexport function filterNilArray(\n input: readonly unknown[] | null | undefined\n): unknown[] | undefined;\nexport function filterNilArray(input: unknown[]): unknown[];\nexport function filterNilArray(input: unknown): unknown {\n if (isNil(input)) return undefined;\n if (!isArray(input)) return [];\n\n const filtered = input.reduce<unknown[]>((output, element) => {\n if (!isNil(element)) {\n if (isArray(element)) {\n const cleanedNested = filterNilArray(element);\n if (cleanedNested && !isEmptyArray(cleanedNested)) {\n output.push(cleanedNested);\n }\n } else {\n output.push(element);\n }\n }\n return output;\n }, []);\n\n return filtered;\n}\n","import type {\n ToStringArrayUnRecursiveOptions,\n ToStringArrayUnRecursiveReturn\n} from \"./toStringArrayUnRecursive.types\";\n\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isFinite } from \"@/predicates/is/isFinite\";\nimport { isBigInt } from \"@/predicates/is/isBigInt\";\nimport { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { hasOwnProp } from \"@/predicates/has/hasOwnProp\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\nimport { filterNilArray } from \"../transforms/filterNilArray\";\n\n/** ---------------------------------------------\n * * ***Utility: `toStringArrayUnRecursive`.***\n * ---------------------------------------------\n * **Converts all values in a flat array into string representations.**\n * - **Behavior:**\n * - Only processes **flat arrays** (non-recursive).\n * - Supports input values: `string`, `number`, `bigint`, `boolean`,\n * `null`, `undefined`.\n * - Invalid values (`null` and `undefined`) can be **removed** or **kept**\n * depending on the option.\n * - Other unsupported types will be converted to `undefined` (and removed\n * if `removeInvalidValue=true`).\n * - **ℹ️ Note:**\n * - _For recursive / nested arrays, use ***`toStringDeep` utility function*** instead._\n * @template T - Element type of the input array.\n * @template R - Whether invalid values should be removed (`true`) or kept (`false`).\n * @param {Array<string | number | bigint | boolean | null | undefined> | null | undefined} [array] - The array to convert, returns `undefined` if not an array.\n * @param {ToStringArrayUnRecursiveOptions<RemoveInvalidValue>} [options] - Options to control transformation behavior, defaults to `{ removeInvalidValue: true }`.\n * @param {RemoveInvalidValue extends true ? boolean : boolean} [options.removeInvalidValue=true] Whether to remove invalid values (`null`, `undefined`, or unsupported types), default: `true`.\n * @returns {RemoveInvalidValue extends true ? string[] : (string | null | undefined)[]} A new array of string representations, with invalid values optionally removed.\n * @example\n * ```ts\n * // Convert numbers and strings\n * toStringArrayUnRecursive([1, 2, '3']);\n * // ➔ ['1', '2', '3']\n * // Remove null and undefined\n * toStringArrayUnRecursive([1, null, undefined, 'abc'], {\n * removeInvalidValue: true\n * });\n * // ➔ ['1', 'abc']\n * // Keep null and undefined\n * toStringArrayUnRecursive([1, null, undefined, 'abc'], {\n * removeInvalidValue: false\n * });\n * // ➔ ['1', null, undefined, 'abc']\n * // Convert boolean and bigint\n * toStringArrayUnRecursive([true, false, 10n]);\n * // ➔ ['true', 'false', '10']\n * // Not an array ➔ returns undefined\n * toStringArrayUnRecursive(null);\n * // ➔ undefined\n * toStringArrayUnRecursive(undefined);\n * // ➔ undefined\n * toStringArrayUnRecursive(1);\n * // ➔ undefined\n * toStringArrayUnRecursive(\"string\");\n * // ➔ undefined\n * ```\n */\nexport function toStringArrayUnRecursive(\n array?: undefined | null,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): undefined;\nexport function toStringArrayUnRecursive(\n array?: Array<never>,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): [];\nexport function toStringArrayUnRecursive<T, R extends boolean = true>(\n array?: Array<T> | readonly T[] | null,\n options?: ToStringArrayUnRecursiveOptions<R>\n): ToStringArrayUnRecursiveReturn<T, R>;\nexport function toStringArrayUnRecursive<T = unknown>(\n array?: T,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): undefined;\nexport function toStringArrayUnRecursive<T>(\n array?: Array<T> | readonly T[] | null,\n options: ToStringArrayUnRecursiveOptions<boolean> = {}\n) {\n assertIsPlainObject(options, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const riv = hasOwnProp(options, \"removeInvalidValue\")\n ? options.removeInvalidValue\n : true;\n\n assertIsBoolean(riv, {\n message: ({ currentType, validType }) =>\n `Parameter \\`removeInvalidValue\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n if (isArray(array)) {\n // Convert each item in the array to a string, or null/undefined if it's not a valid value.\n const result = Array.from(array, (x) => {\n // Convert finite number, boolean, bigInt or string to string\n if (isString(x) || isFinite(x) || isBoolean(x) || isBigInt(x))\n return String(x);\n\n // Handle null or undefined values\n return isNull(x) ? null : undefined;\n });\n\n // Remove invalid values (null, undefined) if specified in options\n if (riv) return filterNilArray(result);\n\n return result;\n }\n\n // Return undefined if no array is provided\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuDA,SAAgB,eAAe,OAAyB;CACtD,IAAI,MAAM,MAAM,EAAE,OAAO;CACzB,IAAI,CAAC,QAAQ,MAAM,EAAE,OAAO,EAAE;CAgB9B,OAdiB,MAAM,QAAmB,QAAQ,YAAY;EAC5D,IAAI,CAAC,MAAM,QAAQ,EACjB,IAAI,QAAQ,QAAQ,EAAE;GACpB,MAAM,gBAAgB,eAAe,QAAQ;GAC7C,IAAI,iBAAiB,CAAC,aAAa,cAAc,EAC/C,OAAO,KAAK,cAAc;SAG5B,OAAO,KAAK,QAAQ;EAGxB,OAAO;IACN,EAAE,CAEU;;;;;ACSjB,SAAgB,yBACd,OACA,UAAoD,EAAE,EACtD;CACA,oBAAoB,SAAS,EAC3B,UAAU,EAAE,aAAa,gBACvB,oDAAoD,UAAU,sBAAsB,YAAY,MACnG,CAAC;CAEF,MAAM,MAAM,WAAW,SAAS,qBAAqB,GACjD,QAAQ,qBACR;CAEJ,gBAAgB,KAAK,EACnB,UAAU,EAAE,aAAa,gBACvB,qGAAqG,UAAU,sBAAsB,YAAY,MACpJ,CAAC;CAEF,IAAI,QAAQ,MAAM,EAAE;EAElB,MAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;GAEtC,IAAI,SAAS,EAAE,IAAI,SAAS,EAAE,IAAI,UAAU,EAAE,IAAI,SAAS,EAAE,EAC3D,OAAO,OAAO,EAAE;GAGlB,OAAO,OAAO,EAAE,GAAG,OAAO;IAC1B;EAGF,IAAI,KAAK,OAAO,eAAe,OAAO;EAEtC,OAAO"}
|
package/dist/{toStringArrayUnRecursive-D1mPM4wg.cjs → toStringArrayUnRecursive-DJ8JBO3N.cjs}
RENAMED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
|
-
const require_assertIsBoolean = require('./assertIsBoolean-
|
|
12
|
-
const require_isBigInt = require('./isBigInt-
|
|
13
|
-
const require_isEmptyObject = require('./isEmptyObject-
|
|
14
|
-
const require_isFinite = require('./isFinite-
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-BKcvET7Z.cjs');
|
|
12
|
+
const require_isBigInt = require('./isBigInt-BePsmNsm.cjs');
|
|
13
|
+
const require_isEmptyObject = require('./isEmptyObject-DYypq92-.cjs');
|
|
14
|
+
const require_isFinite = require('./isFinite-D8jhlqPf.cjs');
|
|
15
15
|
function filterNilArray(input) {
|
|
16
16
|
if (require_assertIsBoolean.isNil(input)) return void 0;
|
|
17
17
|
if (!require_assertIsBoolean.isArray(input)) return [];
|
|
@@ -48,4 +48,4 @@ Object.defineProperty(exports, 'toStringArrayUnRecursive', {
|
|
|
48
48
|
return toStringArrayUnRecursive;
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
//# sourceMappingURL=toStringArrayUnRecursive-
|
|
51
|
+
//# sourceMappingURL=toStringArrayUnRecursive-DJ8JBO3N.cjs.map
|
package/dist/{toStringArrayUnRecursive-D1mPM4wg.cjs.map → toStringArrayUnRecursive-DJ8JBO3N.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toStringArrayUnRecursive-
|
|
1
|
+
{"version":3,"file":"toStringArrayUnRecursive-DJ8JBO3N.cjs","names":["isNil","isArray","isEmptyArray","hasOwnProp","isArray","isString","isFinite","isBoolean","isBigInt","isNull"],"sources":["../src/conversions/arrays/transforms/filterNilArray.ts","../src/conversions/arrays/casts/toStringArrayUnRecursive.ts"],"sourcesContent":["import type {\n FilterNilArray,\n FilterNilArrayFromTuple,\n PreserveMutability\n} from \"./_private/filterNilArray.types\";\n\nimport { isNil } from \"@/predicates/is/isNil\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isEmptyArray } from \"@/predicates/is/isEmptyArray\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `filterNilArray`.***\n * ---------------------------------------------\n * **Removes `null` and `undefined` values from an array, including nested arrays.**\n * - **Behavior:**\n * - Returns `undefined` if the input is explicitly `undefined` or `null`.\n * - Returns `[]` if input is empty or all elements are removed after filtering.\n * - Recursively filters nested arrays while preserving structure.\n * - Ensures proper type inference for safer downstream operations.\n * @template A - The type of elements in the array.\n * @param {T[]|null|undefined} input - The array to be filtered.\n * @returns {T[] | undefined} A new array with `null` and `undefined` values removed,\n * or `undefined` if the input is explicitly `undefined` or `null`.\n * @example\n * ```ts\n * filterNilArray([1, null, 2, undefined, 3]);\n * // ➔ [1, 2, 3]\n * filterNilArray([null, undefined]);\n * // ➔ []\n * filterNilArray(undefined);\n * // ➔ undefined\n * filterNilArray(null);\n * // ➔ undefined\n * filterNilArray([]); // or\n * filterNilArray([[[]]]); // or\n * filterNilArray([[[],undefined,null]]);\n * // ➔ []\n * filterNilArray([1, [null, 2, [undefined, 3]]]);\n * // ➔ [1, [2, [3]]]\n * ```\n */\nexport function filterNilArray(input: null | undefined): undefined;\nexport function filterNilArray<A extends readonly unknown[]>(\n input: A\n): PreserveMutability<A, FilterNilArrayFromTuple<A>>;\nexport function filterNilArray<A extends readonly unknown[]>(\n input: A | null | undefined\n): PreserveMutability<A, FilterNilArrayFromTuple<A>> | undefined;\nexport function filterNilArray<A>(\n input: (A | null | undefined)[] | null | undefined\n): FilterNilArray<A> | undefined;\nexport function filterNilArray(\n input: readonly unknown[] | null | undefined\n): unknown[] | undefined;\nexport function filterNilArray(input: unknown[]): unknown[];\nexport function filterNilArray(input: unknown): unknown {\n if (isNil(input)) return undefined;\n if (!isArray(input)) return [];\n\n const filtered = input.reduce<unknown[]>((output, element) => {\n if (!isNil(element)) {\n if (isArray(element)) {\n const cleanedNested = filterNilArray(element);\n if (cleanedNested && !isEmptyArray(cleanedNested)) {\n output.push(cleanedNested);\n }\n } else {\n output.push(element);\n }\n }\n return output;\n }, []);\n\n return filtered;\n}\n","import type {\n ToStringArrayUnRecursiveOptions,\n ToStringArrayUnRecursiveReturn\n} from \"./toStringArrayUnRecursive.types\";\n\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isFinite } from \"@/predicates/is/isFinite\";\nimport { isBigInt } from \"@/predicates/is/isBigInt\";\nimport { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { hasOwnProp } from \"@/predicates/has/hasOwnProp\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\nimport { filterNilArray } from \"../transforms/filterNilArray\";\n\n/** ---------------------------------------------\n * * ***Utility: `toStringArrayUnRecursive`.***\n * ---------------------------------------------\n * **Converts all values in a flat array into string representations.**\n * - **Behavior:**\n * - Only processes **flat arrays** (non-recursive).\n * - Supports input values: `string`, `number`, `bigint`, `boolean`,\n * `null`, `undefined`.\n * - Invalid values (`null` and `undefined`) can be **removed** or **kept**\n * depending on the option.\n * - Other unsupported types will be converted to `undefined` (and removed\n * if `removeInvalidValue=true`).\n * - **ℹ️ Note:**\n * - _For recursive / nested arrays, use ***`toStringDeep` utility function*** instead._\n * @template T - Element type of the input array.\n * @template R - Whether invalid values should be removed (`true`) or kept (`false`).\n * @param {Array<string | number | bigint | boolean | null | undefined> | null | undefined} [array] - The array to convert, returns `undefined` if not an array.\n * @param {ToStringArrayUnRecursiveOptions<RemoveInvalidValue>} [options] - Options to control transformation behavior, defaults to `{ removeInvalidValue: true }`.\n * @param {RemoveInvalidValue extends true ? boolean : boolean} [options.removeInvalidValue=true] Whether to remove invalid values (`null`, `undefined`, or unsupported types), default: `true`.\n * @returns {RemoveInvalidValue extends true ? string[] : (string | null | undefined)[]} A new array of string representations, with invalid values optionally removed.\n * @example\n * ```ts\n * // Convert numbers and strings\n * toStringArrayUnRecursive([1, 2, '3']);\n * // ➔ ['1', '2', '3']\n * // Remove null and undefined\n * toStringArrayUnRecursive([1, null, undefined, 'abc'], {\n * removeInvalidValue: true\n * });\n * // ➔ ['1', 'abc']\n * // Keep null and undefined\n * toStringArrayUnRecursive([1, null, undefined, 'abc'], {\n * removeInvalidValue: false\n * });\n * // ➔ ['1', null, undefined, 'abc']\n * // Convert boolean and bigint\n * toStringArrayUnRecursive([true, false, 10n]);\n * // ➔ ['true', 'false', '10']\n * // Not an array ➔ returns undefined\n * toStringArrayUnRecursive(null);\n * // ➔ undefined\n * toStringArrayUnRecursive(undefined);\n * // ➔ undefined\n * toStringArrayUnRecursive(1);\n * // ➔ undefined\n * toStringArrayUnRecursive(\"string\");\n * // ➔ undefined\n * ```\n */\nexport function toStringArrayUnRecursive(\n array?: undefined | null,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): undefined;\nexport function toStringArrayUnRecursive(\n array?: Array<never>,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): [];\nexport function toStringArrayUnRecursive<T, R extends boolean = true>(\n array?: Array<T> | readonly T[] | null,\n options?: ToStringArrayUnRecursiveOptions<R>\n): ToStringArrayUnRecursiveReturn<T, R>;\nexport function toStringArrayUnRecursive<T = unknown>(\n array?: T,\n options?: ToStringArrayUnRecursiveOptions<boolean>\n): undefined;\nexport function toStringArrayUnRecursive<T>(\n array?: Array<T> | readonly T[] | null,\n options: ToStringArrayUnRecursiveOptions<boolean> = {}\n) {\n assertIsPlainObject(options, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const riv = hasOwnProp(options, \"removeInvalidValue\")\n ? options.removeInvalidValue\n : true;\n\n assertIsBoolean(riv, {\n message: ({ currentType, validType }) =>\n `Parameter \\`removeInvalidValue\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n if (isArray(array)) {\n // Convert each item in the array to a string, or null/undefined if it's not a valid value.\n const result = Array.from(array, (x) => {\n // Convert finite number, boolean, bigInt or string to string\n if (isString(x) || isFinite(x) || isBoolean(x) || isBigInt(x))\n return String(x);\n\n // Handle null or undefined values\n return isNull(x) ? null : undefined;\n });\n\n // Remove invalid values (null, undefined) if specified in options\n if (riv) return filterNilArray(result);\n\n return result;\n }\n\n // Return undefined if no array is provided\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuDA,SAAgB,eAAe,OAAyB;CACtD,IAAIA,8BAAM,MAAM,EAAE,OAAO;CACzB,IAAI,CAACC,gCAAQ,MAAM,EAAE,OAAO,EAAE;CAgB9B,OAdiB,MAAM,QAAmB,QAAQ,YAAY;EAC5D,IAAI,CAACD,8BAAM,QAAQ,EACjB,IAAIC,gCAAQ,QAAQ,EAAE;GACpB,MAAM,gBAAgB,eAAe,QAAQ;GAC7C,IAAI,iBAAiB,CAACC,mCAAa,cAAc,EAC/C,OAAO,KAAK,cAAc;SAG5B,OAAO,KAAK,QAAQ;EAGxB,OAAO;IACN,EAAE,CAEU;;;;;ACSjB,SAAgB,yBACd,OACA,UAAoD,EAAE,EACtD;CACA,4CAAoB,SAAS,EAC3B,UAAU,EAAE,aAAa,gBACvB,oDAAoD,UAAU,sBAAsB,YAAY,MACnG,CAAC;CAEF,MAAM,MAAMC,mCAAW,SAAS,qBAAqB,GACjD,QAAQ,qBACR;CAEJ,wCAAgB,KAAK,EACnB,UAAU,EAAE,aAAa,gBACvB,qGAAqG,UAAU,sBAAsB,YAAY,MACpJ,CAAC;CAEF,IAAIC,gCAAQ,MAAM,EAAE;EAElB,MAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;GAEtC,IAAIC,iCAAS,EAAE,IAAIC,0BAAS,EAAE,IAAIC,kCAAU,EAAE,IAAIC,0BAAS,EAAE,EAC3D,OAAO,OAAO,EAAE;GAGlB,OAAOC,+BAAO,EAAE,GAAG,OAAO;IAC1B;EAGF,IAAI,KAAK,OAAO,eAAe,OAAO;EAEtC,OAAO"}
|
package/dist/urls/index.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
12
|
-
const require_punyCode = require('../punyCode-
|
|
13
|
-
const require_urls = require('../urls-
|
|
12
|
+
const require_punyCode = require('../punyCode-DaBFrfga.cjs');
|
|
13
|
+
const require_urls = require('../urls-DCjjZNTH.cjs');
|
|
14
14
|
exports.constructURL = require_urls.constructURL;
|
|
15
15
|
exports.extractURLs = require_urls.extractURLs;
|
|
16
16
|
exports.formatEnvPort = require_urls.formatEnvPort;
|
package/dist/urls/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
package/dist/urls/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
package/dist/urls/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
|
-
import { t as punycodeUtilsJS } from "../punyCode-
|
|
11
|
-
import { a as extractURLs, i as normalizePathname, n as getPrefixPathname, o as constructURL, r as getFirstPrefixPathname, t as formatEnvPort } from "../urls-
|
|
10
|
+
import { t as punycodeUtilsJS } from "../punyCode-GakZYPCT.js";
|
|
11
|
+
import { a as extractURLs, i as normalizePathname, n as getPrefixPathname, o as constructURL, r as getFirstPrefixPathname, t as formatEnvPort } from "../urls-DTndjYDD.js";
|
|
12
12
|
export { constructURL, extractURLs, formatEnvPort, getFirstPrefixPathname, getPrefixPathname, normalizePathname, punycodeUtilsJS };
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
* ========================================================================
|
|
3
3
|
* @rzl-zone/utils-js
|
|
4
4
|
* ------------------------------------------------------------------------
|
|
5
|
-
* Version: `3.13.0-beta.
|
|
5
|
+
* Version: `3.13.0-beta.3`
|
|
6
6
|
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
7
|
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
8
|
* ========================================================================
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
|
-
const require_assertIsBoolean = require('./assertIsBoolean-
|
|
12
|
-
const require_assertIsArray = require('./assertIsArray-
|
|
13
|
-
const require_toStringArrayUnRecursive = require('./toStringArrayUnRecursive-
|
|
14
|
-
const require_safeStableStringify = require('./safeStableStringify-
|
|
15
|
-
const require_isEmptyString = require('./isEmptyString-
|
|
16
|
-
const require_isEmptyValue = require('./isEmptyValue-
|
|
17
|
-
const require_isInteger = require('./isInteger-
|
|
18
|
-
const require_isValidDomain = require('./isValidDomain-
|
|
19
|
-
const require_removeSpaces = require('./removeSpaces-
|
|
11
|
+
const require_assertIsBoolean = require('./assertIsBoolean-BKcvET7Z.cjs');
|
|
12
|
+
const require_assertIsArray = require('./assertIsArray-DWsgvahU.cjs');
|
|
13
|
+
const require_toStringArrayUnRecursive = require('./toStringArrayUnRecursive-DJ8JBO3N.cjs');
|
|
14
|
+
const require_safeStableStringify = require('./safeStableStringify-DSwcrPll.cjs');
|
|
15
|
+
const require_isEmptyString = require('./isEmptyString-CzY-9G-x.cjs');
|
|
16
|
+
const require_isEmptyValue = require('./isEmptyValue-Ci3kVU4E.cjs');
|
|
17
|
+
const require_isInteger = require('./isInteger-CCJhQ1Mx.cjs');
|
|
18
|
+
const require_isValidDomain = require('./isValidDomain-CXWNcRo6.cjs');
|
|
19
|
+
const require_removeSpaces = require('./removeSpaces-DhJ1haaH.cjs');
|
|
20
20
|
const constructURL = (baseUrl, queryParams, removeParams) => {
|
|
21
21
|
if (require_assertIsBoolean.isString(baseUrl)) {
|
|
22
22
|
if (require_isEmptyString.isEmptyString(baseUrl)) throw new TypeError("First parameter (`baseUrl`) cannot be an empty-string.");
|
|
@@ -296,4 +296,4 @@ Object.defineProperty(exports, 'normalizePathname', {
|
|
|
296
296
|
return normalizePathname;
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
|
-
//# sourceMappingURL=urls-
|
|
299
|
+
//# sourceMappingURL=urls-DCjjZNTH.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls-DCyx8Wpk.cjs","names":["isString","isEmptyString","normalizeString","isURL","getPreciseType","safeStableStringify","isUndefined","isNonEmptyString","isFunction","isEmptyValue","isNumber","isError","isNonEmptyString","isFunction","isNonEmptyString","getPreciseType","safeStableStringify","isUndefined","isSet","isArray","isNil","isString","isNull","removeSpaces","isValidDomain","isError","isNonEmptyString","getPreciseType","safeStableStringify","isArray","isString","isNil","isString","isArray","getPreciseType","isNull","isPlainObject","isInteger","safeStableStringify","isBoolean","isNonEmptyArray","joinLines","EOL","isNonEmptyString","isNonEmptyString","hasOwnProp","isBoolean","getPreciseType","isEmptyString"],"sources":["../src/urls/builders/constructURL.ts","../src/urls/extractors/extractURLs.ts","../src/urls/_private/NormalizePathnameError.ts","../src/urls/pathname/normalizePathname.ts","../src/urls/pathname/getFirstPrefixPathname.ts","../src/urls/pathname/getPrefixPathname.ts","../src/urls/utils/formatEnvPort.ts"],"sourcesContent":["import { isURL } from \"@/predicates/is/isURL\";\nimport { isError } from \"@/predicates/is/isError\";\nimport { isNumber } from \"@/predicates/is/isNumber\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isFunction } from \"@/predicates/is/isFunction\";\nimport { isUndefined } from \"@/predicates/is/isUndefined\";\nimport { isEmptyValue } from \"@/predicates/is/isEmptyValue\";\nimport { isEmptyString } from \"@/predicates/is/isEmptyString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { normalizeString } from \"@/strings/sanitizations/normalizeString\";\n\nimport { assertIsArray } from \"@/assertions/objects/assertIsArray\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\nimport { toStringArrayUnRecursive } from \"@/conversions/arrays/casts/toStringArrayUnRecursive\";\n\n/** ----------------------------------------------------------\n * * ***Type-Utility: `QueryParamPairs`.***\n * ----------------------------------------------------------\n * **Represents a non-empty array of key–value pairs.**\n * @description\n * Type for `queryParams` parameter, the second parameter of ***`constructURL` utility function***.\n * - **Behavior:**\n * - Each inner tuple strictly follows the `[string, string | number]` shape.\n * - Ensures the outer array contains **at least one pair** (non-empty).\n * - Commonly used for URL construction parameters,\n * query string segments, or other key–value structured data.\n * @example\n * // ✅ valid usage\n * const params: QueryParamPairs = [\n * [\"foo\", 1],\n * [\"bar\", \"baz\"]\n * ];\n * constructURL(\"https://example.com\", params);\n *\n * // ❌ invalid: must contain at least one item\n * const empty: QueryParamPairs = [];\n *\n * // ❌ invalid: key without value pairs.\n * const empty2: QueryParamPairs = [[\"key\"]];\n */\nexport type QueryParamPairs = [\n [string, string | number],\n ...[string, string | number][]\n];\n\n/** ---------------------------------\n * * ***Utility: `constructURL`.***\n * ---------------------------------\n * **Constructs a valid URL with optional query parameters and allows selective removal of duplicate parameters.**\n * @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.\n * @param {Iterable<[string, string]> | URLSearchParamsIterator<[string, string]> | QueryParamPairs} [queryParams]\n * Additional query parameters to append or overwrite on the URL.\n * - Accepts any iterable of key-value pairs (like `new URLSearchParams().entries()` and `[[string, string | number]...]`).\n * @param {string[]} [removeParams]\n * A list of query parameter keys to remove from the final URL, whether they were in the base URL or provided queryParams.\n * @returns {URL} A new URL object representing the constructed URL with merged and cleaned query parameters.\n * @throws **{@link TypeError | `TypeError`}** 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.\n * @example\n * 1. #### Basic Usage:\n * ```ts\n * constructURL(\n * \"https://example.com/path\",\n * new URLSearchParams({ a: \"1\", b: \"2\" }).entries()\n * );\n * // ➔ URL { href: \"https://example.com/path?a=1&b=2\", ... }\n * ```\n * 2. #### Remove parameters from Base and Added:\n * ```ts\n * // with new URLSearchParams({ ... }).entries();\n * constructURL(\n * \"https://example.com/path?foo=1&bar=2\",\n * new URLSearchParams({ bar: \"ignored\", baz: \"3\" }).entries(),\n * [\"bar\"]\n * );\n * // ➔ URL { href: \"https://example.com/path?foo=1&baz=3\", ... }\n *\n * // with [[string, string | number]...]\n * constructURL(\n * \"https://example.com/path?foo=1&bar=2\",\n * [[\"bar\", \"ignored\"],[\"baz\", 3]],\n * [\"bar\"]\n * );\n * // ➔ URL { href: \"https://example.com/path?foo=1&baz=3\", ... }\n *\n * const params: QueryParamPairs = [\n * [\"foo\", 1],\n * [\"bar\", 2],\n * [\"baz\", 3]\n * ];\n *\n * constructURL(\"https://example.com\", params, [\"bar\"]);\n * // ➔ URL { href: \"https://example.com/?foo=1&baz=3\", ... }\n * ```\n */\nexport const constructURL = (\n baseUrl: string | URL,\n queryParams?:\n | URLSearchParamsIterator<[string, string | number]>\n | QueryParamPairs,\n removeParams?: string[]\n): URL => {\n if (isString(baseUrl)) {\n if (isEmptyString(baseUrl)) {\n throw new TypeError(\n \"First parameter (`baseUrl`) cannot be an empty-string.\"\n );\n }\n baseUrl = normalizeString(baseUrl);\n } else if (!isURL(baseUrl)) {\n throw new TypeError(\n `First parameter (\\`baseUrl\\`) must be of type an URL instance or a \\`string\\` and a non empty-string, but received: \\`${getPreciseType(\n baseUrl\n )}\\`, with current value: \\`${safeStableStringify(baseUrl, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n // Check removeParams\n if (!isUndefined(removeParams)) {\n assertIsArray(removeParams, {\n message: ({ currentType, validType }) =>\n `Third parameter (\\`removeParams\\`) must be of type \\`${validType} of strings\\`, but received: \\`${currentType}\\`.`\n });\n\n if (!removeParams.every((param) => isNonEmptyString(param))) {\n throw new TypeError(\n \"Third parameter (`removeParams`) must be of type `array` and contains `string` only and non empty-string.\"\n );\n }\n }\n\n try {\n // Check queryParams\n if (\n !isUndefined(queryParams) &&\n !isFunction(queryParams[Symbol.iterator])\n ) {\n throw new TypeError(\n `Second parameter (\\`queryParams\\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \\`${getPreciseType(\n queryParams\n )}\\`, with value: \\`${safeStableStringify(queryParams, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n const urlInstance = new URL(baseUrl);\n\n // Add query parameters if provided\n if (!isUndefined(queryParams)) {\n const paramObject = Object.fromEntries(queryParams);\n\n if (!isEmptyValue(paramObject)) {\n // existing params\n const mergedParams = new URLSearchParams(urlInstance.search);\n\n // add / overwrite from queryParams\n for (const [key, value] of Object.entries(paramObject)) {\n if (\n !isNonEmptyString(value) &&\n !isNumber(value, { includeNaN: true })\n ) {\n throw new TypeError(\n `Second parameter (\\`queryParams\\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \\`${getPreciseType(\n queryParams\n )}\\`, with value: \\`${safeStableStringify(queryParams, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n mergedParams.set(key, String(value));\n }\n\n // Remove specific query parameters if needed\n if (removeParams?.length) {\n toStringArrayUnRecursive(removeParams).map((paramKey) => {\n mergedParams.delete(paramKey);\n });\n }\n\n urlInstance.search = mergedParams.toString();\n }\n }\n\n // Remove query parameters directly from URL if needed\n removeParams?.forEach((param) => urlInstance.searchParams.delete(param));\n\n return urlInstance;\n } catch (error) {\n if (isError(error)) throw error;\n\n throw new Error(\n \"Failed to construct a valid URL in `constructURL()`, Error:\" + error,\n { cause: error }\n );\n }\n};\n","import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ---------------------------------\n * * ***Utility: `extractURLs`.***\n * ---------------------------------\n * **Extracts all valid URLs from a given string.**\n * @description\n * This function scans the input url and returns an array of URLs\n * that match a valid `http` or `https` format.\n * - **Supports:**\n * - Internationalized domain names (IDN), e.g. `https://münich.de`\n * - Unicode & emoji paths, e.g. `https://example.com/🎉/page`\n * - Long URLs with multiple queries & fragments, e.g. `https://example.com/path?foo=1#hash`\n * - **Ignores:**\n * - Non-string inputs\n * - Empty or whitespace-only strings\n * - Non-HTTP(S) protocols (ftp, mailto, etc)\n * @param {string | null | undefined} url - The input string containing potential URLs.\n * @returns {string[] | null} An array of extracted URLs or `null` if no URLs are found.\n * @example\n * extractURLs(\"Visit https://example.com and https://例子.公司\");\n * // ➔ [\"https://example.com\", \"https://例子.公司\"]\n * extractURLs(\"Here: https://example.com/🎉/page\");\n * // ➔ [\"https://example.com/🎉/page\"]\n * extractURLs(\"ftp://example.com http://example.com\");\n * // ➔ [\"http://example.com\"]\n */\nexport const extractURLs = (\n url: string | null | undefined\n): string[] | null => {\n if (!isNonEmptyString(url)) return null;\n\n let decoded;\n try {\n decoded = decodeURIComponent(url);\n } catch {\n return null;\n }\n\n // Core regex with lookahead\n const urlPattern = /https?:\\/\\/.*?(?=https?:\\/\\/|\\s|$)/g;\n const matches = decoded.match(urlPattern);\n if (!matches) return null;\n\n // Cleanup trailing punctuation and validation protocol\n const cleaned = matches\n .map((url) => url.replace(/[.,;:!?)]*$/, \"\"))\n .filter((url) => {\n try {\n const u = new URL(url);\n return u.protocol === \"http:\" || u.protocol === \"https:\";\n } catch {\n return false;\n }\n });\n\n return cleaned.length ? cleaned : null;\n};\n","import { isFunction } from \"@/predicates/is/isFunction\";\n\n/** ---------------------------------\n * * ***Custom Error for Pathname Normalization Failures***\n * ---------------------------------\n */\nexport class NormalizePathnameError extends Error {\n /** ---------------------------------\n * * ***The original error that triggered this normalization failure.***\n * ---------------------------------\n *\n * **Always available for backward compatibility.**\n */\n public readonly originalError: Error;\n\n constructor(message: string, originalError: Error) {\n // Pass a `cause` option if the runtime supports it (ignored by older engines).\n super(message, isFunction(Error) ? { cause: originalError } : undefined);\n\n this.name = \"NormalizePathnameError\";\n this.originalError = originalError;\n\n // Preserve stack trace when available (Node.js & modern browsers).\n if (isFunction(Error.captureStackTrace)) {\n Error.captureStackTrace(this, NormalizePathnameError);\n } else {\n // Fallback for very old environments.\n this.stack = new Error(message).stack;\n }\n }\n\n /** ---------------------------------\n * * ***Safe JSON representation for logging or IPC.***\n * ---------------------------------\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n originalError: {\n name: this.originalError.name,\n message: this.originalError.message,\n stack: this.originalError.stack\n }\n };\n }\n}\n","import type { OverrideTypes, Prettify } from \"@rzl-zone/ts-types-plus\";\n\nimport { isSet } from \"@/predicates/is/isSet\";\nimport { isNil } from \"@/predicates/is/isNil\";\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isError } from \"@/predicates/is/isError\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isValidDomain } from \"@/predicates/is/isValidDomain\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\nimport { removeSpaces } from \"@/strings/sanitizations/removeSpaces\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\nimport { NormalizePathnameError } from \"../_private/NormalizePathnameError\";\nimport { isUndefined } from \"@/predicates/is/isUndefined\";\n\n/** Options when `keepNullable` is false (default).\n *\n * Returns `defaultPath` if `pathname` is empty or invalid.\n */\ntype UnKeepNullableOptions = {\n /** * ***Fallback value returned if `pathname` is empty-string or invalid.***\n *\n * Must be a **`non-empty string`**, defaultValue: `\"/\"`.\n *\n * @default \"/\"\n */\n defaultPath?: string;\n\n /** * ***Whether to preserve `null` or `undefined`, defaultValue: `false`.***\n *\n * @default false\n */\n keepNullable?: false;\n};\n\n/** Options when `keepNullable` is true.\n *\n * Preserves `null` or `undefined` instead of returning `defaultPath`.\n */\ntype KeepNullableOptions = {\n /** * ***Fallback path is ignored when `keepNullable` is true **(except if\n * `pathname` is empty-string or invalid, even this `true`)**,\n * defaultValue: `\"/\"`.***\n *\n * @default \"/\"\n */\n defaultPath?: string;\n\n /** * ***Preserve `null` or `undefined` as-is if `true` (defaultValue: `false`).***\n *\n * - ***⚠️ Notes:***\n * - Keep returning `defaultPath` if `pathname` is empty-string, even this `true`.\n *\n * **Must be `true` in this type.**\n *\n * @default false\n */\n keepNullable?: true;\n};\n\ntype MainNormalizePathnameOptions = {\n /** --------------------------------------------------------\n * * ***Preserve trailing slash at the end of the normalized pathname, defaultValue: `false`.***\n * --------------------------------------------------------\n *\n * @default `false`\n */\n keepTrailingSlash?: boolean;\n\n /** --------------------------------------------------------\n * * ***Allow special localhost domain at the beginning of the pathname.***\n * --------------------------------------------------------\n * @description\n * If `true`, the first segment of the pathname that is `/localhost` or `localhost`\n * (with or without a port, e.g., `localhost:3000`) will be treated as a special domain\n * and **removed** from the normalized pathname.\n *\n * - **Examples (`localhostDomain: true`)**:\n * - `\"/localhost/path\"` ➔ `\"/path\"`\n * - `\"localhost:3000/path\"` ➔ `\"/path\"`\n * - `\"localhost\"` ➔ `\"/\"` (entire path removed)\n *\n * - Only the **first path segment** is affected. Any subsequent occurrences of `\"localhost\"`\n * will remain intact.\n *\n * @default false\n */\n localhostDomain?: boolean;\n\n /**\n * --------------------------------------------------------\n * * ***Custom list of file extensions that prevent the first path segment from being treated as a domain.***\n * --------------------------------------------------------\n *\n * **Description:**\n * - The first segment of a pathname is often interpreted as a domain (e.g., `example.com`).\n * - If this first segment ends with any of the extensions listed here, it will **not** be considered a domain,\n * and will instead be preserved as part of the relative path.\n * - This is useful for cases where filenames appear at the start of a path and you want them treated as relative paths,\n * such as `\"image.png?version=2\"` or `\"archive.tar.gz#download\"`.\n * - Only the **first path segment** is affected; all other segments are processed normally.\n * - **Ignored** if:\n * 1. The pathname starts with a full URL protocol (`http://` or `https://`), e.g., `\"https://example.com/file.png\"`.\n * 2. The first path segment is already a valid domain, e.g., `\"example.com/image.png\"`.\n *\n * **Type & Validation:**\n * - Must be a `Set<string>` or `string[]`.\n * - Each string **must include the leading dot**, e.g., `.png`, `.tar.gz`.\n * - Multi-part extensions (like `.tar.gz`, `.tar.bz`) are supported.\n * - Throws a **TypeError** if:\n * 1. The type is not a `Set<string>` or `string[]`.\n * 2. Any string in the array/set is empty.\n * 3. Any string does not start with a dot (`.`).\n *\n * **Usage Notes:**\n * - Only applied when the first segment is otherwise domain-like **and** pathname is relative or domain-like without protocol.\n * - Query strings (`?x=1`) and hash fragments (`#section`) are preserved.\n *\n * **Examples (relative paths, option active):**\n * ```ts\n * normalizePathname(\"image.png?version=2\", {\n * ignoreDomainExtensions: [\".png\", \".jpg\"]\n * });\n * // ➔ \"/image.png?version=2\"\n *\n * normalizePathname(\"archive.tar.gz#download\", {\n * ignoreDomainExtensions: new Set([\".tar.gz\"])\n * });\n * // ➔ \"/archive.tar.gz#download\"\n *\n * normalizePathname(\"script.js?module=true#top\", {\n * ignoreDomainExtensions: [\".js\"]\n * });\n * // ➔ \"/script.js?module=true#top\"\n * ```\n *\n * **Examples (full URL or explicit domain - option ignored):**\n * ```ts\n * normalizePathname(\"https://example.com/image.png?version=2\", {\n * ignoreDomainExtensions: [\".png\"]\n * });\n * // ➔ \"/image.png?version=2\" // URL is parsed normally; ignoreDomainExtensions has no effect\n *\n * normalizePathname(\"example.com/script.js?module=true#top\", {\n * ignoreDomainExtensions: [\".js\"]\n * });\n * // ➔ \"/script.js?module=true#top\" // domain recognized; option ignored\n * ```\n *\n * **Notes:**\n * - Only the **first path segment** is checked.\n * - Prevents false-positive domain stripping for filenames that look like domains.\n * - Throws **TypeError** if invalid type or invalid string is provided.\n *\n * @default undefined (feature inactive if not provided)\n */\n ignoreDomainExtensions?: Set<string> | string[];\n};\n\n/** Options for main `normalizePathname`.\n *\n * Combines `UnKeepNullableOptions` or `KeepNullableOptions` with trailing slash control.\n */\ntype NormalizePathnameOptions = Prettify<\n MainNormalizePathnameOptions & (UnKeepNullableOptions | KeepNullableOptions)\n>;\n\ntype NormalizePathnameOptionsKeepNullableTrue = MainNormalizePathnameOptions &\n KeepNullableOptions;\ntype NormalizePathnameOptionsKeepNullableFalse = MainNormalizePathnameOptions &\n UnKeepNullableOptions;\n\ntype ResUnKeepNullable<T> = T extends undefined\n ? string\n : T extends null\n ? string\n : T extends null | undefined\n ? string\n : string;\n\ntype ResKeepNullable<T> = T extends string\n ? string\n : T extends undefined\n ? undefined\n : T extends null\n ? null\n : T extends null | undefined\n ? null | undefined\n : string | null | undefined;\n\n/** --------------------------------------------------------\n * * ***Utility: `normalizePathname`.***\n * --------------------------------------------------------\n *\n * - **Description:**\n * Normalizes any pathname or URL string to a clean, predictable format.\n * Useful for routing, file paths, and URL handling.\n * - Handles:\n * - Leading/trailing spaces\n * - Internal spaces in path segments\n * - Redundant slashes (`//`)\n * - Full URLs vs relative paths\n * - Query (`?`) and hash (`#`) preservation\n * - Unicode & emoji characters\n * - Optional nullable preservation (`keepNullable`)\n * - Optional trailing slash preservation (`keepTrailingSlash`)\n * - Optional removal of localhost first segment (`localhostDomain`)\n * - Prevention of false-positive domain stripping (`ignoreDomainExtensions`)\n *\n * - **Key Steps Internally:**\n * 1. Validate `options` (plain object, correct types)\n * 2. Validate `defaultPath` (non-empty string if `keepNullable` is false)\n * 3. Validate `ignoreDomainExtensions` (Set<string> | string[], each starts with `.`)\n * 4. Handle nullable:\n * - Returns `null` / `undefined` if `keepNullable: true`\n * - Otherwise uses `defaultPath`\n * 5. Trim spaces, remove internal spaces\n * 6. If full URL: parse using `URL` constructor\n * 7. If relative path or domain-like:\n * - Remove `localhost`/`localhost:port` if `localhostDomain`\n * - Remove first segment if domain-like and **not** in `ignoreDomainExtensions`\n * 8. Normalize slashes\n * 9. Ensure leading slash\n * 10. Handle trailing slash\n * 11. Decode Unicode safely\n * 12. Return normalized pathname + search + hash\n *\n * - **Error Handling:**\n * - **TypeError**:\n * - `defaultPath` invalid (non-string or empty) when `keepNullable: false`\n * - `keepNullable`, `keepTrailingSlash`, `localhostDomain` not boolean\n * - `ignoreDomainExtensions` invalid\n * - **NormalizePathnameError** (extends ***Error***):\n * - Invalid URL parsing\n * - Unexpected normalization errors\n *\n * - **Options:**\n * ```ts\n * {\n * // fallback if invalid path, default: \"/\"\n * defaultPath?: string;\n * // preserve null/undefined, default: false\n * keepNullable?: boolean;\n * // preserve trailing slash, default: false\n * keepTrailingSlash?: boolean;\n * // remove localhost:port first segment, default: false\n * localhostDomain?: boolean;\n * // prevent domain stripping, default: undefined\n * ignoreDomainExtensions?: Set<string> | string[];\n * }\n * ```\n *\n * @example\n * // Basic path cleaning\n * normalizePathname(\" /foo//bar \");\n * // ➔ \"/foo/bar\"\n *\n * // Trailing slash control\n * normalizePathname(\"/api//v1//user//\", { keepTrailingSlash: true });\n * // ➔ \"/api/v1/user/\"\n * normalizePathname(\"/api//v1//user//\", { keepTrailingSlash: false });\n * // ➔ \"/api/v1/user\"\n *\n * // Full URL normalization\n * normalizePathname(\"https://example.com//path///to/resource?x=1#hash\");\n * // ➔ \"/path/to/resource?x=1#hash\"\n *\n * // Null/undefined preservation\n * normalizePathname(null, { keepNullable: true });\n * // ➔ null\n * normalizePathname(undefined, { keepNullable: true });\n * // ➔ undefined\n *\n * // Default fallback\n * normalizePathname(\"\", { defaultPath: \"/home\" });\n * // ➔ \"/home\"\n *\n * // Localhost removal\n * normalizePathname(\"localhost:3000/path/to/resource\", { localhostDomain: true });\n * // ➔ \"/path/to/resource\"\n *\n * // Prevent false-positive domain stripping\n * normalizePathname(\"archive.tar.gz#download\", { ignoreDomainExtensions: [\".tar.gz\"] });\n * // ➔ \"/archive.tar.gz#download\"\n * normalizePathname(\"image.png?version=2\", { ignoreDomainExtensions: [\".png\"] });\n * // ➔ \"/image.png?version=2\"\n *\n * // Emojis and Unicode\n * normalizePathname(\"🔥//deep//path///🚀\");\n * // ➔ \"/🔥/deep/path/🚀\"\n *\n * // Query-only or hash-only\n * normalizePathname(\"?page=2\");\n * // ➔ \"/?page=2\"\n * normalizePathname(\"#section3\");\n * // ➔ \"/#section3\"\n *\n * // Complex nested paths\n * normalizePathname(\" //nested///folder//file.txt \");\n * // ➔ \"/nested/folder/file.txt\"\n *\n * // Invalid URL triggers error\n * try {\n * normalizePathname(\"http://\");\n * } catch (e) {\n * // console.log(e);\n * }\n *\n * // First segment is domain but ignored due to extension\n * normalizePathname(\"example.tar.bz/file\", { ignoreDomainExtensions: [\".tar.bz\"] });\n * // ➔ \"/example.tar.bz/file\"\n */\nexport function normalizePathname<T>(\n pathname: T,\n options?: NormalizePathnameOptionsKeepNullableFalse\n): ResUnKeepNullable<T>;\nexport function normalizePathname<T>(\n pathname: T,\n options?: NormalizePathnameOptionsKeepNullableTrue\n): ResKeepNullable<T>;\nexport function normalizePathname(\n pathname: unknown,\n options: NormalizePathnameOptions = {\n defaultPath: \"/\",\n keepNullable: false\n }\n): string | null | undefined {\n assertIsPlainObject(options, {\n message({ currentType, validType }) {\n return `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n const {\n defaultPath = \"/\",\n keepNullable = false,\n keepTrailingSlash = false,\n localhostDomain = false,\n ignoreDomainExtensions = undefined\n } = options;\n\n // Validate defaultPath\n if (!isNonEmptyString(defaultPath)) {\n throw new TypeError(\n `Parameter \\`defaultPath\\` property of the \\`options\\` (second parameter) must be of type \\`string\\` and not empty-string, but received: \\`${getPreciseType(\n defaultPath\n )}\\`, with value: \\`${safeStableStringify(defaultPath, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n assertIsBoolean(keepNullable, {\n message({ currentType, validType }) {\n return `Parameter \\`keepNullable\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n assertIsBoolean(keepTrailingSlash, {\n message({ currentType, validType }) {\n return `Parameter \\`keepTrailingSlash\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n assertIsBoolean(localhostDomain, {\n message({ currentType, validType }) {\n return `Parameter \\`localhostDomain\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n let ignoreDomainExtsSet: Set<string> | undefined;\n\n if (!isUndefined(ignoreDomainExtensions)) {\n if (!isSet(ignoreDomainExtensions) && !isArray(ignoreDomainExtensions)) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions\\` must be of type a \\`Set<string>\\` or \\`string[]\\`, but received: \\`${getPreciseType(\n ignoreDomainExtensions\n )}\\`.`\n );\n }\n\n ignoreDomainExtsSet = isSet(ignoreDomainExtensions)\n ? ignoreDomainExtensions\n : new Set(ignoreDomainExtensions);\n\n // validation every ext\n let idx = 0;\n for (const ext of ignoreDomainExtsSet) {\n if (!isNonEmptyString(ext)) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions[${idx}]\\` must be a \\`string\\` and \\`non-empty string\\`, but received: \\`${safeStableStringify(\n ext,\n { keepUndefined: true }\n )}\\`.`\n );\n }\n if (!ext.startsWith(\".\")) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions[${idx}]\\` must start with a dot (.), but received: ${safeStableStringify(\n ext,\n { keepUndefined: true }\n )}`\n );\n }\n idx++;\n }\n }\n\n try {\n if (keepNullable && (isNil(pathname) || !isString(pathname))) {\n if (isNull(pathname)) return null;\n return undefined;\n }\n\n // If the pathname is invalid (null, undefined, or an empty string), return the default value, only if `keepNullable` is false\n let currentPathName: string = isNonEmptyString(pathname)\n ? pathname\n : defaultPath;\n\n // Trim spaces from the string (only trim leading and trailing spaces)\n currentPathName = removeSpaces(currentPathName, { trimOnly: true }).replace(\n /\\s+/g,\n \"\"\n ); // remove all space\n\n currentPathName = stripLeadingDomain(currentPathName, {\n keepTrailingSlash,\n localhostDomain,\n ignoreDomainExtensions: ignoreDomainExtsSet\n });\n\n let _pathName: string = currentPathName;\n let search = \"\";\n let hash = \"\";\n\n // relative path: extract search/hash manually\n const searchIndex = currentPathName.indexOf(\"?\");\n const hashIndex = currentPathName.indexOf(\"#\");\n\n if (searchIndex !== -1) {\n search = currentPathName.slice(\n searchIndex,\n hashIndex !== -1 ? hashIndex : undefined\n );\n }\n if (hashIndex !== -1) {\n hash = currentPathName.slice(hashIndex);\n }\n\n const endIndex = Math.min(\n searchIndex !== -1 ? searchIndex : currentPathName.length,\n hashIndex !== -1 ? hashIndex : currentPathName.length\n );\n _pathName = currentPathName.slice(0, endIndex);\n\n // Normalize slashes\n _pathName = \"/\" + _pathName.replace(/^\\/+/, \"\").replace(/\\/{2,}/g, \"/\");\n\n // Trailing slash\n if (!keepTrailingSlash && _pathName !== \"/\") {\n _pathName = _pathName.replace(/\\/+$/, \"\");\n }\n\n // Decode Unicode safely\n _pathName = decodeUnicodeSequences(_pathName);\n search = decodeUnicodeSequences(search);\n hash = decodeUnicodeSequences(hash);\n\n return _pathName + search + hash;\n } catch (error) {\n // Handle any errors that occur during processing\n throwError(error);\n }\n}\n\n// --- Internal Helper Utils ----\n\n/**\n * @internal\n */\nconst decodeUnicodeSequences = (str: string): string => {\n return str.replace(/(?:%(?:[0-9A-F]{2})){2,}/gi, (match) => {\n try {\n const decoded = decodeURIComponent(match);\n // eslint-disable-next-line no-control-regex\n if (/^[\\u0000-\\u007F]+$/.test(decoded)) return match;\n // eslint-enable-next-line no-control-regex\n return decoded;\n } catch {\n return match;\n }\n });\n};\n\n/**\n * @internal\n */\nconst stripLeadingDomain = (\n path: string,\n options: OverrideTypes<\n MainNormalizePathnameOptions,\n { ignoreDomainExtensions?: Set<string> }\n >\n): string => {\n let currentPath = path;\n\n const { ignoreDomainExtensions, localhostDomain } = options;\n\n // Full URL (protocol) -> only normalize path, ignore ignoreDomainExtensions\n if (/^https?:\\/\\//i.test(currentPath)) {\n try {\n const url = new URL(currentPath);\n currentPath =\n url.pathname.replace(/^\\/+/, \"\").replace(/\\/{2,}/g, \"/\") +\n url.search +\n url.hash;\n\n return ensureLeadingSlash(currentPath);\n } catch (error) {\n // fallback: keep as-is\n // Handle any errors that occur during processing\n throwError(error);\n }\n }\n\n // relative path: remove leading slash\n if (currentPath.startsWith(\"/\")) {\n currentPath = currentPath.replace(/\\/{2,}/g, \"/\").slice(1);\n }\n\n // take first segment\n const segments = currentPath.split(\"/\");\n const firstPart = segments[0];\n const domainPart = firstPart?.split(\":\")[0];\n\n const isDomain = isValidDomain(domainPart, {\n subdomain: true,\n allowUnicode: true,\n wildcard: true,\n allowLocalhost: localhostDomain,\n allowPort: true,\n allowProtocol: true,\n topLevel: false\n });\n\n // ignoreDomainExtensions only applies for relative/non-protocol paths\n let hasIgnoredExtension = false;\n if (ignoreDomainExtensions) {\n for (const ext of ignoreDomainExtensions) {\n if (firstPart?.endsWith(ext)) {\n hasIgnoredExtension = true;\n break;\n }\n }\n }\n\n if (isDomain && !hasIgnoredExtension) {\n segments.shift(); // remove first segment\n }\n\n return ensureLeadingSlash(segments.join(\"/\"));\n};\n\n/**\n * @internal\n */\nconst ensureLeadingSlash = (path: string): string => {\n if (!path.startsWith(\"/\")) path = \"/\" + path;\n return path;\n};\n\n/**\n * @internal\n */\nconst throwError = (error: unknown): never => {\n // Handle any errors that occur during processing\n const err = isError(error)\n ? error\n : new Error(\"Unknown error from function `normalizePathname()`.\");\n throw new NormalizePathnameError(\n `Failed to normalize pathname in function \\`normalizePathname()\\`: ${err.message}`,\n err\n );\n};\n","import { isNil } from \"@/predicates/is/isNil\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\nimport { normalizePathname } from \"./normalizePathname\";\n\n/** --------------------------------------------------------\n * * ***Utility: `getFirstPrefixPathname`.***\n * --------------------------------------------------------\n * **Extract First Valid Prefix from Path Array or String.**\n * - **Main Purpose:**\n * - This function helps extract the first valid URL prefix from various possible inputs.\n * - It is especially useful in routing systems, middleware, or frontend apps that need to\n * decide layout, active navigation, or permissions based on the first segment (or prefix) of a pathname.\n * - **Typical uses include:**\n * - Determining which layout to render (e.g., `/admin` vs `/dashboard` vs `/`).\n * - Highlighting the active menu item in a sidebar based on the current URL.\n * - Enforcing route guards or access controls depending on the URL prefix.\n * - Parsing multi-level route prefixes and selecting the most relevant one.\n * - **Behavior:**\n * - It works as follows:\n * - If `result` is an array of strings, it normalizes each element and returns\n * the first non-root path (i.e., not just `\"/\"`).\n * - If all items normalize to `\"/\"`,\n * it returns the `defaultValue` (normalized).\n * - If `result` is a single string, it normalizes it and returns it if valid,\n * otherwise falls back to the normalized `defaultValue`.\n * - If `result` is `null` or `undefined`, it returns the normalized `defaultValue`.\n * - **Validation & Errors:**\n * - Throws a `TypeError` if:\n * - `defaultValue` is not a string or empty-string.\n * - `result` is an array that contains non-string elements.\n * - `result` is a value that is neither `string`, `string[]`, nor `null`.\n * @example\n * 1. #### For React (*Determining layout*):\n * ```ts\n * const prefix = getFirstPrefixPathname(\n * getPrefixPathname(\n * \"/admin/settings\",\n * [\"/admin\", \"/dashboard\"]\n * )\n * );\n *\n * if (prefix === \"/admin\") {\n * renderAdminLayout();\n * }\n * ```\n *\n * 2. #### Setting active menu state:\n * ```ts\n * const activeSection = getFirstPrefixPathname([\"\", \"/dashboard\", \"/profile\"]);\n * // ➔ \"/dashboard\"\n * ```\n *\n * 3. #### Providing graceful fallback:\n * ```ts\n * const section = getFirstPrefixPathname([], \"/home\");\n * // ➔ \"/home\"\n * ```\n * 4. #### ✅ Using with an Array of Pathnames:\n * ```ts\n * const result = getPrefixPathname([\" \", \"/dashboard\", \"/settings\"]);\n * console.log(getFirstPrefixPathname(result));\n * // ➔ \"/dashboard\"\n * ```\n *\n * 5. #### ✅ Using with Single String:\n * ```ts\n * console.log(getFirstPrefixPathname(\"/profile/settings\"));\n * // ➔ \"/profile/settings\"\n * console.log(getFirstPrefixPathname(\" \"));\n * // ➔ \"/\"\n * ```\n *\n * 6. #### ✅ Fallback to Custom Default:\n * ```ts\n * console.log(getFirstPrefixPathname([\" \", \"\"], \"/home\"));\n * // ➔ \"/home\"\n * console.log(getFirstPrefixPathname(null, \"/dashboard\"));\n * // ➔ \"/dashboard\"\n * ```\n *\n * 7. #### ✅ Throws on Invalid Input:\n * ```ts\n * getFirstPrefixPathname([1, 2] as any); // ➔ ❌ throws TypeError\n * getFirstPrefixPathname({} as any); // ➔ ❌ throws TypeError\n * getFirstPrefixPathname(null, \" \"); // ➔ ❌ throws TypeError\n * ```\n * @param {string | string[] | null | undefined} result\n * ***The pathname(s) to process, can be:***\n * - A string path (e.g. `\"/profile\"`),\n * - An array of string paths (e.g. `[\" \", \"/dashboard\"]`),\n * - Or `null`.\n * @param {string} [defaultValue=\"/\"]\n * ***A custom default path to use if `result` is null or no valid prefix is found, behavior:***\n * - Must be a string and non-empty string.\n * - Defaults to `\"/\"`.\n * @returns {string}\n * ***The first valid normalized pathname, or the normalized default.***\n * @throws **{@link TypeError | `TypeError`}** ***if `result` is not a valid type, or `defaultValue` is not a string or empty-string.***\n */\nexport const getFirstPrefixPathname = (\n result: string | string[] | null | undefined,\n defaultValue: string = \"/\"\n): string => {\n if (!isNonEmptyString(defaultValue)) {\n throw new TypeError(\n `Second parameter (\\`defaultValue\\`) must be of type \\`string\\` and not an \\`empty-string\\`, but received: \\`${getPreciseType(\n defaultValue\n )}\\`, with value: \\`${safeStableStringify(defaultValue, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n if (isArray(result)) {\n if (!result.every((item) => isString(item))) {\n throw new TypeError(\n `First parameter (\\`result\\`) must be of type \\`string\\` or \\`array of string\\`, but received: \\`${getPreciseType(\n result\n )}\\`, with value: \\`${safeStableStringify(result, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n for (const item of result) {\n const normalized = normalizePathname(item);\n if (normalized !== \"/\") {\n return normalized;\n }\n }\n return normalizePathname(defaultValue);\n }\n\n if (isString(result)) {\n const normalized = normalizePathname(result);\n return normalized !== \"/\" ? normalized : normalizePathname(defaultValue);\n }\n\n if (!isNil(result)) {\n throw new TypeError(\n `First parameter (\\`result\\`) must be of type \\`string\\`, \\`array-string\\`, \\`null\\` or \\`undefined\\`, but received: \\`${getPreciseType(\n result\n )}\\`.`\n );\n }\n\n return normalizePathname(defaultValue);\n};\n","import { joinLines, EOL } from \"@rzl-zone/build-tools/utils\";\n\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isInteger } from \"@/predicates/is/isInteger\";\nimport { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyArray } from \"@/predicates/is/isNonEmptyArray\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\nimport { normalizePathname } from \"./normalizePathname\";\n\ntype GetPrefixPathnameOptions = {\n /** The number of levels to include in the prefix (default is `1`).\n *\n * - For example, with `levels = 2`, the function will return the first two parts of the URL.\n *\n * @default 1\n */\n levels?: number;\n /** Whether to remove duplicates from the result if multiple URLs are passed (default is `true`).\n *\n * @default true\n */\n removeDuplicates?: boolean;\n};\n\n/** --------------------------------------------------------\n * * ***Utility: `getPrefixPathname`.***\n * --------------------------------------------------------\n * **Get Prefix from URL with Optional Base or Auto-detection (Supports String or Array of URLs).**\n * - **This function extracts the prefix from one or more URLs. It can either:**\n * - Use a provided `base` string or an array of strings to check and return the matching prefix.\n * - Automatically detect the prefix if no `base` is provided by analyzing the first part of the URL.\n * - **The function is flexible and can handle both scenarios:**\n * 1. **When the base is provided as a single string or an array of strings**:\n * - The function will check if the URL starts with one of the provided base(s) and return the matching base.\n * 2. **When the base is not provided**:\n * - The function will automatically detect the prefix by splitting the URL or using a regex.\n * - **Important Notes**:\n * - If a base (or an array of bases) is provided, the URL must start with one of the given base(s).\n * - If no base is provided, the function will attempt to detect the prefix automatically.\n * - The `url` parameter can be either a string or an array of strings.\n * - Supports deduplication of results (enabled by default).\n * - Automatically returns a single string if only one unique result exists after processing.\n * @param {string|string[]} url\n * ***The full URL(s) from which the prefix should be extracted, can be a `string` or an `array of strings`.***\n * @param {string|string[]|null} [base=null]\n * ***The base URL(s) (e.g., `\"/settings\"`), behavior:***\n * - It can be a `string`, an `array of strings`, or `null`.\n * - If `provided`, it will be used to check the URL(s).\n * - If `not provided`, the prefix will be auto-detected.\n * @param {GetPrefixPathnameOptions} [options]\n * ***Additional options object:***\n * - `levels` (default `1`): The number of segments to include when auto-detecting the prefix (e.g. `/foo/bar` for `levels: 2`).\n * - `removeDuplicates` (default `true`): Whether to remove duplicate prefixes from the final array result.\n * @returns {string|string[]|null}\n * ***Returns one of:***\n * - A single string if only one unique prefix/base is found.\n * - An array of strings if multiple different prefixes/bases are found.\n * - `null` if no matching base is found when using `base`.\n * @throws **{@link TypeError | `TypeError`}**\n * ***if:***\n * - `url` is `not a string` or `not an array of strings`.\n * - `base` is `not a string`, `array of strings`, or `null`.\n * - `options` is `not an object`.\n * - `levels` is `not a number`.\n * - `removeDuplicates` is `not a boolean`.\n * @example\n * - #### ✅ **Correct Usage (With an Array of URLs and Base):**\n * ```ts\n * const routes = [\n * \"/settings/profile\",\n * \"/settings/password\",\n * \"/settings/other-path\",\n * \"/other-path/xyz\",\n * ];\n *\n * // With base provided as a string\n * routes.forEach(route => {\n * console.log(getPrefixPathname(route, '/settings'));\n * // ➔ \"/settings\"\n * });\n *\n * // With base provided as an array\n * routes.forEach(route => {\n * console.log(getPrefixPathname(route, ['/settings', '/admin']));\n * // ➔ \"/settings\" or \"/admin\" depending on the current URL.\n * });\n * ```\n * - #### ✅ **Correct Usage (With Single URL and Single Base):**\n * ```ts\n * const result = getPrefixPathname(\"/settings/profile\", \"/settings\");\n * console.log(result); // ➔ \"/settings\"\n * ```\n * - #### ✅ **Correct Usage (With Multiple URLs and Single Base):**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/password\"],\n * \"/settings\"\n * );\n * console.log(result); // ➔ \"/settings\"\n *\n * const result2 = getPrefixPathname(\n * [\"/settings/profile\", \"/other/password\"],\n * \"/other\"\n * );\n * console.log(result2); // ➔ \"/other\"\n * ```\n * - #### ✅ **Correct Usage (With Multiple URLs and Multiple Bases)**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/admin/password\"],\n * [\"/settings\", \"/admin\"]\n * );\n * console.log(result); // ➔ [\"/settings\", \"/admin\"]\n * ```\n * - #### ✅ **Auto-detection of Prefix**\n * ```ts\n * const result = getPrefixPathname(\"/settings/profile\");\n * console.log(result); // ➔ \"/settings\"\n *\n * const result2 = getPrefixPathname(\n * \"/settings/profile/info\",\n * null,\n * { levels: 2 }\n * );\n * console.log(result2); // ➔ \"/settings/profile\"\n * ```\n * - #### ✅ **Multiple URLs with Auto-detection**\n * ```ts\n * const result = getPrefixPathname([\"/admin/profile\", \"/settings/password\"]);\n * console.log(result); // ➔ [\"/admin\", \"/settings\"]\n * ```\n * - #### ✅ **Handling Duplicates**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/password\"],\n * \"/settings\"\n * );\n * console.log(result); // ➔ \"/settings\" (deduped to single string)\n *\n * const result2 = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/profile\"],\n * \"/settings\",\n * { removeDuplicates: false }\n * );\n * console.log(result2); // ➔ [\"/settings\", \"/settings\"]\n * ```\n * - #### ❌ **Incorrect Usage (URL Does Not Match Base)**\n * ```ts\n * const result = getPrefixPathname(\"/other-path/profile\", \"/settings\");\n * console.log(result); // ➔ null\n * ```\n */\nexport const getPrefixPathname = (\n url: string | string[],\n base: string | string[] | null = null,\n options: GetPrefixPathnameOptions = {}\n): string | string[] | null => {\n const errors: string[] = [];\n\n if (!isString(url) && !isArray(url)) {\n errors.push(\n `First parameter (\\`url\\`) must be of type \\`string\\` or \\`array-string\\`, but received: \\`${getPreciseType(\n url\n )}\\`.`\n );\n }\n if (!isString(base) && !isArray(base) && !isNull(base)) {\n errors.push(\n `Second parameter (\\`base\\`) must be of type \\`string\\`, \\`array-string\\` or \\`null\\`, but received: \\`${getPreciseType(\n base\n )}\\`.`\n );\n }\n if (!isPlainObject(options)) {\n errors.push(\n `Second parameter (\\`options\\`) must be of type \\`plain-object\\`, but received: \\`${getPreciseType(\n options\n )}\\`.`\n );\n }\n\n const { levels = 1, removeDuplicates = true } = options;\n\n if (!isInteger(levels) || (isInteger(levels) && levels < 0)) {\n errors.push(\n `Parameter \\`levels\\` property of the \\`options\\` (second parameter) must be of type \\`integer-number\\` and minimum is \\`0\\`, but received: \\`${getPreciseType(\n levels\n )}\\`, with value: \\`${safeStableStringify(levels, {\n keepUndefined: true\n })}\\`.`\n );\n }\n if (!isBoolean(removeDuplicates)) {\n errors.push(\n `Parameter \\`removeDuplicates\\` property of the \\`options\\` (second parameter) must be of type \\`boolean\\`, but received: \\`${getPreciseType(\n removeDuplicates\n )}\\`.`\n );\n }\n if (isNonEmptyArray(errors)) {\n throw new TypeError(\n joinLines(\n \"Invalid parameter(s) in `getPrefixPathname` function:\",\n `- ${errors.join(`${EOL}- `)}`\n )\n );\n }\n\n // Helper function to process a single URL\n function getLevel(singleUrl: string) {\n // If no base is provided, detect the base automatically\n const parts = normalizePathname(singleUrl).split(\"/\").filter(Boolean); // Split URL into parts\n\n // Return the first `levels` parts as the prefix\n return `/${parts.slice(0, levels).join(\"/\")}`;\n }\n\n // Helper function to process a single URL\n function processUrl(singleUrl: string): string | null {\n // If a base is provided, check if URL starts with one of the bases\n if (base) {\n singleUrl = normalizePathname(singleUrl);\n\n if (isArray(base)) {\n // Check if the URL starts with any of the base values in the array\n for (const b of base) {\n if (singleUrl.startsWith(normalizePathname(b))) {\n // return normalizePathname(b); // Return the matching base if URL starts with it\n return getLevel(singleUrl);\n }\n }\n } else if (\n isNonEmptyString(base) &&\n singleUrl.startsWith(normalizePathname(base))\n ) {\n // If base is a single string, check if URL starts with it\n // return normalizePathname(base); // Return the base if URL starts with it\n return getLevel(singleUrl);\n }\n return null; // Return null if the URL does not match any base\n }\n\n return getLevel(singleUrl);\n }\n\n // If url is an array, process each URL and return an array of results\n if (isArray(url)) {\n const result = url.map(processUrl).filter((r): r is string => !isNull(r));\n\n // Remove duplicates if required\n const uniqueResult = removeDuplicates ? [...new Set(result)] : result;\n\n // If all results are the same, return just the first one\n if (uniqueResult.length === 1) {\n return uniqueResult[0] ?? null;\n }\n\n return uniqueResult;\n }\n\n // If url is a single string, process it and return the result\n return processUrl(url);\n};\n","import { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { hasOwnProp } from \"@/predicates/has/hasOwnProp\";\nimport { isEmptyString } from \"@/predicates/is/isEmptyString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\ntype FormatEnvPortOptions = {\n /** Add prefix with a colon, defaultValue: `false`.\n *\n * @default false\n */\n prefixColon?: boolean;\n};\n\n/** -----------------------------------------------\n * * ***Utility: `formatEnvPort`.***\n * -----------------------------------------------\n * **Retrieves and formats an environment port variable.**\n * - **Behavior:**\n * - Extracts only digits from the input.\n * - If no digits found, returns an empty string.\n * - By default does NOT prefix with a colon.\n * - Use `{ prefixColon: true }` to prefix with a colon.\n * @param {string | null | undefined} envVar The environment variable string.\n * @param {FormatEnvPortOptions} [options] Optional object: `{ prefixColon?: boolean }`.\n * @returns {string} A string like `\":8080\"` or `\"8080\"`, or `\"\"` if no digits.\n * @throws **{@link TypeError | `TypeError`}** if `options` is not an object or `prefixColon` is not boolean.\n * @example\n * formatEnvPort(\"port:8080\");\n * // ➔ \"8080\"\n * formatEnvPort(\"port:8080\", { prefixColon: true });\n * // ➔ \":8080\"\n */\nexport const formatEnvPort = (\n envVar: string | null | undefined,\n options: FormatEnvPortOptions = {}\n): string => {\n if (!isNonEmptyString(envVar)) return \"\"; // Handle empty string case\n\n assertIsPlainObject(options, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const prefixColon = hasOwnProp(options, \"prefixColon\")\n ? options.prefixColon\n : false;\n\n if (!isBoolean(prefixColon)) {\n throw new TypeError(\n `Parameter \\`prefixColon\\` property of the \\`options\\` (second parameter) must be of type \\`boolean\\`, but received: \\`${getPreciseType(\n prefixColon\n )}\\`.`\n );\n }\n\n const digitsOnly = envVar.replace(/\\D+/g, \"\");\n if (isEmptyString(digitsOnly)) return \"\";\n\n return prefixColon ? `:${digitsOnly}` : digitsOnly;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO,aAAa,MAAM;EAG5B,OAAO;;CAIT,OAAO,WAAW,IAAI;;;;;;;;;;;;;;;;;;;;;;;;AC1OxB,MAAa,iBACX,QACA,UAAgC,EAAE,KACvB;CACX,IAAI,CAACS,yCAAiB,OAAO,EAAE,OAAO;CAEtC,4CAAoB,SAAS,EAC3B,UAAU,EAAE,aAAa,gBACvB,oDAAoD,UAAU,sBAAsB,YAAY,MACnG,CAAC;CAEF,MAAM,cAAcC,mCAAW,SAAS,cAAc,GAClD,QAAQ,cACR;CAEJ,IAAI,CAACC,kCAAU,YAAY,EACzB,MAAM,IAAI,UACR,yHAAyHC,uCACvH,YACD,CAAC,KACH;CAGH,MAAM,aAAa,OAAO,QAAQ,QAAQ,GAAG;CAC7C,IAAIC,oCAAc,WAAW,EAAE,OAAO;CAEtC,OAAO,cAAc,IAAI,eAAe"}
|
|
1
|
+
{"version":3,"file":"urls-DCjjZNTH.cjs","names":["isString","isEmptyString","normalizeString","isURL","getPreciseType","safeStableStringify","isUndefined","isNonEmptyString","isFunction","isEmptyValue","isNumber","isError","isNonEmptyString","isFunction","isNonEmptyString","getPreciseType","safeStableStringify","isUndefined","isSet","isArray","isNil","isString","isNull","removeSpaces","isValidDomain","isError","isNonEmptyString","getPreciseType","safeStableStringify","isArray","isString","isNil","isString","isArray","getPreciseType","isNull","isPlainObject","isInteger","safeStableStringify","isBoolean","isNonEmptyArray","joinLines","EOL","isNonEmptyString","isNonEmptyString","hasOwnProp","isBoolean","getPreciseType","isEmptyString"],"sources":["../src/urls/builders/constructURL.ts","../src/urls/extractors/extractURLs.ts","../src/urls/_private/NormalizePathnameError.ts","../src/urls/pathname/normalizePathname.ts","../src/urls/pathname/getFirstPrefixPathname.ts","../src/urls/pathname/getPrefixPathname.ts","../src/urls/utils/formatEnvPort.ts"],"sourcesContent":["import { isURL } from \"@/predicates/is/isURL\";\nimport { isError } from \"@/predicates/is/isError\";\nimport { isNumber } from \"@/predicates/is/isNumber\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isFunction } from \"@/predicates/is/isFunction\";\nimport { isUndefined } from \"@/predicates/is/isUndefined\";\nimport { isEmptyValue } from \"@/predicates/is/isEmptyValue\";\nimport { isEmptyString } from \"@/predicates/is/isEmptyString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { normalizeString } from \"@/strings/sanitizations/normalizeString\";\n\nimport { assertIsArray } from \"@/assertions/objects/assertIsArray\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\nimport { toStringArrayUnRecursive } from \"@/conversions/arrays/casts/toStringArrayUnRecursive\";\n\n/** ----------------------------------------------------------\n * * ***Type-Utility: `QueryParamPairs`.***\n * ----------------------------------------------------------\n * **Represents a non-empty array of key–value pairs.**\n * @description\n * Type for `queryParams` parameter, the second parameter of ***`constructURL` utility function***.\n * - **Behavior:**\n * - Each inner tuple strictly follows the `[string, string | number]` shape.\n * - Ensures the outer array contains **at least one pair** (non-empty).\n * - Commonly used for URL construction parameters,\n * query string segments, or other key–value structured data.\n * @example\n * // ✅ valid usage\n * const params: QueryParamPairs = [\n * [\"foo\", 1],\n * [\"bar\", \"baz\"]\n * ];\n * constructURL(\"https://example.com\", params);\n *\n * // ❌ invalid: must contain at least one item\n * const empty: QueryParamPairs = [];\n *\n * // ❌ invalid: key without value pairs.\n * const empty2: QueryParamPairs = [[\"key\"]];\n */\nexport type QueryParamPairs = [\n [string, string | number],\n ...[string, string | number][]\n];\n\n/** ---------------------------------\n * * ***Utility: `constructURL`.***\n * ---------------------------------\n * **Constructs a valid URL with optional query parameters and allows selective removal of duplicate parameters.**\n * @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.\n * @param {Iterable<[string, string]> | URLSearchParamsIterator<[string, string]> | QueryParamPairs} [queryParams]\n * Additional query parameters to append or overwrite on the URL.\n * - Accepts any iterable of key-value pairs (like `new URLSearchParams().entries()` and `[[string, string | number]...]`).\n * @param {string[]} [removeParams]\n * A list of query parameter keys to remove from the final URL, whether they were in the base URL or provided queryParams.\n * @returns {URL} A new URL object representing the constructed URL with merged and cleaned query parameters.\n * @throws **{@link TypeError | `TypeError`}** 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.\n * @example\n * 1. #### Basic Usage:\n * ```ts\n * constructURL(\n * \"https://example.com/path\",\n * new URLSearchParams({ a: \"1\", b: \"2\" }).entries()\n * );\n * // ➔ URL { href: \"https://example.com/path?a=1&b=2\", ... }\n * ```\n * 2. #### Remove parameters from Base and Added:\n * ```ts\n * // with new URLSearchParams({ ... }).entries();\n * constructURL(\n * \"https://example.com/path?foo=1&bar=2\",\n * new URLSearchParams({ bar: \"ignored\", baz: \"3\" }).entries(),\n * [\"bar\"]\n * );\n * // ➔ URL { href: \"https://example.com/path?foo=1&baz=3\", ... }\n *\n * // with [[string, string | number]...]\n * constructURL(\n * \"https://example.com/path?foo=1&bar=2\",\n * [[\"bar\", \"ignored\"],[\"baz\", 3]],\n * [\"bar\"]\n * );\n * // ➔ URL { href: \"https://example.com/path?foo=1&baz=3\", ... }\n *\n * const params: QueryParamPairs = [\n * [\"foo\", 1],\n * [\"bar\", 2],\n * [\"baz\", 3]\n * ];\n *\n * constructURL(\"https://example.com\", params, [\"bar\"]);\n * // ➔ URL { href: \"https://example.com/?foo=1&baz=3\", ... }\n * ```\n */\nexport const constructURL = (\n baseUrl: string | URL,\n queryParams?:\n | URLSearchParamsIterator<[string, string | number]>\n | QueryParamPairs,\n removeParams?: string[]\n): URL => {\n if (isString(baseUrl)) {\n if (isEmptyString(baseUrl)) {\n throw new TypeError(\n \"First parameter (`baseUrl`) cannot be an empty-string.\"\n );\n }\n baseUrl = normalizeString(baseUrl);\n } else if (!isURL(baseUrl)) {\n throw new TypeError(\n `First parameter (\\`baseUrl\\`) must be of type an URL instance or a \\`string\\` and a non empty-string, but received: \\`${getPreciseType(\n baseUrl\n )}\\`, with current value: \\`${safeStableStringify(baseUrl, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n // Check removeParams\n if (!isUndefined(removeParams)) {\n assertIsArray(removeParams, {\n message: ({ currentType, validType }) =>\n `Third parameter (\\`removeParams\\`) must be of type \\`${validType} of strings\\`, but received: \\`${currentType}\\`.`\n });\n\n if (!removeParams.every((param) => isNonEmptyString(param))) {\n throw new TypeError(\n \"Third parameter (`removeParams`) must be of type `array` and contains `string` only and non empty-string.\"\n );\n }\n }\n\n try {\n // Check queryParams\n if (\n !isUndefined(queryParams) &&\n !isFunction(queryParams[Symbol.iterator])\n ) {\n throw new TypeError(\n `Second parameter (\\`queryParams\\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \\`${getPreciseType(\n queryParams\n )}\\`, with value: \\`${safeStableStringify(queryParams, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n const urlInstance = new URL(baseUrl);\n\n // Add query parameters if provided\n if (!isUndefined(queryParams)) {\n const paramObject = Object.fromEntries(queryParams);\n\n if (!isEmptyValue(paramObject)) {\n // existing params\n const mergedParams = new URLSearchParams(urlInstance.search);\n\n // add / overwrite from queryParams\n for (const [key, value] of Object.entries(paramObject)) {\n if (\n !isNonEmptyString(value) &&\n !isNumber(value, { includeNaN: true })\n ) {\n throw new TypeError(\n `Second parameter (\\`queryParams\\`) must be iterable (like URLSearchParams.entries() or an array of [[string, string | number]...]), but received: \\`${getPreciseType(\n queryParams\n )}\\`, with value: \\`${safeStableStringify(queryParams, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n mergedParams.set(key, String(value));\n }\n\n // Remove specific query parameters if needed\n if (removeParams?.length) {\n toStringArrayUnRecursive(removeParams).map((paramKey) => {\n mergedParams.delete(paramKey);\n });\n }\n\n urlInstance.search = mergedParams.toString();\n }\n }\n\n // Remove query parameters directly from URL if needed\n removeParams?.forEach((param) => urlInstance.searchParams.delete(param));\n\n return urlInstance;\n } catch (error) {\n if (isError(error)) throw error;\n\n throw new Error(\n \"Failed to construct a valid URL in `constructURL()`, Error:\" + error,\n { cause: error }\n );\n }\n};\n","import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ---------------------------------\n * * ***Utility: `extractURLs`.***\n * ---------------------------------\n * **Extracts all valid URLs from a given string.**\n * @description\n * This function scans the input url and returns an array of URLs\n * that match a valid `http` or `https` format.\n * - **Supports:**\n * - Internationalized domain names (IDN), e.g. `https://münich.de`\n * - Unicode & emoji paths, e.g. `https://example.com/🎉/page`\n * - Long URLs with multiple queries & fragments, e.g. `https://example.com/path?foo=1#hash`\n * - **Ignores:**\n * - Non-string inputs\n * - Empty or whitespace-only strings\n * - Non-HTTP(S) protocols (ftp, mailto, etc)\n * @param {string | null | undefined} url - The input string containing potential URLs.\n * @returns {string[] | null} An array of extracted URLs or `null` if no URLs are found.\n * @example\n * extractURLs(\"Visit https://example.com and https://例子.公司\");\n * // ➔ [\"https://example.com\", \"https://例子.公司\"]\n * extractURLs(\"Here: https://example.com/🎉/page\");\n * // ➔ [\"https://example.com/🎉/page\"]\n * extractURLs(\"ftp://example.com http://example.com\");\n * // ➔ [\"http://example.com\"]\n */\nexport const extractURLs = (\n url: string | null | undefined\n): string[] | null => {\n if (!isNonEmptyString(url)) return null;\n\n let decoded;\n try {\n decoded = decodeURIComponent(url);\n } catch {\n return null;\n }\n\n // Core regex with lookahead\n const urlPattern = /https?:\\/\\/.*?(?=https?:\\/\\/|\\s|$)/g;\n const matches = decoded.match(urlPattern);\n if (!matches) return null;\n\n // Cleanup trailing punctuation and validation protocol\n const cleaned = matches\n .map((url) => url.replace(/[.,;:!?)]*$/, \"\"))\n .filter((url) => {\n try {\n const u = new URL(url);\n return u.protocol === \"http:\" || u.protocol === \"https:\";\n } catch {\n return false;\n }\n });\n\n return cleaned.length ? cleaned : null;\n};\n","import { isFunction } from \"@/predicates/is/isFunction\";\n\n/** ---------------------------------\n * * ***Custom Error for Pathname Normalization Failures***\n * ---------------------------------\n */\nexport class NormalizePathnameError extends Error {\n /** ---------------------------------\n * * ***The original error that triggered this normalization failure.***\n * ---------------------------------\n *\n * **Always available for backward compatibility.**\n */\n public readonly originalError: Error;\n\n constructor(message: string, originalError: Error) {\n // Pass a `cause` option if the runtime supports it (ignored by older engines).\n super(message, isFunction(Error) ? { cause: originalError } : undefined);\n\n this.name = \"NormalizePathnameError\";\n this.originalError = originalError;\n\n // Preserve stack trace when available (Node.js & modern browsers).\n if (isFunction(Error.captureStackTrace)) {\n Error.captureStackTrace(this, NormalizePathnameError);\n } else {\n // Fallback for very old environments.\n this.stack = new Error(message).stack;\n }\n }\n\n /** ---------------------------------\n * * ***Safe JSON representation for logging or IPC.***\n * ---------------------------------\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n stack: this.stack,\n originalError: {\n name: this.originalError.name,\n message: this.originalError.message,\n stack: this.originalError.stack\n }\n };\n }\n}\n","import type { OverrideTypes, Prettify } from \"@rzl-zone/ts-types-plus\";\n\nimport { isSet } from \"@/predicates/is/isSet\";\nimport { isNil } from \"@/predicates/is/isNil\";\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isError } from \"@/predicates/is/isError\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isValidDomain } from \"@/predicates/is/isValidDomain\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\nimport { removeSpaces } from \"@/strings/sanitizations/removeSpaces\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\nimport { NormalizePathnameError } from \"../_private/NormalizePathnameError\";\nimport { isUndefined } from \"@/predicates/is/isUndefined\";\n\n/** Options when `keepNullable` is false (default).\n *\n * Returns `defaultPath` if `pathname` is empty or invalid.\n */\ntype UnKeepNullableOptions = {\n /** * ***Fallback value returned if `pathname` is empty-string or invalid.***\n *\n * Must be a **`non-empty string`**, defaultValue: `\"/\"`.\n *\n * @default \"/\"\n */\n defaultPath?: string;\n\n /** * ***Whether to preserve `null` or `undefined`, defaultValue: `false`.***\n *\n * @default false\n */\n keepNullable?: false;\n};\n\n/** Options when `keepNullable` is true.\n *\n * Preserves `null` or `undefined` instead of returning `defaultPath`.\n */\ntype KeepNullableOptions = {\n /** * ***Fallback path is ignored when `keepNullable` is true **(except if\n * `pathname` is empty-string or invalid, even this `true`)**,\n * defaultValue: `\"/\"`.***\n *\n * @default \"/\"\n */\n defaultPath?: string;\n\n /** * ***Preserve `null` or `undefined` as-is if `true` (defaultValue: `false`).***\n *\n * - ***⚠️ Notes:***\n * - Keep returning `defaultPath` if `pathname` is empty-string, even this `true`.\n *\n * **Must be `true` in this type.**\n *\n * @default false\n */\n keepNullable?: true;\n};\n\ntype MainNormalizePathnameOptions = {\n /** --------------------------------------------------------\n * * ***Preserve trailing slash at the end of the normalized pathname, defaultValue: `false`.***\n * --------------------------------------------------------\n *\n * @default `false`\n */\n keepTrailingSlash?: boolean;\n\n /** --------------------------------------------------------\n * * ***Allow special localhost domain at the beginning of the pathname.***\n * --------------------------------------------------------\n * @description\n * If `true`, the first segment of the pathname that is `/localhost` or `localhost`\n * (with or without a port, e.g., `localhost:3000`) will be treated as a special domain\n * and **removed** from the normalized pathname.\n *\n * - **Examples (`localhostDomain: true`)**:\n * - `\"/localhost/path\"` ➔ `\"/path\"`\n * - `\"localhost:3000/path\"` ➔ `\"/path\"`\n * - `\"localhost\"` ➔ `\"/\"` (entire path removed)\n *\n * - Only the **first path segment** is affected. Any subsequent occurrences of `\"localhost\"`\n * will remain intact.\n *\n * @default false\n */\n localhostDomain?: boolean;\n\n /**\n * --------------------------------------------------------\n * * ***Custom list of file extensions that prevent the first path segment from being treated as a domain.***\n * --------------------------------------------------------\n *\n * **Description:**\n * - The first segment of a pathname is often interpreted as a domain (e.g., `example.com`).\n * - If this first segment ends with any of the extensions listed here, it will **not** be considered a domain,\n * and will instead be preserved as part of the relative path.\n * - This is useful for cases where filenames appear at the start of a path and you want them treated as relative paths,\n * such as `\"image.png?version=2\"` or `\"archive.tar.gz#download\"`.\n * - Only the **first path segment** is affected; all other segments are processed normally.\n * - **Ignored** if:\n * 1. The pathname starts with a full URL protocol (`http://` or `https://`), e.g., `\"https://example.com/file.png\"`.\n * 2. The first path segment is already a valid domain, e.g., `\"example.com/image.png\"`.\n *\n * **Type & Validation:**\n * - Must be a `Set<string>` or `string[]`.\n * - Each string **must include the leading dot**, e.g., `.png`, `.tar.gz`.\n * - Multi-part extensions (like `.tar.gz`, `.tar.bz`) are supported.\n * - Throws a **TypeError** if:\n * 1. The type is not a `Set<string>` or `string[]`.\n * 2. Any string in the array/set is empty.\n * 3. Any string does not start with a dot (`.`).\n *\n * **Usage Notes:**\n * - Only applied when the first segment is otherwise domain-like **and** pathname is relative or domain-like without protocol.\n * - Query strings (`?x=1`) and hash fragments (`#section`) are preserved.\n *\n * **Examples (relative paths, option active):**\n * ```ts\n * normalizePathname(\"image.png?version=2\", {\n * ignoreDomainExtensions: [\".png\", \".jpg\"]\n * });\n * // ➔ \"/image.png?version=2\"\n *\n * normalizePathname(\"archive.tar.gz#download\", {\n * ignoreDomainExtensions: new Set([\".tar.gz\"])\n * });\n * // ➔ \"/archive.tar.gz#download\"\n *\n * normalizePathname(\"script.js?module=true#top\", {\n * ignoreDomainExtensions: [\".js\"]\n * });\n * // ➔ \"/script.js?module=true#top\"\n * ```\n *\n * **Examples (full URL or explicit domain - option ignored):**\n * ```ts\n * normalizePathname(\"https://example.com/image.png?version=2\", {\n * ignoreDomainExtensions: [\".png\"]\n * });\n * // ➔ \"/image.png?version=2\" // URL is parsed normally; ignoreDomainExtensions has no effect\n *\n * normalizePathname(\"example.com/script.js?module=true#top\", {\n * ignoreDomainExtensions: [\".js\"]\n * });\n * // ➔ \"/script.js?module=true#top\" // domain recognized; option ignored\n * ```\n *\n * **Notes:**\n * - Only the **first path segment** is checked.\n * - Prevents false-positive domain stripping for filenames that look like domains.\n * - Throws **TypeError** if invalid type or invalid string is provided.\n *\n * @default undefined (feature inactive if not provided)\n */\n ignoreDomainExtensions?: Set<string> | string[];\n};\n\n/** Options for main `normalizePathname`.\n *\n * Combines `UnKeepNullableOptions` or `KeepNullableOptions` with trailing slash control.\n */\ntype NormalizePathnameOptions = Prettify<\n MainNormalizePathnameOptions & (UnKeepNullableOptions | KeepNullableOptions)\n>;\n\ntype NormalizePathnameOptionsKeepNullableTrue = MainNormalizePathnameOptions &\n KeepNullableOptions;\ntype NormalizePathnameOptionsKeepNullableFalse = MainNormalizePathnameOptions &\n UnKeepNullableOptions;\n\ntype ResUnKeepNullable<T> = T extends undefined\n ? string\n : T extends null\n ? string\n : T extends null | undefined\n ? string\n : string;\n\ntype ResKeepNullable<T> = T extends string\n ? string\n : T extends undefined\n ? undefined\n : T extends null\n ? null\n : T extends null | undefined\n ? null | undefined\n : string | null | undefined;\n\n/** --------------------------------------------------------\n * * ***Utility: `normalizePathname`.***\n * --------------------------------------------------------\n *\n * - **Description:**\n * Normalizes any pathname or URL string to a clean, predictable format.\n * Useful for routing, file paths, and URL handling.\n * - Handles:\n * - Leading/trailing spaces\n * - Internal spaces in path segments\n * - Redundant slashes (`//`)\n * - Full URLs vs relative paths\n * - Query (`?`) and hash (`#`) preservation\n * - Unicode & emoji characters\n * - Optional nullable preservation (`keepNullable`)\n * - Optional trailing slash preservation (`keepTrailingSlash`)\n * - Optional removal of localhost first segment (`localhostDomain`)\n * - Prevention of false-positive domain stripping (`ignoreDomainExtensions`)\n *\n * - **Key Steps Internally:**\n * 1. Validate `options` (plain object, correct types)\n * 2. Validate `defaultPath` (non-empty string if `keepNullable` is false)\n * 3. Validate `ignoreDomainExtensions` (Set<string> | string[], each starts with `.`)\n * 4. Handle nullable:\n * - Returns `null` / `undefined` if `keepNullable: true`\n * - Otherwise uses `defaultPath`\n * 5. Trim spaces, remove internal spaces\n * 6. If full URL: parse using `URL` constructor\n * 7. If relative path or domain-like:\n * - Remove `localhost`/`localhost:port` if `localhostDomain`\n * - Remove first segment if domain-like and **not** in `ignoreDomainExtensions`\n * 8. Normalize slashes\n * 9. Ensure leading slash\n * 10. Handle trailing slash\n * 11. Decode Unicode safely\n * 12. Return normalized pathname + search + hash\n *\n * - **Error Handling:**\n * - **TypeError**:\n * - `defaultPath` invalid (non-string or empty) when `keepNullable: false`\n * - `keepNullable`, `keepTrailingSlash`, `localhostDomain` not boolean\n * - `ignoreDomainExtensions` invalid\n * - **NormalizePathnameError** (extends ***Error***):\n * - Invalid URL parsing\n * - Unexpected normalization errors\n *\n * - **Options:**\n * ```ts\n * {\n * // fallback if invalid path, default: \"/\"\n * defaultPath?: string;\n * // preserve null/undefined, default: false\n * keepNullable?: boolean;\n * // preserve trailing slash, default: false\n * keepTrailingSlash?: boolean;\n * // remove localhost:port first segment, default: false\n * localhostDomain?: boolean;\n * // prevent domain stripping, default: undefined\n * ignoreDomainExtensions?: Set<string> | string[];\n * }\n * ```\n *\n * @example\n * // Basic path cleaning\n * normalizePathname(\" /foo//bar \");\n * // ➔ \"/foo/bar\"\n *\n * // Trailing slash control\n * normalizePathname(\"/api//v1//user//\", { keepTrailingSlash: true });\n * // ➔ \"/api/v1/user/\"\n * normalizePathname(\"/api//v1//user//\", { keepTrailingSlash: false });\n * // ➔ \"/api/v1/user\"\n *\n * // Full URL normalization\n * normalizePathname(\"https://example.com//path///to/resource?x=1#hash\");\n * // ➔ \"/path/to/resource?x=1#hash\"\n *\n * // Null/undefined preservation\n * normalizePathname(null, { keepNullable: true });\n * // ➔ null\n * normalizePathname(undefined, { keepNullable: true });\n * // ➔ undefined\n *\n * // Default fallback\n * normalizePathname(\"\", { defaultPath: \"/home\" });\n * // ➔ \"/home\"\n *\n * // Localhost removal\n * normalizePathname(\"localhost:3000/path/to/resource\", { localhostDomain: true });\n * // ➔ \"/path/to/resource\"\n *\n * // Prevent false-positive domain stripping\n * normalizePathname(\"archive.tar.gz#download\", { ignoreDomainExtensions: [\".tar.gz\"] });\n * // ➔ \"/archive.tar.gz#download\"\n * normalizePathname(\"image.png?version=2\", { ignoreDomainExtensions: [\".png\"] });\n * // ➔ \"/image.png?version=2\"\n *\n * // Emojis and Unicode\n * normalizePathname(\"🔥//deep//path///🚀\");\n * // ➔ \"/🔥/deep/path/🚀\"\n *\n * // Query-only or hash-only\n * normalizePathname(\"?page=2\");\n * // ➔ \"/?page=2\"\n * normalizePathname(\"#section3\");\n * // ➔ \"/#section3\"\n *\n * // Complex nested paths\n * normalizePathname(\" //nested///folder//file.txt \");\n * // ➔ \"/nested/folder/file.txt\"\n *\n * // Invalid URL triggers error\n * try {\n * normalizePathname(\"http://\");\n * } catch (e) {\n * // console.log(e);\n * }\n *\n * // First segment is domain but ignored due to extension\n * normalizePathname(\"example.tar.bz/file\", { ignoreDomainExtensions: [\".tar.bz\"] });\n * // ➔ \"/example.tar.bz/file\"\n */\nexport function normalizePathname<T>(\n pathname: T,\n options?: NormalizePathnameOptionsKeepNullableFalse\n): ResUnKeepNullable<T>;\nexport function normalizePathname<T>(\n pathname: T,\n options?: NormalizePathnameOptionsKeepNullableTrue\n): ResKeepNullable<T>;\nexport function normalizePathname(\n pathname: unknown,\n options: NormalizePathnameOptions = {\n defaultPath: \"/\",\n keepNullable: false\n }\n): string | null | undefined {\n assertIsPlainObject(options, {\n message({ currentType, validType }) {\n return `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n const {\n defaultPath = \"/\",\n keepNullable = false,\n keepTrailingSlash = false,\n localhostDomain = false,\n ignoreDomainExtensions = undefined\n } = options;\n\n // Validate defaultPath\n if (!isNonEmptyString(defaultPath)) {\n throw new TypeError(\n `Parameter \\`defaultPath\\` property of the \\`options\\` (second parameter) must be of type \\`string\\` and not empty-string, but received: \\`${getPreciseType(\n defaultPath\n )}\\`, with value: \\`${safeStableStringify(defaultPath, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n assertIsBoolean(keepNullable, {\n message({ currentType, validType }) {\n return `Parameter \\`keepNullable\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n assertIsBoolean(keepTrailingSlash, {\n message({ currentType, validType }) {\n return `Parameter \\`keepTrailingSlash\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n assertIsBoolean(localhostDomain, {\n message({ currentType, validType }) {\n return `Parameter \\`localhostDomain\\` property of the \\`options\\` (second parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`;\n }\n });\n\n let ignoreDomainExtsSet: Set<string> | undefined;\n\n if (!isUndefined(ignoreDomainExtensions)) {\n if (!isSet(ignoreDomainExtensions) && !isArray(ignoreDomainExtensions)) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions\\` must be of type a \\`Set<string>\\` or \\`string[]\\`, but received: \\`${getPreciseType(\n ignoreDomainExtensions\n )}\\`.`\n );\n }\n\n ignoreDomainExtsSet = isSet(ignoreDomainExtensions)\n ? ignoreDomainExtensions\n : new Set(ignoreDomainExtensions);\n\n // validation every ext\n let idx = 0;\n for (const ext of ignoreDomainExtsSet) {\n if (!isNonEmptyString(ext)) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions[${idx}]\\` must be a \\`string\\` and \\`non-empty string\\`, but received: \\`${safeStableStringify(\n ext,\n { keepUndefined: true }\n )}\\`.`\n );\n }\n if (!ext.startsWith(\".\")) {\n throw new TypeError(\n `Parameter \\`ignoreDomainExtensions[${idx}]\\` must start with a dot (.), but received: ${safeStableStringify(\n ext,\n { keepUndefined: true }\n )}`\n );\n }\n idx++;\n }\n }\n\n try {\n if (keepNullable && (isNil(pathname) || !isString(pathname))) {\n if (isNull(pathname)) return null;\n return undefined;\n }\n\n // If the pathname is invalid (null, undefined, or an empty string), return the default value, only if `keepNullable` is false\n let currentPathName: string = isNonEmptyString(pathname)\n ? pathname\n : defaultPath;\n\n // Trim spaces from the string (only trim leading and trailing spaces)\n currentPathName = removeSpaces(currentPathName, { trimOnly: true }).replace(\n /\\s+/g,\n \"\"\n ); // remove all space\n\n currentPathName = stripLeadingDomain(currentPathName, {\n keepTrailingSlash,\n localhostDomain,\n ignoreDomainExtensions: ignoreDomainExtsSet\n });\n\n let _pathName: string = currentPathName;\n let search = \"\";\n let hash = \"\";\n\n // relative path: extract search/hash manually\n const searchIndex = currentPathName.indexOf(\"?\");\n const hashIndex = currentPathName.indexOf(\"#\");\n\n if (searchIndex !== -1) {\n search = currentPathName.slice(\n searchIndex,\n hashIndex !== -1 ? hashIndex : undefined\n );\n }\n if (hashIndex !== -1) {\n hash = currentPathName.slice(hashIndex);\n }\n\n const endIndex = Math.min(\n searchIndex !== -1 ? searchIndex : currentPathName.length,\n hashIndex !== -1 ? hashIndex : currentPathName.length\n );\n _pathName = currentPathName.slice(0, endIndex);\n\n // Normalize slashes\n _pathName = \"/\" + _pathName.replace(/^\\/+/, \"\").replace(/\\/{2,}/g, \"/\");\n\n // Trailing slash\n if (!keepTrailingSlash && _pathName !== \"/\") {\n _pathName = _pathName.replace(/\\/+$/, \"\");\n }\n\n // Decode Unicode safely\n _pathName = decodeUnicodeSequences(_pathName);\n search = decodeUnicodeSequences(search);\n hash = decodeUnicodeSequences(hash);\n\n return _pathName + search + hash;\n } catch (error) {\n // Handle any errors that occur during processing\n throwError(error);\n }\n}\n\n// --- Internal Helper Utils ----\n\n/**\n * @internal\n */\nconst decodeUnicodeSequences = (str: string): string => {\n return str.replace(/(?:%(?:[0-9A-F]{2})){2,}/gi, (match) => {\n try {\n const decoded = decodeURIComponent(match);\n // eslint-disable-next-line no-control-regex\n if (/^[\\u0000-\\u007F]+$/.test(decoded)) return match;\n // eslint-enable-next-line no-control-regex\n return decoded;\n } catch {\n return match;\n }\n });\n};\n\n/**\n * @internal\n */\nconst stripLeadingDomain = (\n path: string,\n options: OverrideTypes<\n MainNormalizePathnameOptions,\n { ignoreDomainExtensions?: Set<string> }\n >\n): string => {\n let currentPath = path;\n\n const { ignoreDomainExtensions, localhostDomain } = options;\n\n // Full URL (protocol) -> only normalize path, ignore ignoreDomainExtensions\n if (/^https?:\\/\\//i.test(currentPath)) {\n try {\n const url = new URL(currentPath);\n currentPath =\n url.pathname.replace(/^\\/+/, \"\").replace(/\\/{2,}/g, \"/\") +\n url.search +\n url.hash;\n\n return ensureLeadingSlash(currentPath);\n } catch (error) {\n // fallback: keep as-is\n // Handle any errors that occur during processing\n throwError(error);\n }\n }\n\n // relative path: remove leading slash\n if (currentPath.startsWith(\"/\")) {\n currentPath = currentPath.replace(/\\/{2,}/g, \"/\").slice(1);\n }\n\n // take first segment\n const segments = currentPath.split(\"/\");\n const firstPart = segments[0];\n const domainPart = firstPart?.split(\":\")[0];\n\n const isDomain = isValidDomain(domainPart, {\n subdomain: true,\n allowUnicode: true,\n wildcard: true,\n allowLocalhost: localhostDomain,\n allowPort: true,\n allowProtocol: true,\n topLevel: false\n });\n\n // ignoreDomainExtensions only applies for relative/non-protocol paths\n let hasIgnoredExtension = false;\n if (ignoreDomainExtensions) {\n for (const ext of ignoreDomainExtensions) {\n if (firstPart?.endsWith(ext)) {\n hasIgnoredExtension = true;\n break;\n }\n }\n }\n\n if (isDomain && !hasIgnoredExtension) {\n segments.shift(); // remove first segment\n }\n\n return ensureLeadingSlash(segments.join(\"/\"));\n};\n\n/**\n * @internal\n */\nconst ensureLeadingSlash = (path: string): string => {\n if (!path.startsWith(\"/\")) path = \"/\" + path;\n return path;\n};\n\n/**\n * @internal\n */\nconst throwError = (error: unknown): never => {\n // Handle any errors that occur during processing\n const err = isError(error)\n ? error\n : new Error(\"Unknown error from function `normalizePathname()`.\");\n throw new NormalizePathnameError(\n `Failed to normalize pathname in function \\`normalizePathname()\\`: ${err.message}`,\n err\n );\n};\n","import { isNil } from \"@/predicates/is/isNil\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\nimport { normalizePathname } from \"./normalizePathname\";\n\n/** --------------------------------------------------------\n * * ***Utility: `getFirstPrefixPathname`.***\n * --------------------------------------------------------\n * **Extract First Valid Prefix from Path Array or String.**\n * - **Main Purpose:**\n * - This function helps extract the first valid URL prefix from various possible inputs.\n * - It is especially useful in routing systems, middleware, or frontend apps that need to\n * decide layout, active navigation, or permissions based on the first segment (or prefix) of a pathname.\n * - **Typical uses include:**\n * - Determining which layout to render (e.g., `/admin` vs `/dashboard` vs `/`).\n * - Highlighting the active menu item in a sidebar based on the current URL.\n * - Enforcing route guards or access controls depending on the URL prefix.\n * - Parsing multi-level route prefixes and selecting the most relevant one.\n * - **Behavior:**\n * - It works as follows:\n * - If `result` is an array of strings, it normalizes each element and returns\n * the first non-root path (i.e., not just `\"/\"`).\n * - If all items normalize to `\"/\"`,\n * it returns the `defaultValue` (normalized).\n * - If `result` is a single string, it normalizes it and returns it if valid,\n * otherwise falls back to the normalized `defaultValue`.\n * - If `result` is `null` or `undefined`, it returns the normalized `defaultValue`.\n * - **Validation & Errors:**\n * - Throws a `TypeError` if:\n * - `defaultValue` is not a string or empty-string.\n * - `result` is an array that contains non-string elements.\n * - `result` is a value that is neither `string`, `string[]`, nor `null`.\n * @example\n * 1. #### For React (*Determining layout*):\n * ```ts\n * const prefix = getFirstPrefixPathname(\n * getPrefixPathname(\n * \"/admin/settings\",\n * [\"/admin\", \"/dashboard\"]\n * )\n * );\n *\n * if (prefix === \"/admin\") {\n * renderAdminLayout();\n * }\n * ```\n *\n * 2. #### Setting active menu state:\n * ```ts\n * const activeSection = getFirstPrefixPathname([\"\", \"/dashboard\", \"/profile\"]);\n * // ➔ \"/dashboard\"\n * ```\n *\n * 3. #### Providing graceful fallback:\n * ```ts\n * const section = getFirstPrefixPathname([], \"/home\");\n * // ➔ \"/home\"\n * ```\n * 4. #### ✅ Using with an Array of Pathnames:\n * ```ts\n * const result = getPrefixPathname([\" \", \"/dashboard\", \"/settings\"]);\n * console.log(getFirstPrefixPathname(result));\n * // ➔ \"/dashboard\"\n * ```\n *\n * 5. #### ✅ Using with Single String:\n * ```ts\n * console.log(getFirstPrefixPathname(\"/profile/settings\"));\n * // ➔ \"/profile/settings\"\n * console.log(getFirstPrefixPathname(\" \"));\n * // ➔ \"/\"\n * ```\n *\n * 6. #### ✅ Fallback to Custom Default:\n * ```ts\n * console.log(getFirstPrefixPathname([\" \", \"\"], \"/home\"));\n * // ➔ \"/home\"\n * console.log(getFirstPrefixPathname(null, \"/dashboard\"));\n * // ➔ \"/dashboard\"\n * ```\n *\n * 7. #### ✅ Throws on Invalid Input:\n * ```ts\n * getFirstPrefixPathname([1, 2] as any); // ➔ ❌ throws TypeError\n * getFirstPrefixPathname({} as any); // ➔ ❌ throws TypeError\n * getFirstPrefixPathname(null, \" \"); // ➔ ❌ throws TypeError\n * ```\n * @param {string | string[] | null | undefined} result\n * ***The pathname(s) to process, can be:***\n * - A string path (e.g. `\"/profile\"`),\n * - An array of string paths (e.g. `[\" \", \"/dashboard\"]`),\n * - Or `null`.\n * @param {string} [defaultValue=\"/\"]\n * ***A custom default path to use if `result` is null or no valid prefix is found, behavior:***\n * - Must be a string and non-empty string.\n * - Defaults to `\"/\"`.\n * @returns {string}\n * ***The first valid normalized pathname, or the normalized default.***\n * @throws **{@link TypeError | `TypeError`}** ***if `result` is not a valid type, or `defaultValue` is not a string or empty-string.***\n */\nexport const getFirstPrefixPathname = (\n result: string | string[] | null | undefined,\n defaultValue: string = \"/\"\n): string => {\n if (!isNonEmptyString(defaultValue)) {\n throw new TypeError(\n `Second parameter (\\`defaultValue\\`) must be of type \\`string\\` and not an \\`empty-string\\`, but received: \\`${getPreciseType(\n defaultValue\n )}\\`, with value: \\`${safeStableStringify(defaultValue, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n if (isArray(result)) {\n if (!result.every((item) => isString(item))) {\n throw new TypeError(\n `First parameter (\\`result\\`) must be of type \\`string\\` or \\`array of string\\`, but received: \\`${getPreciseType(\n result\n )}\\`, with value: \\`${safeStableStringify(result, {\n keepUndefined: true\n })}\\`.`\n );\n }\n\n for (const item of result) {\n const normalized = normalizePathname(item);\n if (normalized !== \"/\") {\n return normalized;\n }\n }\n return normalizePathname(defaultValue);\n }\n\n if (isString(result)) {\n const normalized = normalizePathname(result);\n return normalized !== \"/\" ? normalized : normalizePathname(defaultValue);\n }\n\n if (!isNil(result)) {\n throw new TypeError(\n `First parameter (\\`result\\`) must be of type \\`string\\`, \\`array-string\\`, \\`null\\` or \\`undefined\\`, but received: \\`${getPreciseType(\n result\n )}\\`.`\n );\n }\n\n return normalizePathname(defaultValue);\n};\n","import { joinLines, EOL } from \"@rzl-zone/build-tools/utils\";\n\nimport { isNull } from \"@/predicates/is/isNull\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isString } from \"@/predicates/is/isString\";\nimport { isInteger } from \"@/predicates/is/isInteger\";\nimport { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyArray } from \"@/predicates/is/isNonEmptyArray\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\nimport { normalizePathname } from \"./normalizePathname\";\n\ntype GetPrefixPathnameOptions = {\n /** The number of levels to include in the prefix (default is `1`).\n *\n * - For example, with `levels = 2`, the function will return the first two parts of the URL.\n *\n * @default 1\n */\n levels?: number;\n /** Whether to remove duplicates from the result if multiple URLs are passed (default is `true`).\n *\n * @default true\n */\n removeDuplicates?: boolean;\n};\n\n/** --------------------------------------------------------\n * * ***Utility: `getPrefixPathname`.***\n * --------------------------------------------------------\n * **Get Prefix from URL with Optional Base or Auto-detection (Supports String or Array of URLs).**\n * - **This function extracts the prefix from one or more URLs. It can either:**\n * - Use a provided `base` string or an array of strings to check and return the matching prefix.\n * - Automatically detect the prefix if no `base` is provided by analyzing the first part of the URL.\n * - **The function is flexible and can handle both scenarios:**\n * 1. **When the base is provided as a single string or an array of strings**:\n * - The function will check if the URL starts with one of the provided base(s) and return the matching base.\n * 2. **When the base is not provided**:\n * - The function will automatically detect the prefix by splitting the URL or using a regex.\n * - **Important Notes**:\n * - If a base (or an array of bases) is provided, the URL must start with one of the given base(s).\n * - If no base is provided, the function will attempt to detect the prefix automatically.\n * - The `url` parameter can be either a string or an array of strings.\n * - Supports deduplication of results (enabled by default).\n * - Automatically returns a single string if only one unique result exists after processing.\n * @param {string|string[]} url\n * ***The full URL(s) from which the prefix should be extracted, can be a `string` or an `array of strings`.***\n * @param {string|string[]|null} [base=null]\n * ***The base URL(s) (e.g., `\"/settings\"`), behavior:***\n * - It can be a `string`, an `array of strings`, or `null`.\n * - If `provided`, it will be used to check the URL(s).\n * - If `not provided`, the prefix will be auto-detected.\n * @param {GetPrefixPathnameOptions} [options]\n * ***Additional options object:***\n * - `levels` (default `1`): The number of segments to include when auto-detecting the prefix (e.g. `/foo/bar` for `levels: 2`).\n * - `removeDuplicates` (default `true`): Whether to remove duplicate prefixes from the final array result.\n * @returns {string|string[]|null}\n * ***Returns one of:***\n * - A single string if only one unique prefix/base is found.\n * - An array of strings if multiple different prefixes/bases are found.\n * - `null` if no matching base is found when using `base`.\n * @throws **{@link TypeError | `TypeError`}**\n * ***if:***\n * - `url` is `not a string` or `not an array of strings`.\n * - `base` is `not a string`, `array of strings`, or `null`.\n * - `options` is `not an object`.\n * - `levels` is `not a number`.\n * - `removeDuplicates` is `not a boolean`.\n * @example\n * - #### ✅ **Correct Usage (With an Array of URLs and Base):**\n * ```ts\n * const routes = [\n * \"/settings/profile\",\n * \"/settings/password\",\n * \"/settings/other-path\",\n * \"/other-path/xyz\",\n * ];\n *\n * // With base provided as a string\n * routes.forEach(route => {\n * console.log(getPrefixPathname(route, '/settings'));\n * // ➔ \"/settings\"\n * });\n *\n * // With base provided as an array\n * routes.forEach(route => {\n * console.log(getPrefixPathname(route, ['/settings', '/admin']));\n * // ➔ \"/settings\" or \"/admin\" depending on the current URL.\n * });\n * ```\n * - #### ✅ **Correct Usage (With Single URL and Single Base):**\n * ```ts\n * const result = getPrefixPathname(\"/settings/profile\", \"/settings\");\n * console.log(result); // ➔ \"/settings\"\n * ```\n * - #### ✅ **Correct Usage (With Multiple URLs and Single Base):**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/password\"],\n * \"/settings\"\n * );\n * console.log(result); // ➔ \"/settings\"\n *\n * const result2 = getPrefixPathname(\n * [\"/settings/profile\", \"/other/password\"],\n * \"/other\"\n * );\n * console.log(result2); // ➔ \"/other\"\n * ```\n * - #### ✅ **Correct Usage (With Multiple URLs and Multiple Bases)**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/admin/password\"],\n * [\"/settings\", \"/admin\"]\n * );\n * console.log(result); // ➔ [\"/settings\", \"/admin\"]\n * ```\n * - #### ✅ **Auto-detection of Prefix**\n * ```ts\n * const result = getPrefixPathname(\"/settings/profile\");\n * console.log(result); // ➔ \"/settings\"\n *\n * const result2 = getPrefixPathname(\n * \"/settings/profile/info\",\n * null,\n * { levels: 2 }\n * );\n * console.log(result2); // ➔ \"/settings/profile\"\n * ```\n * - #### ✅ **Multiple URLs with Auto-detection**\n * ```ts\n * const result = getPrefixPathname([\"/admin/profile\", \"/settings/password\"]);\n * console.log(result); // ➔ [\"/admin\", \"/settings\"]\n * ```\n * - #### ✅ **Handling Duplicates**\n * ```ts\n * const result = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/password\"],\n * \"/settings\"\n * );\n * console.log(result); // ➔ \"/settings\" (deduped to single string)\n *\n * const result2 = getPrefixPathname(\n * [\"/settings/profile\", \"/settings/profile\"],\n * \"/settings\",\n * { removeDuplicates: false }\n * );\n * console.log(result2); // ➔ [\"/settings\", \"/settings\"]\n * ```\n * - #### ❌ **Incorrect Usage (URL Does Not Match Base)**\n * ```ts\n * const result = getPrefixPathname(\"/other-path/profile\", \"/settings\");\n * console.log(result); // ➔ null\n * ```\n */\nexport const getPrefixPathname = (\n url: string | string[],\n base: string | string[] | null = null,\n options: GetPrefixPathnameOptions = {}\n): string | string[] | null => {\n const errors: string[] = [];\n\n if (!isString(url) && !isArray(url)) {\n errors.push(\n `First parameter (\\`url\\`) must be of type \\`string\\` or \\`array-string\\`, but received: \\`${getPreciseType(\n url\n )}\\`.`\n );\n }\n if (!isString(base) && !isArray(base) && !isNull(base)) {\n errors.push(\n `Second parameter (\\`base\\`) must be of type \\`string\\`, \\`array-string\\` or \\`null\\`, but received: \\`${getPreciseType(\n base\n )}\\`.`\n );\n }\n if (!isPlainObject(options)) {\n errors.push(\n `Second parameter (\\`options\\`) must be of type \\`plain-object\\`, but received: \\`${getPreciseType(\n options\n )}\\`.`\n );\n }\n\n const { levels = 1, removeDuplicates = true } = options;\n\n if (!isInteger(levels) || (isInteger(levels) && levels < 0)) {\n errors.push(\n `Parameter \\`levels\\` property of the \\`options\\` (second parameter) must be of type \\`integer-number\\` and minimum is \\`0\\`, but received: \\`${getPreciseType(\n levels\n )}\\`, with value: \\`${safeStableStringify(levels, {\n keepUndefined: true\n })}\\`.`\n );\n }\n if (!isBoolean(removeDuplicates)) {\n errors.push(\n `Parameter \\`removeDuplicates\\` property of the \\`options\\` (second parameter) must be of type \\`boolean\\`, but received: \\`${getPreciseType(\n removeDuplicates\n )}\\`.`\n );\n }\n if (isNonEmptyArray(errors)) {\n throw new TypeError(\n joinLines(\n \"Invalid parameter(s) in `getPrefixPathname` function:\",\n `- ${errors.join(`${EOL}- `)}`\n )\n );\n }\n\n // Helper function to process a single URL\n function getLevel(singleUrl: string) {\n // If no base is provided, detect the base automatically\n const parts = normalizePathname(singleUrl).split(\"/\").filter(Boolean); // Split URL into parts\n\n // Return the first `levels` parts as the prefix\n return `/${parts.slice(0, levels).join(\"/\")}`;\n }\n\n // Helper function to process a single URL\n function processUrl(singleUrl: string): string | null {\n // If a base is provided, check if URL starts with one of the bases\n if (base) {\n singleUrl = normalizePathname(singleUrl);\n\n if (isArray(base)) {\n // Check if the URL starts with any of the base values in the array\n for (const b of base) {\n if (singleUrl.startsWith(normalizePathname(b))) {\n // return normalizePathname(b); // Return the matching base if URL starts with it\n return getLevel(singleUrl);\n }\n }\n } else if (\n isNonEmptyString(base) &&\n singleUrl.startsWith(normalizePathname(base))\n ) {\n // If base is a single string, check if URL starts with it\n // return normalizePathname(base); // Return the base if URL starts with it\n return getLevel(singleUrl);\n }\n return null; // Return null if the URL does not match any base\n }\n\n return getLevel(singleUrl);\n }\n\n // If url is an array, process each URL and return an array of results\n if (isArray(url)) {\n const result = url.map(processUrl).filter((r): r is string => !isNull(r));\n\n // Remove duplicates if required\n const uniqueResult = removeDuplicates ? [...new Set(result)] : result;\n\n // If all results are the same, return just the first one\n if (uniqueResult.length === 1) {\n return uniqueResult[0] ?? null;\n }\n\n return uniqueResult;\n }\n\n // If url is a single string, process it and return the result\n return processUrl(url);\n};\n","import { isBoolean } from \"@/predicates/is/isBoolean\";\nimport { hasOwnProp } from \"@/predicates/has/hasOwnProp\";\nimport { isEmptyString } from \"@/predicates/is/isEmptyString\";\nimport { getPreciseType } from \"@/predicates/type/getPreciseType\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\nimport { assertIsPlainObject } from \"@/assertions/objects/assertIsPlainObject\";\n\ntype FormatEnvPortOptions = {\n /** Add prefix with a colon, defaultValue: `false`.\n *\n * @default false\n */\n prefixColon?: boolean;\n};\n\n/** -----------------------------------------------\n * * ***Utility: `formatEnvPort`.***\n * -----------------------------------------------\n * **Retrieves and formats an environment port variable.**\n * - **Behavior:**\n * - Extracts only digits from the input.\n * - If no digits found, returns an empty string.\n * - By default does NOT prefix with a colon.\n * - Use `{ prefixColon: true }` to prefix with a colon.\n * @param {string | null | undefined} envVar The environment variable string.\n * @param {FormatEnvPortOptions} [options] Optional object: `{ prefixColon?: boolean }`.\n * @returns {string} A string like `\":8080\"` or `\"8080\"`, or `\"\"` if no digits.\n * @throws **{@link TypeError | `TypeError`}** if `options` is not an object or `prefixColon` is not boolean.\n * @example\n * formatEnvPort(\"port:8080\");\n * // ➔ \"8080\"\n * formatEnvPort(\"port:8080\", { prefixColon: true });\n * // ➔ \":8080\"\n */\nexport const formatEnvPort = (\n envVar: string | null | undefined,\n options: FormatEnvPortOptions = {}\n): string => {\n if (!isNonEmptyString(envVar)) return \"\"; // Handle empty string case\n\n assertIsPlainObject(options, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`options\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const prefixColon = hasOwnProp(options, \"prefixColon\")\n ? options.prefixColon\n : false;\n\n if (!isBoolean(prefixColon)) {\n throw new TypeError(\n `Parameter \\`prefixColon\\` property of the \\`options\\` (second parameter) must be of type \\`boolean\\`, but received: \\`${getPreciseType(\n prefixColon\n )}\\`.`\n );\n }\n\n const digitsOnly = envVar.replace(/\\D+/g, \"\");\n if (isEmptyString(digitsOnly)) return \"\";\n\n return prefixColon ? `:${digitsOnly}` : digitsOnly;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,MAAa,gBACX,SACA,aAGA,iBACQ;CACR,IAAIA,iCAAS,QAAQ,EAAE;EACrB,IAAIC,oCAAc,QAAQ,EACxB,MAAM,IAAI,UACR,yDACD;EAEH,UAAUC,qCAAgB,QAAQ;QAC7B,IAAI,CAACC,4BAAM,QAAQ,EACxB,MAAM,IAAI,UACR,yHAAyHC,uCACvH,QACD,CAAC,4BAA4BC,gDAAoB,SAAS,EACzD,eAAe,MAChB,CAAC,CAAC,KACJ;CAIH,IAAI,CAACC,oCAAY,aAAa,EAAE;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