@rzl-zone/utils-js 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -27
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +26 -0
- package/dist/any-BmdI8UbK.d.ts +67 -0
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +72 -0
- package/dist/assertions/index.cjs +1 -0
- package/dist/assertions/index.d.ts +408 -0
- package/dist/assertions/index.js +1 -0
- package/dist/chunk-2HSNUPEO.cjs +1 -0
- package/dist/chunk-3YCFMGRB.js +1 -0
- package/dist/chunk-4Z75R3IT.cjs +1 -0
- package/dist/chunk-5C2SMIGX.cjs +1 -0
- package/dist/chunk-5Z2G23WP.js +1 -0
- package/dist/chunk-6C3ATUGM.cjs +1 -0
- package/dist/chunk-AJ25PWXX.cjs +1 -0
- package/dist/chunk-BHIBDDQF.js +1 -0
- package/dist/chunk-CE4JI2YB.js +1 -0
- package/dist/chunk-CMJ6UYWW.cjs +1 -0
- package/dist/chunk-D3VSHABU.cjs +1 -0
- package/dist/chunk-DG2GWBTS.cjs +1 -0
- package/dist/chunk-DVMHRLKP.cjs +1 -0
- package/dist/chunk-ECRNH4FW.js +1 -0
- package/dist/chunk-EKS4IZJR.cjs +1 -0
- package/dist/chunk-EOZKYR5S.cjs +1 -0
- package/dist/chunk-EUANTHVN.js +1 -0
- package/dist/chunk-EW3I4O7X.js +1 -0
- package/dist/chunk-F3E77L46.js +1 -0
- package/dist/chunk-FIAAX3UE.js +1 -0
- package/dist/chunk-FV7SEBKD.cjs +1 -0
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GGWPB23G.cjs +1 -0
- package/dist/chunk-GVWGQNLF.js +1 -0
- package/dist/chunk-H3FXL4DU.cjs +1 -0
- package/dist/chunk-HHPDLSX2.cjs +1 -0
- package/dist/chunk-IMCLPT5V.cjs +1 -0
- package/dist/chunk-IRGE5W7L.js +1 -0
- package/dist/chunk-J2RGTPGK.cjs +1 -0
- package/dist/chunk-JARPXKBM.cjs +1 -0
- package/dist/chunk-JFJUPYDT.cjs +1 -0
- package/dist/chunk-JLP56WSM.js +1 -0
- package/dist/chunk-K3MV4AIN.cjs +1 -0
- package/dist/chunk-KHO2SBNA.cjs +1 -0
- package/dist/chunk-KOVO72OM.js +1 -0
- package/dist/chunk-LJ4M3VGE.js +1 -0
- package/dist/chunk-LJVGJLP4.js +1 -0
- package/dist/chunk-M47QIBXI.cjs +1 -0
- package/dist/chunk-MC3LXMCQ.js +1 -0
- package/dist/chunk-MISCBZJC.js +1 -0
- package/dist/chunk-MMSYCIJ2.cjs +1 -0
- package/dist/chunk-MTUBDVJ2.js +1 -0
- package/dist/chunk-O7UT5AN3.cjs +1 -0
- package/dist/chunk-OGPPP2S3.js +1 -0
- package/dist/chunk-OLPKAX7F.cjs +1 -0
- package/dist/chunk-ONZFBJVW.js +1 -0
- package/dist/chunk-ORZFHBEY.js +1 -0
- package/dist/chunk-OWV2P376.js +1 -0
- package/dist/chunk-QNKGP5DY.js +1 -0
- package/dist/chunk-RV2WK5E6.js +1 -0
- package/dist/chunk-SBF43G3B.cjs +1 -0
- package/dist/chunk-T4CIAKEK.js +1 -0
- package/dist/chunk-UDA26MCU.cjs +1 -0
- package/dist/chunk-VCFXNV3Q.cjs +1 -0
- package/dist/chunk-VHAPTHEA.cjs +1 -0
- package/dist/chunk-WVSPXFTY.js +1 -0
- package/dist/chunk-X74TUJSE.cjs +1 -0
- package/dist/chunk-XC3QHAK2.cjs +1 -0
- package/dist/chunk-XLDAIZRK.js +1 -0
- package/dist/chunk-XZJ7C4N6.js +1 -0
- package/dist/chunk-YV3K2EKJ.js +1 -0
- package/dist/chunk-ZHV5ZYVN.cjs +1 -0
- package/dist/chunk-ZL7J6GTP.js +1 -0
- package/dist/chunk-ZTCLKKMB.js +1 -0
- package/dist/conversions/index.cjs +1 -0
- package/dist/conversions/index.d.ts +1436 -0
- package/dist/conversions/index.js +1 -0
- package/dist/env/index.cjs +1 -0
- package/dist/env/index.d.ts +16 -0
- package/dist/env/index.js +1 -0
- package/dist/events/index.cjs +1 -0
- package/dist/events/index.d.ts +122 -0
- package/dist/events/index.js +1 -0
- package/dist/extends-Bk_SBGdT.d.ts +367 -0
- package/dist/formatting/index.cjs +1 -0
- package/dist/formatting/index.d.ts +950 -0
- package/dist/formatting/index.js +1 -0
- package/dist/generator/index.cjs +1 -0
- package/dist/generator/index.d.ts +186 -0
- package/dist/generator/index.js +1 -0
- package/dist/if-CvT4R7Kh.d.ts +18 -0
- package/dist/is-array--YjXV-Wx.d.ts +1207 -0
- package/dist/isPlainObject-BVhBAPHX.d.ts +169 -0
- package/dist/never-BfayMBF9.d.ts +75 -0
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.d.ts +130 -110
- package/dist/next/index.js +1 -1
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +9 -23
- package/dist/next/server/index.js +1 -1
- package/dist/nils-DMz3kU7M.d.ts +177 -0
- package/dist/omit-VvmIsZmX.d.ts +28 -0
- package/dist/operations/index.cjs +1 -0
- package/dist/operations/index.d.ts +127 -0
- package/dist/operations/index.js +1 -0
- package/dist/parsers/index.cjs +1 -0
- package/dist/parsers/index.d.ts +36 -0
- package/dist/parsers/index.js +1 -0
- package/dist/predicates/index.cjs +1 -0
- package/dist/predicates/index.d.ts +1865 -0
- package/dist/predicates/index.js +1 -0
- package/dist/prettify-C4xLcYOP.d.ts +353 -0
- package/dist/promise/index.cjs +1 -0
- package/dist/promise/index.d.ts +31 -0
- package/dist/promise/index.js +1 -0
- package/dist/rzl-utils.global.js +1 -1
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -0
- package/dist/strings/index.d.ts +741 -0
- package/dist/strings/index.js +1 -0
- package/dist/tailwind/index.cjs +1 -0
- package/dist/tailwind/index.d.ts +565 -0
- package/dist/tailwind/index.js +1 -0
- package/dist/type-data-DDs-u2kq.d.ts +261 -0
- package/dist/types/index.d.ts +3054 -1555
- package/dist/urls/index.cjs +1 -0
- package/dist/urls/index.d.ts +393 -0
- package/dist/urls/index.js +1 -0
- package/package.json +196 -27
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -4334
- package/dist/index.js +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import{N as NonPlainObject}from'./type-data-DDs-u2kq.js';
|
|
2
|
+
/** Types for **{@link getPreciseType}**. */
|
|
3
|
+
type GetPreciseTypeOptions={
|
|
4
|
+
/** -------------------------------------------------------
|
|
5
|
+
* * ***Specifies the format in which the returned string type should be transformed.***
|
|
6
|
+
* -------------------------------------------------------
|
|
7
|
+
*
|
|
8
|
+
* ℹ️ For special string literals in `SPECIAL_CASES` (`"-Infinity" | "Infinity" | "NaN"`), which will remain unchanged.
|
|
9
|
+
* @default "toLowerCase"
|
|
10
|
+
*
|
|
11
|
+
* @description
|
|
12
|
+
* Supported formats:
|
|
13
|
+
* - `"toLowerCase"` (default) — converts all letters to lowercase.
|
|
14
|
+
* - ➔ `"result example type"`
|
|
15
|
+
* - `"toDotCase"` — words separated by dots.
|
|
16
|
+
* - ➔ `"result.example.type"`
|
|
17
|
+
* - `"toCamelCase"` — first word lowercase, subsequent words capitalized.
|
|
18
|
+
* - ➔ `"resultExampleType"`
|
|
19
|
+
* - `"toKebabCase"` — words separated by hyphens.
|
|
20
|
+
* - ➔ `"result-example-type"`
|
|
21
|
+
* - `"toSnakeCase"` — words separated by underscores.
|
|
22
|
+
* - ➔ `"result_example_type"`
|
|
23
|
+
* - `"toPascalCase"` — all words capitalized, no spaces.
|
|
24
|
+
* - ➔ `"ResultExampleType"`
|
|
25
|
+
* - `"toPascalCaseSpace"` — all words capitalized with spaces between words.
|
|
26
|
+
* - ➔ `"Result Example Type"`
|
|
27
|
+
* - `"slugify"` — URL-friendly slug (lowercase with hyphens).
|
|
28
|
+
* - ➔ `"result-example-type"`
|
|
29
|
+
*
|
|
30
|
+
* @note
|
|
31
|
+
* ⚠️ If an invalid value is provided, the function will automatically fallback to the default `"toLowerCase"`.
|
|
32
|
+
*/
|
|
33
|
+
formatCase?:"toPascalCaseSpace"|"toPascalCase"|"toCamelCase"|"toKebabCase"|"toSnakeCase"|"toDotCase"|"slugify"|"toLowerCase";};
|
|
34
|
+
/** ----------------------------------------------------------
|
|
35
|
+
* * ***Utility-Predicate: `getPreciseType`.***
|
|
36
|
+
* ----------------------------------------------------------
|
|
37
|
+
* **Returns a detailed and normalized type string for the given value.**
|
|
38
|
+
* @description
|
|
39
|
+
* The returned string is human-readable _**toLowerCase**_ with spaces _***(by default)***_ or formatted according to the `options.formatCase` setting.
|
|
40
|
+
* - **Handles:**
|
|
41
|
+
* - Primitives (`string`, `number`, `boolean`, `null`, `undefined`, `symbol`, `bigint`)
|
|
42
|
+
* - Built-in objects (`Array`, `Map`, `Set`, `Error subclasses`, `Typed Arrays`, `etc`)
|
|
43
|
+
* - Objects created with `Object.create(null)`
|
|
44
|
+
* - Generator instances
|
|
45
|
+
* - Node.js `Buffer` instances
|
|
46
|
+
* - Proxy detection (returns `"Proxy"` if detected; detection is not 100% accurate)
|
|
47
|
+
* - Uses cached mapping table (`FIXES`) for known types to provide consistent naming
|
|
48
|
+
* - Falls back to constructor name or `Object.prototype.toString` tag
|
|
49
|
+
* @param {*} value - The value to detect the precise type of
|
|
50
|
+
* @param {GetPreciseTypeOptions} [options] - Optional configuration
|
|
51
|
+
* @param {GetPreciseTypeOptions["formatCase"]} [options.formatCase="toLowerCase"]
|
|
52
|
+
* Specifies how the returned type string should be formatted.
|
|
53
|
+
* - ⚠️ Special string literals in `SPECIAL_CASES`
|
|
54
|
+
* (`"-Infinity" | "Infinity" | "NaN"`) will remain
|
|
55
|
+
* unchanged even if a different `formatCase` is applied.
|
|
56
|
+
* @returns {string} The normalized and formatted type string
|
|
57
|
+
* @example
|
|
58
|
+
* getPreciseType(123); // ➔ "number"
|
|
59
|
+
* getPreciseType(null); // ➔ "null"
|
|
60
|
+
* getPreciseType(/regex/,{ formatCase: "toKebabCase" });
|
|
61
|
+
* // ➔ "reg-exp"
|
|
62
|
+
* getPreciseType(function* () {}, { formatCase: "toCamelCase" });
|
|
63
|
+
* // ➔ "generatorFunction"
|
|
64
|
+
* getPreciseType(async function () {}, { formatCase: "toPascalCaseSpace" });
|
|
65
|
+
* // ➔ "Async Function"
|
|
66
|
+
* getPreciseType(NaN, { formatCase: "toKebabCase" });
|
|
67
|
+
* // ➔ "NaN" (SPECIAL_CASES remain)
|
|
68
|
+
*/
|
|
69
|
+
declare const getPreciseType:(value:unknown,options?:GetPreciseTypeOptions)=>string;type IsNumberOptions={
|
|
70
|
+
/** If set to `true`, `NaN` will be considered a valid number, defaultValue: `false`.
|
|
71
|
+
*
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
includeNaN?:boolean;};
|
|
75
|
+
/** ---------------------------------------------------------
|
|
76
|
+
* * ***Type guard: `isNumber`.***
|
|
77
|
+
* ----------------------------------------------------------
|
|
78
|
+
* **Checks if a value is of type **`number`**.**
|
|
79
|
+
* - **Behavior:**
|
|
80
|
+
* - Uses `typeof value === "number"`.
|
|
81
|
+
* - By default, excludes **`NaN`**.
|
|
82
|
+
* - If `options.includeNaN` is `true`, then **`NaN`** is also considered valid.
|
|
83
|
+
* - Still considers `Infinity` and `-Infinity` as **numbers** (consistent with JavaScript).
|
|
84
|
+
* - **ℹ️ Note:**
|
|
85
|
+
* - To exclude `Infinity` and `-Infinity`, use **{@link isFinite | `isFinite`}** instead.
|
|
86
|
+
* @param {*} value - The value to check.
|
|
87
|
+
* @param {IsNumberOptions} [options] - Optional settings.
|
|
88
|
+
* @param {boolean} [options.includeNaN=false] If `true`, `NaN` will be considered a valid number, defaults to `false`, which excludes `NaN`.
|
|
89
|
+
* @returns {boolean} Returns `true` if the value is a number (and depending on `includeNaN`, `NaN` is included or excluded).
|
|
90
|
+
* @example
|
|
91
|
+
* isNumber(42);
|
|
92
|
+
* // ➔ true
|
|
93
|
+
* isNumber(Infinity);
|
|
94
|
+
* // ➔ true
|
|
95
|
+
* isNumber(-Infinity);
|
|
96
|
+
* // ➔ true
|
|
97
|
+
* isNumber(NaN);
|
|
98
|
+
* // ➔ false (default)
|
|
99
|
+
* isNumber(NaN, { includeNaN: true });
|
|
100
|
+
* // ➔ true
|
|
101
|
+
* isNumber("42");
|
|
102
|
+
* // ➔ false
|
|
103
|
+
*/
|
|
104
|
+
declare const isNumber:(value:unknown,options?:IsNumberOptions)=>value is number;type HasKeys<T>=keyof T extends never?false:true;
|
|
105
|
+
/** ----------------------------------------------------------
|
|
106
|
+
* * ***Utility type: `IsPlainObjectResult`.***
|
|
107
|
+
* ----------------------------------------------------------
|
|
108
|
+
* **Represents the inferred type after asserting a value is a **plain object**.**
|
|
109
|
+
* - **Behavior:**
|
|
110
|
+
* - If `T` is `unknown`, the resulting type is `Record<PropertyKey, unknown> & T`.
|
|
111
|
+
* - If `T` is an object:
|
|
112
|
+
* - If it is a non-plain object (class instance, built-in object, etc.), the result is `never`.
|
|
113
|
+
* - If it has no keys (`HasKeys<T>` checked by **{@link HasKeys}** is false), the result is `Record<PropertyKey, unknown> & T`.
|
|
114
|
+
* - Otherwise, the result is `T` itself.
|
|
115
|
+
* - For any other types, the result is `never`.
|
|
116
|
+
* @template T - The input type to be asserted as a plain object.
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* type A = IsPlainObjectResult<unknown>;
|
|
120
|
+
* // ➔ Record<PropertyKey, unknown> & unknown
|
|
121
|
+
* type B = IsPlainObjectResult<{}>;
|
|
122
|
+
* // ➔ Record<PropertyKey, unknown> & {}
|
|
123
|
+
* type C = IsPlainObjectResult<{ foo: string }>;
|
|
124
|
+
* // ➔ { foo: string }
|
|
125
|
+
* type D = IsPlainObjectResult<Date>;
|
|
126
|
+
* // ➔ never
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
type IsPlainObjectResult<T>=unknown extends T?Record<PropertyKey,unknown>& T:T extends object?T extends NonPlainObject?never:HasKeys<T>extends false?Record<PropertyKey,unknown>& T:T:Extract<T,Record<PropertyKey,unknown>>;
|
|
130
|
+
/** ----------------------------------------------------------
|
|
131
|
+
* * ***Type guard: `isPlainObject`.***
|
|
132
|
+
* ----------------------------------------------------------
|
|
133
|
+
* **Checks if a value is a **plain-object**.**
|
|
134
|
+
* - **A plain object is:**
|
|
135
|
+
* - Created by the `Object` constructor, or
|
|
136
|
+
* - Has a `[[Prototype]]` of `null` (e.g. `Object.create(null)`).
|
|
137
|
+
* - **✅ Returns `true` for:**
|
|
138
|
+
* - Empty object literals: `{}`
|
|
139
|
+
* - Objects with null prototype: `Object.create(null)`
|
|
140
|
+
* - **❌ Returns `false` for:**
|
|
141
|
+
* - Arrays (`[]`, `new Array()`)
|
|
142
|
+
* - Functions (regular, arrow, or class constructors)
|
|
143
|
+
* - Built-in objects: `Date`, `RegExp`, `Error`, `Map`, `Set`, `WeakMap`, `WeakSet`
|
|
144
|
+
* - Boxed primitives: `new String()`, `new Number()`, `new Boolean()`
|
|
145
|
+
* - `null` or `undefined`
|
|
146
|
+
* - Symbols
|
|
147
|
+
* - Class instances
|
|
148
|
+
* @template T - The type of the value being checked.
|
|
149
|
+
* @param {*} value - The value to check.
|
|
150
|
+
* @returns {boolean} Return `true` if `value` is a `plain-object`, otherwise `false`.
|
|
151
|
+
* @example
|
|
152
|
+
* isPlainObject({});
|
|
153
|
+
* // ➔ true
|
|
154
|
+
* isPlainObject(Object.create(null));
|
|
155
|
+
* // ➔ true
|
|
156
|
+
* isPlainObject(null);
|
|
157
|
+
* // ➔ false
|
|
158
|
+
* isPlainObject(() => {});
|
|
159
|
+
* // ➔ false
|
|
160
|
+
* isPlainObject([1, 2, 3]);
|
|
161
|
+
* // ➔ false
|
|
162
|
+
* isPlainObject(new Date());
|
|
163
|
+
* // ➔ false
|
|
164
|
+
* isPlainObject(new MyClass());
|
|
165
|
+
* // ➔ false
|
|
166
|
+
* isPlainObject(new String("x"));
|
|
167
|
+
* // ➔ false
|
|
168
|
+
*/
|
|
169
|
+
declare function isPlainObject<T>(value:T):value is IsPlainObjectResult<T>;declare function isPlainObject<T>(value:T):value is NonNullable<Extract<T,Record<PropertyKey,unknown>>>;export{type GetPreciseTypeOptions as G,type IsNumberOptions as I,type IsPlainObjectResult as a,isPlainObject as b,getPreciseType as g,isNumber as i};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import{I as If}from'./if-CvT4R7Kh.js';
|
|
2
|
+
/** -------------------------------------------------------
|
|
3
|
+
* * ***IsNever.***
|
|
4
|
+
* -------------------------------------------------------
|
|
5
|
+
* **Conditional**: returns `true` if `T` is `never`, otherwise `false`.
|
|
6
|
+
*
|
|
7
|
+
* @template T - Type to check.
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* type A = IsNever<never>; // ➔ true
|
|
11
|
+
* type B = IsNever<true>; // ➔ false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type IsNever<T>=[T] extends [never]?true:false;
|
|
15
|
+
/** -------------------------------------------------------
|
|
16
|
+
* * ***IfNever.***
|
|
17
|
+
* -------------------------------------------------------
|
|
18
|
+
* **Conditional**: Selects one of two branches depending on whether `T` is `never`.
|
|
19
|
+
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
20
|
+
*
|
|
21
|
+
* @template T - Type to check.
|
|
22
|
+
* @template IfTrue - The branch type if `T` is `never`, (default: `true`).
|
|
23
|
+
* @template IfFalse - The branch type if `T` is not `never`, (default: `false`).
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* type A = IfNever<never>;
|
|
27
|
+
* // ➔ true
|
|
28
|
+
* type B = IfNever<string>;
|
|
29
|
+
* // ➔ false
|
|
30
|
+
* type C = IfNever<never, 'valid', 'no'>;
|
|
31
|
+
* // ➔ 'valid'
|
|
32
|
+
* type D = IfNever<string, 'valid', 'no'>;
|
|
33
|
+
* // ➔ 'no'
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
type IfNever<T,IfTrue=true,IfFalse=false>=If<IsNever<T>,IfTrue,IfFalse>;
|
|
37
|
+
/** -------------------------------------------------------
|
|
38
|
+
* * ***NeverifyPropertiesOptions.***
|
|
39
|
+
* -------------------------------------------------------
|
|
40
|
+
* Configuration options for the ***{@link NeverifyProperties}*** type utility.
|
|
41
|
+
*
|
|
42
|
+
* @property makeOptional - Whether to make all properties optional.
|
|
43
|
+
* - If `true`, resulting properties will be optional (`?`).
|
|
44
|
+
* - Default: `false`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* type Opt1 = NeverifyPropertiesOptions;
|
|
49
|
+
* // ➔ { makeOptional: boolean }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
type NeverifyPropertiesOptions={
|
|
53
|
+
/** Whether to make all properties optional, defaultValue: `false`.
|
|
54
|
+
*
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
makeOptional:boolean;};
|
|
58
|
+
/** -------------------------------------------------------
|
|
59
|
+
* * ***NeverifyProperties.***
|
|
60
|
+
* -------------------------------------------------------
|
|
61
|
+
* Turns all properties of an object to type `never`.
|
|
62
|
+
* - If `Options["makeOptional"]` is `true`, properties will be optional.
|
|
63
|
+
*
|
|
64
|
+
* @template T - Object type to transform.
|
|
65
|
+
* @template Options - Configuration options (default: `{ makeOptional: false }`).
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* type A = NeverifyProperties<{ a: string; b: string }>;
|
|
69
|
+
* // ➔ { a: never; b: never }
|
|
70
|
+
*
|
|
71
|
+
* type B = NeverifyProperties<{ a: string; b: string }, { makeOptional: true }>;
|
|
72
|
+
* // ➔ { a?: never; b?: never }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
type NeverifyProperties<T extends object,Options extends NeverifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:never;}extends infer Result?If<Options["makeOptional"],Partial<Result>,Result>:never;export type{IsNever as I,NeverifyProperties as N,IfNever as a,NeverifyPropertiesOptions as b};
|
package/dist/next/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var e=require("../chunk-SBF43G3B.cjs"),r=require("../chunk-2HSNUPEO.cjs"),t=require("../chunk-4Z75R3IT.cjs"),n=require("../chunk-VCFXNV3Q.cjs");require("../chunk-DVMHRLKP.cjs");var s=require("../chunk-ZHV5ZYVN.cjs");require("../chunk-UDA26MCU.cjs");var i=require("../chunk-D3VSHABU.cjs");var a=({suffix:t="/"}={})=>{var s;n.assertIsString(t,{message:({currentType:e,validType:r})=>`Parameter \`suffix\` property of the first parameter must be of type \`${r}\`, but received: \`${e}\`.`});try{let n=null==(s=process.env.NEXT_PUBLIC_BACKEND_API_URL)?void 0:s.trim();if(n){n=r.removeSpaces(n);const t=new URL(n);!!!t.port&&process.env.NEXT_PUBLIC_PORT_BE&&(n=t.origin+e.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}))}else n="http://localhost"+e.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});t=r.removeSpaces(t).length?r.removeSpaces(t):"/";const i=new URL(n.replace(/\/+$/,"")).origin;return`${i}${"/"===t?"/":`${t.startsWith("/")?"":"/"}${t.replace(/\/+$/,"")}`}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+e)}};exports.createBeApiUrl=(r,t={})=>{try{let s=function(e,r){return`${e.replace(/\/+$/,"")}/${r.replace(/^\/+/,"")}`};n.assertIsString(i.isNil(r)?"":r,{message:({currentType:e,validType:r})=>`First parameter (\`pathname\`) must be of type \`${r}\`, but received: \`${e}\`.`}),i.isPlainObject(t)||(t={});let{prefix:o="/api",withOrigin:c=!0}=t;if(!i.isUndefined(o)&&!i.isString(o))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${i.getPreciseType(o)}\`.`);i.assertIsBoolean(c,{message:({currentType:e,validType:r})=>`Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${r}\`, but received: \`${e}\`.`}),r=e.normalizePathname(r),o=e.normalizePathname(o);const p=o.endsWith("/")?o:o+"/";(r===o||r===o+"/"||r.startsWith(p))&&(r=r.slice(o.length),r=e.normalizePathname(r));const u=a({suffix:o});return s(c?u:new URL(u).pathname,r).replace(/\/+$/,"")}catch(e){throw i.isError(e)?e:new Error("Failed to generate backend API URL in `createBeApiUrl()`, Error: "+new Error(String(e)).message.trim())}},exports.generateRoute=function(e,r){if(!i.isString(e)||t.isEmptyString(e))throw new TypeError(`❌ 'generateRoute' Failed:\n- Invalid 'route' value.\n- Must be of type \`string\` and non-empty string, but received: "${i.getPreciseType(e)}": \`${s.safeStableStringify(e)}\`.`);if(!/[\\[\]]/.test(e))return e;if(i.assertIsPlainObject(r,{message:({validType:r})=>`❌ 'generateRoute' Failed cause in route "${e}":\n- Missing or invalid parameters \`${r}\` for route: "${e}", must be of type \`${r}\` mapping parameters.`}),i.isNil(r))throw new TypeError(`❌ 'generateRoute' Failed cause in route "${e}":\n- Missing parameters \`plain-object\` for route: "${e}".`);const n=["?","&","#","=","/","'",'"',"(",")","+",";","%","@",":"],a=[],o=Array.from(e.matchAll(/\[(\w+)\]/g)).map(e=>e[1]);for(const e of o){const s=r[e];if(!i.isString(s)){a.push(`- Invalid parameter: "${e}" must be of type \`string\`, but received: \`${i.getPreciseType(s)}\`.`);continue}if(t.isEmptyString(s)){a.push(`- Parameter "${e}" cannot be empty string.`);continue}const o=n.filter(e=>s.includes(e));if(/\s/.test(s)&&o.push("white-space(s)"),o.length>0){const r=o.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);n.includes("white-space(s)")||n.push("white-space(s)");const t=n.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);a.push(`- Parameter "${e}" contains invalid characters (${r.join(", ")}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters: (${t.join(", ")}).`)}}if(i.isNonEmptyArray(a))throw new Error(`❌ 'generateRoute' Failed cause in route "${e}":\n${a.join("\n")}.`);return e.replace(/\[(\w+)\]/g,(e,t)=>(i.isNonEmptyString(r[t])?r[t]:"").trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")},exports.getBaseUrl=()=>{var t,n;try{const s=null==(t=process.env.NEXT_PUBLIC_BASE_URL)?void 0:t.trim(),i=null==(n=process.env.NEXT_PUBLIC_PORT_FE)?void 0:n.trim();let a=s||"http://localhost";a=r.removeSpaces(a).replace(/\/+$/,"");const o=/:\/\/[^/]+:\d+/.test(a);!o&&i?a+=e.formatEnvPort(i,{prefixColon:!0}):o||s||(a+=":3000");const c=new URL(a);return`${c.protocol}//${c.hostname}${c.port?`:${c.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}},exports.getBeApiUrl=a;
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,184 +1,204 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
1
|
+
import{I as IsAny}from'../any-BmdI8UbK.js';import'../if-CvT4R7Kh.js';
|
|
2
|
+
/** ---------------------------------------------------------
|
|
3
|
+
* * ***Extracts dynamic route parameters from a given route string.***
|
|
4
|
+
* ---------------------------------------------------------
|
|
5
|
+
* **This utility type recursively searches for dynamic segments within a route,
|
|
5
6
|
* extracting each parameter and constructing an object where each key represents
|
|
6
|
-
* a dynamic segment and its value is of type `string
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* a dynamic segment and its value is of type `string`.**
|
|
8
|
+
* - ***⚠️ Warning:***
|
|
9
|
+
* - ***This types only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
10
10
|
* @template T - The route string containing potential dynamic segments.
|
|
11
|
-
*
|
|
12
11
|
* @example
|
|
13
12
|
* ```ts
|
|
14
13
|
* type Params1 = ExtractRouteParams<"/user/[id]">;
|
|
15
|
-
* //
|
|
16
|
-
*
|
|
14
|
+
* // ➔ { id: string }
|
|
17
15
|
* type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
|
|
18
|
-
* //
|
|
19
|
-
*
|
|
16
|
+
* // ➔ { slug: string; commentId: string }
|
|
20
17
|
* type Params3 = ExtractRouteParams<"/dashboard">;
|
|
21
|
-
* //
|
|
18
|
+
* // ➔ {} (no dynamic parameters)
|
|
22
19
|
* ```
|
|
23
20
|
*/
|
|
24
|
-
type ExtractRouteParams<T extends string
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
21
|
+
type ExtractRouteParams<T>=T extends string?HasDynamicSegments<T>extends true?T extends`${infer _Start}[${infer Param}]${infer Rest}`?{[K in Param|keyof ExtractRouteParams<Rest>]:string;}:unknown:unknown:unknown;
|
|
22
|
+
/** ---------------------------------------------------------
|
|
23
|
+
* * ***Determines whether a given route contains dynamic segments.***
|
|
24
|
+
* ---------------------------------------------------------
|
|
25
|
+
* **This type checks if the route includes at least one `[param]` pattern.
|
|
26
|
+
* If it does, the result is `true`, otherwise `false`.**
|
|
27
|
+
* - ***⚠️ Warning:***
|
|
28
|
+
* - ***This types only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
32
29
|
* @template T - The route string to be evaluated.
|
|
33
|
-
*
|
|
34
30
|
* @example
|
|
35
31
|
* ```ts
|
|
36
32
|
* type HasParams1 = HasDynamicSegments<"/user/[id]">;
|
|
37
|
-
* //
|
|
38
|
-
*
|
|
33
|
+
* // ➔ true
|
|
39
34
|
* type HasParams2 = HasDynamicSegments<"/settings/profile">;
|
|
40
|
-
* //
|
|
41
|
-
*
|
|
35
|
+
* // ➔ false
|
|
42
36
|
* type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
|
|
43
|
-
* //
|
|
37
|
+
* // ➔ true
|
|
44
38
|
* ```
|
|
45
39
|
*/
|
|
46
|
-
type HasDynamicSegments<T
|
|
40
|
+
type HasDynamicSegments<T>=T extends`${string}[${string}]${string}`?true:false;type GenerateRouteResult<T>=true extends IsAny<T>?unknown:T extends string?string:unknown;
|
|
47
41
|
/** ---------------------------------
|
|
48
42
|
* * ***Generates a URL by replacing dynamic route parameters with provided values.***
|
|
49
43
|
* ---------------------------------
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
44
|
+
* - ***⚠️ Warning:***
|
|
45
|
+
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
53
46
|
* @template T - The route string containing dynamic segments in the format `[param]`.
|
|
54
|
-
*
|
|
55
47
|
* @param {T} route - The route string containing dynamic segments.
|
|
56
48
|
* @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
|
|
57
|
-
*
|
|
58
49
|
* @returns {string} The formatted URL with all dynamic segments replaced.
|
|
59
|
-
*
|
|
60
50
|
* @throws {Error} If the route contains dynamic segments but no parameters object is provided.
|
|
61
51
|
* @throws {Error} If a required parameter is missing from the `params` object.
|
|
62
52
|
* @throws {Error} If a parameter value is an empty string.
|
|
63
53
|
* @throws {Error} If any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
|
|
64
|
-
*
|
|
65
54
|
* @example
|
|
66
55
|
* // Basic usage
|
|
67
56
|
* generateRoute("/user/[id]", { id: "123" });
|
|
68
|
-
* //
|
|
57
|
+
* // ➔ "/user/123"
|
|
69
58
|
*
|
|
70
|
-
* @example
|
|
71
59
|
* // No dynamic segments, returns as-is
|
|
72
60
|
* generateRoute("/dashboard");
|
|
73
|
-
* //
|
|
61
|
+
* // ➔ "/dashboard"
|
|
74
62
|
*
|
|
75
|
-
* @example
|
|
76
63
|
* // Throws an error due to missing parameters object
|
|
77
64
|
* generateRoute("/profile/[username]");
|
|
78
|
-
* // ❌ Error:
|
|
65
|
+
* // ➔ ❌ Error: ❌ Missing parameters object for route: "/profile/[username]"
|
|
79
66
|
*
|
|
80
|
-
* @example
|
|
81
67
|
* // Throws an error due to an empty parameter value
|
|
82
68
|
* generateRoute("/post/[category]/[slug]", { category: "tech", slug: "" });
|
|
83
|
-
* // ❌ Error:
|
|
69
|
+
* // ➔ ❌ Error: ❌ Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
|
|
84
70
|
*
|
|
85
|
-
* @example
|
|
86
71
|
* // Throws an error due to parameter containing invalid characters
|
|
87
72
|
* generateRoute("/search/[query]", { query: "how to?learn" });
|
|
88
|
-
* // ❌ Error:
|
|
73
|
+
* // ➔ ❌ Error: ❌ Parameter "query" contains invalid character "?" in route: "/search/[query]"
|
|
89
74
|
*
|
|
90
|
-
* @example
|
|
91
75
|
* // Handles leading/trailing slashes correctly
|
|
92
76
|
* generateRoute("/blog/[category]/[slug]", { category: "/news/", slug: "/latest-update/" });
|
|
93
|
-
* // ❌ Error:
|
|
77
|
+
* // ➔ ❌ Error: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
|
|
94
78
|
*/
|
|
95
|
-
declare function generateRoute<T extends string>(route:T
|
|
79
|
+
declare function generateRoute<T extends string>(route:T extends string?(HasDynamicSegments<T>extends true?T:never):never,params:T extends string?ExtractRouteParams<T>:undefined):GenerateRouteResult<T>;declare function generateRoute<T extends string>(route:T extends string?T:never,params?:Extract<ExtractRouteParams<T>,Record<string,unknown>>):GenerateRouteResult<T>;declare function generateRoute<T=unknown>(route:T extends string?(HasDynamicSegments<T>extends true?T:unknown):unknown,params?:T extends string?ExtractRouteParams<T>:undefined):unknown;type OptionsCreateBeApiUrl={
|
|
80
|
+
/** * The prefix pathname api url, e.g:`"http://localhost.com/your-target-prefix-entri-point-api-is-here"`, default: `"/api"`.
|
|
81
|
+
*
|
|
82
|
+
* @default "/api" */
|
|
83
|
+
prefix?:string;
|
|
84
|
+
/** * Option to getting `prefix` and `pathname` of api url only `(removing origin base api url)`, default: `true`.
|
|
85
|
+
*
|
|
86
|
+
* @default true */
|
|
87
|
+
withOrigin?:boolean;};
|
|
96
88
|
/** ---------------------------------
|
|
97
89
|
* * ***Constructs a backend API URL by appending a given pathname to the base API URL.***
|
|
98
90
|
* ---------------------------------
|
|
99
|
-
* This function builds on top of `getBeApiUrl()
|
|
100
|
-
* -
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* Features of this function
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @param {
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
113
|
-
* @param {boolean} [options.withOrigin=true] - Whether to include the full base URL or return only the API path.
|
|
91
|
+
* This function builds on top of `getBeApiUrl()`.
|
|
92
|
+
* - **Determines the base API URL from:**
|
|
93
|
+
* - `NEXT_PUBLIC_BACKEND_API_URL` environment variable (or defaults to `"http://localhost:8000"`).
|
|
94
|
+
* - Automatically appends `NEXT_PUBLIC_PORT_BE` if the base URL does not already include a port.
|
|
95
|
+
* - **Features of this function:**
|
|
96
|
+
* - Allows customizing the API path with an optional `prefix` (defaults to `"/api"`).
|
|
97
|
+
* - Can include or exclude the origin (protocol + host) via `withOrigin`.
|
|
98
|
+
* - Normalizes paths to avoid duplicate slashes.
|
|
99
|
+
* - ***⚠️ Warning:***
|
|
100
|
+
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
101
|
+
* @param {string|null|undefined} pathname - The API endpoint path (e.g., `/users` or `/v1/posts`), defaultValue: `""`.
|
|
102
|
+
* @param {OptionsCreateBeApiUrl} [options] - Configuration options.
|
|
103
|
+
* @param {OptionsCreateBeApiUrl["prefix"]} [options.prefix="/api"] - The prefix for the API path (default is `"/api"`).
|
|
104
|
+
* @param {OptionsCreateBeApiUrl["withOrigin"]} [options.withOrigin=true] - Whether to include the full base URL or return only the API path.
|
|
114
105
|
* @returns {string} The formatted API URL.
|
|
115
|
-
*
|
|
116
106
|
* @throws {TypeError} If `withOrigin` is not a boolean.
|
|
117
107
|
* @throws {TypeError} If `prefix` and `pathname` is not a string.
|
|
118
108
|
* @throws {Error} If constructing the API URL fails due to an invalid base URL.
|
|
119
|
-
*
|
|
120
109
|
* @example
|
|
121
110
|
* createBeApiUrl("/users")
|
|
122
|
-
* //
|
|
123
|
-
*
|
|
111
|
+
* // ➔ "http://localhost:8000/api/users"
|
|
112
|
+
* createBeApiUrl("/api/users")
|
|
113
|
+
* // ➔ "http://localhost:8000/api/users"
|
|
114
|
+
* createBeApiUrl("/v1", { prefix: "/v1" })
|
|
115
|
+
* // ➔ "http://localhost:8000/v1"
|
|
116
|
+
* createBeApiUrl("/v1/users")
|
|
117
|
+
* // ➔ "http://localhost:8000/api/v1/users"
|
|
118
|
+
* createBeApiUrl("/v1/users", { prefix: "/v1" })
|
|
119
|
+
* // ➔ "http://localhost:8000/v1/users"
|
|
124
120
|
* createBeApiUrl("/users", { withOrigin: false })
|
|
125
|
-
* //
|
|
121
|
+
* // ➔ "/api/users"
|
|
122
|
+
* createBeApiUrl(null, { withOrigin: false })
|
|
123
|
+
* // ➔ "/api"
|
|
124
|
+
* createBeApiUrl(undefined, { withOrigin: false })
|
|
125
|
+
* // ➔ "/api"
|
|
126
126
|
*/
|
|
127
127
|
declare const createBeApiUrl:(
|
|
128
128
|
/** * The pathname api url, e.g:`"http://localhost.com/your-target-prefix-entri-point-api-is-here/your-target-pathname-is-here"`.
|
|
129
129
|
*
|
|
130
|
-
* @default ""
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
* @default "/api" */
|
|
135
|
-
prefix?:string;
|
|
136
|
-
/** * Option to getting `prefix` and `pathname` of api url only `(removing origin base api url)`.
|
|
137
|
-
*
|
|
138
|
-
* @default true */
|
|
139
|
-
withOrigin?:boolean;})=>string;
|
|
140
|
-
/** ---------------------------------
|
|
141
|
-
* * ***Retrieves the base API URL of the backend.***
|
|
142
|
-
* ---------------------------------
|
|
143
|
-
*
|
|
144
|
-
* This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
|
|
145
|
-
* If the variable is not set, it defaults to `"http://localhost:8000"`.
|
|
146
|
-
* It also allows adding an optional suffix to the returned URL.
|
|
147
|
-
*
|
|
148
|
-
* * ⚠️ ***Notes: This Function only support when using `NextJS`***
|
|
130
|
+
* @default ""
|
|
131
|
+
*/
|
|
132
|
+
pathname:string|null|undefined,options?:OptionsCreateBeApiUrl)=>string;type OptionsGetBeApiUrl={
|
|
133
|
+
/** * The Suffix origin base api url, e.g:`http://localhost.com/api`, default: `"/"`.
|
|
149
134
|
*
|
|
135
|
+
* @default "/" */
|
|
136
|
+
suffix?:string;};
|
|
137
|
+
/** ---------------------------------------------------
|
|
138
|
+
* * ***Retrieves the base API URL of the backend.***
|
|
139
|
+
* ---------------------------------------------------
|
|
140
|
+
* **This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.**
|
|
141
|
+
* - **Behavior:**
|
|
142
|
+
* - If the variable is not set, it defaults to `"http://localhost:8000"`.
|
|
143
|
+
* - It also allows adding an optional suffix to the returned URL.
|
|
144
|
+
* - ***⚠️ Warning:***
|
|
145
|
+
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
146
|
+
* @description
|
|
150
147
|
* This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
|
|
151
148
|
* - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
|
|
152
149
|
* - If `NEXT_PUBLIC_BACKEND_API_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_BE` if available.
|
|
153
150
|
* - Supports appending optional suffix (like "/api").
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param {Object} options - Configuration options.
|
|
157
|
-
* @param {string} [options.suffix="/"] - The suffix to append to the base API URL.
|
|
151
|
+
* @param {OptionsGetBeApiUrl|undefined} options - Configuration options.
|
|
152
|
+
* @param {OptionsGetBeApiUrl["suffix"]} [options.suffix="/"] - The suffix to append to the base API URL.
|
|
158
153
|
* @returns {string} The formatted backend API base URL.
|
|
159
154
|
* @throws {TypeError} If `suffix` is not a `string`.
|
|
160
155
|
* @throws {Error} If `NEXT_PUBLIC_BACKEND_API_URL` is invalid.
|
|
156
|
+
* @example
|
|
157
|
+
* // With NEXT_PUBLIC_BACKEND_API_URL set at `*.env` file
|
|
158
|
+
* NEXT_PUBLIC_BACKEND_API_URL = "https://api.example.com";
|
|
159
|
+
* getBeApiUrl();
|
|
160
|
+
* // ➔ "https://api.example.com/"
|
|
161
|
+
*
|
|
162
|
+
* // With NEXT_PUBLIC_BACKEND_API_URL but no port, using NEXT_PUBLIC_PORT_BE at `*.env` file
|
|
163
|
+
* NEXT_PUBLIC_BACKEND_API_URL = "http://localhost";
|
|
164
|
+
* NEXT_PUBLIC_PORT_BE = "5000";
|
|
165
|
+
* getBeApiUrl({ suffix: "/api" });
|
|
166
|
+
* // ➔ "http://localhost:5000/api"
|
|
167
|
+
*
|
|
168
|
+
* // Without NEXT_PUBLIC_BACKEND_API_URL at `*.env` file (defaults to localhost:8000)
|
|
169
|
+
* delete NEXT_PUBLIC_BACKEND_API_URL;
|
|
170
|
+
* getBeApiUrl({ suffix: "/v1" });
|
|
171
|
+
* // ➔ "http://localhost:8000/v1"
|
|
161
172
|
*/
|
|
162
|
-
declare const getBeApiUrl:({suffix
|
|
163
|
-
/**
|
|
164
|
-
*
|
|
165
|
-
* @default "/" */
|
|
166
|
-
suffix?:string;})=>string;
|
|
167
|
-
/** ---------------------------------
|
|
173
|
+
declare const getBeApiUrl:({suffix}?:OptionsGetBeApiUrl)=>string;
|
|
174
|
+
/** ---------------------------------------------------
|
|
168
175
|
* * ***Retrieves the base URL of the application.***
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* It determines the base URL from the `NEXT_PUBLIC_BASE_URL` environment variable.
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* -
|
|
177
|
-
*
|
|
178
|
-
* - Ensures the final URL is valid and normalized (no trailing slashes).
|
|
179
|
-
*
|
|
176
|
+
* ---------------------------------------------------
|
|
177
|
+
* **This function is designed to be used within `Next.js` applications.**
|
|
178
|
+
* - **Behavior:**
|
|
179
|
+
* - It determines the base URL from the `NEXT_PUBLIC_BASE_URL` environment variable.
|
|
180
|
+
* - If `NEXT_PUBLIC_BASE_URL` is not set, it defaults to `"http://localhost:3000"`.
|
|
181
|
+
* - If `NEXT_PUBLIC_BASE_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_FE` if available.
|
|
182
|
+
* - Ensures the final URL is valid and normalized (no trailing slashes).
|
|
183
|
+
* - ***⚠️ Warning:***
|
|
184
|
+
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
180
185
|
* @returns {string} The resolved base URL of the application.
|
|
181
186
|
* @throws {Error} If the constructed URL is invalid or malformed.
|
|
182
|
-
*
|
|
187
|
+
* @example
|
|
188
|
+
* // With environment variable set at `*.env` file
|
|
189
|
+
* NEXT_PUBLIC_BASE_URL = "https://example.com";
|
|
190
|
+
* getBaseUrl();
|
|
191
|
+
* // ➔ "https://example.com"
|
|
192
|
+
*
|
|
193
|
+
* // With custom port via NEXT_PUBLIC_PORT_FE at `*.env` file
|
|
194
|
+
* NEXT_PUBLIC_BASE_URL = "http://localhost";
|
|
195
|
+
* NEXT_PUBLIC_PORT_FE = "4000";
|
|
196
|
+
* getBaseUrl();
|
|
197
|
+
* // ➔ "http://localhost:4000"
|
|
198
|
+
*
|
|
199
|
+
* // Without environment variable at `*.env` file
|
|
200
|
+
* delete NEXT_PUBLIC_BASE_URL;
|
|
201
|
+
* getBaseUrl();
|
|
202
|
+
* // ➔ "http://localhost:3000"
|
|
183
203
|
*/
|
|
184
|
-
declare const getBaseUrl:()=>string;export{createBeApiUrl,generateRoute,getBaseUrl,getBeApiUrl};
|
|
204
|
+
declare const getBaseUrl:()=>string;export{type ExtractRouteParams,type HasDynamicSegments,createBeApiUrl,generateRoute,getBaseUrl,getBeApiUrl};
|