@rzl-zone/utils-js 3.0.1-beta.0 → 3.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/assertions/index.cjs +1 -1
  2. package/dist/assertions/index.d.ts +96 -116
  3. package/dist/assertions/index.js +1 -1
  4. package/dist/chunk-25G6B35W.js +1 -0
  5. package/dist/chunk-2AUUPGMN.js +1 -0
  6. package/dist/chunk-2JQQQ625.js +1 -0
  7. package/dist/chunk-445TAVT4.cjs +1 -0
  8. package/dist/chunk-467VEMJH.js +1 -0
  9. package/dist/chunk-6Q4I2RPC.cjs +1 -0
  10. package/dist/chunk-6SMJMZ7G.cjs +1 -0
  11. package/dist/chunk-BLCANGFS.js +1 -0
  12. package/dist/chunk-CK3BZGEU.js +1 -0
  13. package/dist/{chunk-JWHM3WZQ.cjs → chunk-D43GV6EF.cjs} +1 -1
  14. package/dist/chunk-DFSTVQFI.cjs +1 -0
  15. package/dist/chunk-DYRDBYPF.cjs +1 -0
  16. package/dist/chunk-EXXLUO7L.cjs +1 -0
  17. package/dist/chunk-G72VSVGO.js +1 -0
  18. package/dist/chunk-GAJTFCUA.js +1 -0
  19. package/dist/chunk-GOJNH55O.cjs +1 -0
  20. package/dist/chunk-HXST7RJB.js +1 -0
  21. package/dist/{chunk-BYZAD3XN.cjs → chunk-HXTACM3O.cjs} +1 -1
  22. package/dist/chunk-IJTZWWRJ.cjs +1 -0
  23. package/dist/chunk-ISJ33O2J.cjs +1 -0
  24. package/dist/chunk-JISH2VGG.js +1 -0
  25. package/dist/{chunk-FF76ISQ2.js → chunk-JQZUWBIX.js} +1 -1
  26. package/dist/{chunk-XH6MCRLP.js → chunk-K4PLGD7C.js} +1 -1
  27. package/dist/chunk-KZQB7H4E.cjs +1 -0
  28. package/dist/chunk-LUVV5KSD.cjs +2 -0
  29. package/dist/chunk-LVUSFXQS.cjs +1 -0
  30. package/dist/chunk-ME5OV5HN.js +1 -0
  31. package/dist/chunk-MF5Y5K4N.cjs +1 -0
  32. package/dist/chunk-MJAW5RAK.js +1 -0
  33. package/dist/chunk-MWLEM7ED.js +1 -0
  34. package/dist/chunk-NSVLG7NY.js +4 -0
  35. package/dist/chunk-NUHOOAUN.cjs +1 -0
  36. package/dist/chunk-NUVGETPD.js +2 -0
  37. package/dist/chunk-O5VXBNUQ.cjs +4 -0
  38. package/dist/chunk-O7SJR4CY.cjs +1 -0
  39. package/dist/chunk-OX6RLS2F.cjs +1 -0
  40. package/dist/chunk-PFLNHD4B.cjs +1 -0
  41. package/dist/chunk-PSWITZK5.js +1 -0
  42. package/dist/chunk-PYUVKHUF.cjs +1 -0
  43. package/dist/chunk-REFMEB4A.js +1 -0
  44. package/dist/chunk-RHE3M2NJ.cjs +1 -0
  45. package/dist/chunk-RHIBYOFQ.js +1 -0
  46. package/dist/chunk-S7GMG4TB.js +1 -0
  47. package/dist/chunk-TQMZ2LPI.js +1 -0
  48. package/dist/{chunk-RN3TP3S3.js → chunk-U4TZO7WV.js} +1 -1
  49. package/dist/chunk-UUMKL74S.js +1 -0
  50. package/dist/{chunk-EXZ47NOW.js → chunk-VQLAPEL3.js} +1 -1
  51. package/dist/chunk-VTR75UID.cjs +1 -0
  52. package/dist/chunk-XFCJDSB2.cjs +1 -0
  53. package/dist/chunk-XOYX4PLZ.cjs +1 -0
  54. package/dist/chunk-Z6FLCEN6.js +1 -0
  55. package/dist/chunk-ZO5364A6.cjs +1 -0
  56. package/dist/conversions/index.cjs +1 -1
  57. package/dist/conversions/index.d.ts +396 -593
  58. package/dist/conversions/index.js +1 -1
  59. package/dist/env/index.d.ts +5 -8
  60. package/dist/events/index.cjs +1 -1
  61. package/dist/events/index.d.ts +80 -77
  62. package/dist/events/index.js +1 -1
  63. package/dist/{array-CIZRbqTF.d.ts → extends-Bk_SBGdT.d.ts} +145 -1
  64. package/dist/formatting/index.cjs +1 -1
  65. package/dist/formatting/index.d.ts +478 -440
  66. package/dist/formatting/index.js +1 -1
  67. package/dist/generator/index.cjs +1 -1
  68. package/dist/generator/index.d.ts +135 -112
  69. package/dist/generator/index.js +1 -1
  70. package/dist/index.cjs +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/index.js +1 -1
  73. package/dist/{is-array-Ckm_47hw.d.ts → is-array--YjXV-Wx.d.ts} +2 -352
  74. package/dist/{isPlainObject-BKYaI6a8.d.ts → isPlainObject-BVhBAPHX.d.ts} +49 -62
  75. package/dist/next/index.cjs +6 -6
  76. package/dist/next/index.d.ts +125 -105
  77. package/dist/next/index.js +5 -5
  78. package/dist/next/server/index.cjs +1 -1
  79. package/dist/next/server/index.d.ts +8 -22
  80. package/dist/next/server/index.js +1 -1
  81. package/dist/operations/index.cjs +1 -1
  82. package/dist/operations/index.d.ts +72 -127
  83. package/dist/operations/index.js +1 -1
  84. package/dist/parsers/index.cjs +1 -1
  85. package/dist/parsers/index.d.ts +26 -27
  86. package/dist/parsers/index.js +1 -1
  87. package/dist/predicates/index.cjs +1 -1
  88. package/dist/predicates/index.d.ts +686 -660
  89. package/dist/predicates/index.js +1 -1
  90. package/dist/promise/index.cjs +1 -1
  91. package/dist/promise/index.d.ts +14 -23
  92. package/dist/promise/index.js +1 -1
  93. package/dist/rzl-utils.global.js +3 -3
  94. package/dist/string-XA-til3C.d.ts +351 -0
  95. package/dist/strings/index.cjs +1 -1
  96. package/dist/strings/index.d.ts +301 -376
  97. package/dist/strings/index.js +1 -1
  98. package/dist/stylings/index.cjs +1 -1
  99. package/dist/stylings/index.d.ts +15 -23
  100. package/dist/stylings/index.js +1 -1
  101. package/dist/types/index.d.ts +1 -1
  102. package/dist/urls/index.cjs +1 -1
  103. package/dist/urls/index.d.ts +279 -302
  104. package/dist/urls/index.js +1 -1
  105. package/package.json +53 -11
  106. package/dist/chunk-2TRAPBZ7.cjs +0 -1
  107. package/dist/chunk-4DK3RCC4.js +0 -2
  108. package/dist/chunk-4JOQ45HL.js +0 -1
  109. package/dist/chunk-55CZALRS.js +0 -1
  110. package/dist/chunk-62HX5Z45.cjs +0 -1
  111. package/dist/chunk-7NA6DUHR.cjs +0 -2
  112. package/dist/chunk-BVPMMWDL.cjs +0 -1
  113. package/dist/chunk-CEFYHEM4.cjs +0 -1
  114. package/dist/chunk-CN53M4QZ.cjs +0 -1
  115. package/dist/chunk-D47MHBSD.cjs +0 -1
  116. package/dist/chunk-DGH75GJD.js +0 -1
  117. package/dist/chunk-E5NUI7PN.js +0 -1
  118. package/dist/chunk-FDITZ5C6.cjs +0 -1
  119. package/dist/chunk-FSSV24W7.cjs +0 -1
  120. package/dist/chunk-GCGU2WB7.js +0 -1
  121. package/dist/chunk-GECI2YBP.js +0 -1
  122. package/dist/chunk-GQE4OVHC.cjs +0 -1
  123. package/dist/chunk-GRVZXQXL.cjs +0 -1
  124. package/dist/chunk-I4AVNHPA.cjs +0 -1
  125. package/dist/chunk-KBKYG3IY.cjs +0 -1
  126. package/dist/chunk-KCQDDZJE.cjs +0 -1
  127. package/dist/chunk-LVKAYEZ4.js +0 -1
  128. package/dist/chunk-MBDWTK54.cjs +0 -1
  129. package/dist/chunk-MNGGDB2G.js +0 -1
  130. package/dist/chunk-MY7BA4GI.cjs +0 -1
  131. package/dist/chunk-N2IJPIND.cjs +0 -1
  132. package/dist/chunk-NIMNTEGV.js +0 -1
  133. package/dist/chunk-POCPQYZS.js +0 -1
  134. package/dist/chunk-PVJF2JHM.js +0 -1
  135. package/dist/chunk-QCFXEUKL.js +0 -1
  136. package/dist/chunk-QFCGBBSY.js +0 -1
  137. package/dist/chunk-QQYAUPSK.cjs +0 -1
  138. package/dist/chunk-TC4VBE4Y.cjs +0 -1
  139. package/dist/chunk-TUXDINHF.cjs +0 -1
  140. package/dist/chunk-U5Y2FXMN.cjs +0 -1
  141. package/dist/chunk-UUPQI6ND.cjs +0 -1
  142. package/dist/chunk-VYCGZ2S6.js +0 -1
  143. package/dist/chunk-W5EDKJK3.js +0 -1
  144. package/dist/chunk-WHAVUFEU.js +0 -1
  145. package/dist/chunk-X3GTRVVK.cjs +0 -4
  146. package/dist/chunk-XCFIOTCV.js +0 -1
  147. package/dist/chunk-XE27XPJR.js +0 -1
  148. package/dist/chunk-XVB3ZZEB.js +0 -1
  149. package/dist/chunk-YEERJDOF.js +0 -4
  150. package/dist/chunk-ZBSIGJFO.cjs +0 -1
  151. package/dist/chunk-ZYAML74V.js +0 -1
  152. package/dist/extends-Mp81Hq9-.d.ts +0 -145
@@ -1,184 +1,204 @@
1
1
  import{I as IsAny}from'../any-BmdI8UbK.js';import'../if-CvT4R7Kh.js';
2
- /** Extracts dynamic route parameters from a given route string.
3
- *
4
- * This utility type recursively searches for dynamic segments within a route,
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
- * * ⚠️ ***Notes: This Type only support when using `NextJS`***
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
- * // Result: { id: string }
16
- *
14
+ * // { id: string }
17
15
  * type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
18
- * // Result: { slug: string; commentId: string }
19
- *
16
+ * // { slug: string; commentId: string }
20
17
  * type Params3 = ExtractRouteParams<"/dashboard">;
21
- * // Result: {} (no dynamic parameters)
18
+ * // {} (no dynamic parameters)
22
19
  * ```
23
20
  */
24
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;
25
- /** Determines whether a given route contains dynamic segments.
26
- *
27
- * This type checks if the route includes at least one `[param]` pattern.
28
- * If it does, the result is `true`, otherwise `false`.
29
- *
30
- * * ⚠️ ***Notes: This Type only support when using `NextJS`***
31
- *
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
- * // Result: true
38
- *
33
+ * // true
39
34
  * type HasParams2 = HasDynamicSegments<"/settings/profile">;
40
- * // Result: false
41
- *
35
+ * // false
42
36
  * type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
43
- * // Result: true
37
+ * // true
44
38
  * ```
45
39
  */
46
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
- * * ⚠️ ***Notes: This Function only support when using `NextJS`***
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
- * // Returns: "/user/123"
57
+ * // "/user/123"
69
58
  *
70
- * @example
71
59
  * // No dynamic segments, returns as-is
72
60
  * generateRoute("/dashboard");
73
- * // Returns: "/dashboard"
61
+ * // "/dashboard"
74
62
  *
75
- * @example
76
63
  * // Throws an error due to missing parameters object
77
64
  * generateRoute("/profile/[username]");
78
- * // ❌ Error: ❌ Missing parameters object for route: "/profile/[username]"
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: ❌ Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
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: ❌ Parameter "query" contains invalid character "?" in route: "/search/[query]"
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: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
77
+ * // ❌ Error: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
94
78
  */
95
- 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;
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()`, which determines the base API URL from:
100
- * - `NEXT_PUBLIC_BACKEND_API_URL` environment variable (or defaults to `"http://localhost:8000"`).
101
- * - Automatically appends `NEXT_PUBLIC_PORT_BE` if the base URL does not already include a port.
102
- *
103
- * Features of this function:
104
- * - Allows customizing the API path with an optional `prefix` (defaults to `"/api"`).
105
- * - Can include or exclude the origin (protocol + host) via `withOrigin`.
106
- * - Normalizes paths to avoid duplicate slashes.
107
- *
108
- * * ⚠️ ***Notes: This Function only support when using `NextJS`***
109
- *
110
- * @param {string} pathname - The API endpoint path (e.g., `/users` or `/v1/posts`).
111
- * @param {Object} options - Configuration options.
112
- * @param {string} [options.prefix="/api"] - The prefix for the API path (default is `"/api"`).
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
- * // -> "http://localhost:8000/api/users"
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
- * // -> "/api/users"
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
- pathname?:string,options?:{
132
- /** * The prefix pathname api url, e.g:`"http://localhost.com/your-target-prefix-entri-point-api-is-here"`.
133
- *
134
- * @default "/api" */
135
- prefix?:string;
136
- /** * Option to getting `prefix` and `pathname` of api url only `(removing origin base api url)`.
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: `"/"`.
137
134
  *
138
- * @default true */
139
- withOrigin?:boolean;})=>string;
140
- /** ---------------------------------
135
+ * @default "/" */
136
+ suffix?:string;};
137
+ /** ---------------------------------------------------
141
138
  * * ***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`***
149
- *
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
- /** * The Suffix origin base api url, e.g:`http://localhost.com/api`.
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
- * This function is designed to be used within Next.js applications.
172
- * It determines the base URL from the `NEXT_PUBLIC_BASE_URL` environment variable.
173
- *
174
- * * ⚠️ ***Notes: This Function only support when using `NextJS`***
175
- *
176
- * - If `NEXT_PUBLIC_BASE_URL` is not set, it defaults to `"http://localhost:3000"`.
177
- * - If `NEXT_PUBLIC_BASE_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_FE` if available.
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
204
  declare const getBaseUrl:()=>string;export{type ExtractRouteParams,type HasDynamicSegments,createBeApiUrl,generateRoute,getBaseUrl,getBeApiUrl};
@@ -1,8 +1,8 @@
1
- import {c as c$2,d}from'../chunk-YEERJDOF.js';import {c as c$3}from'../chunk-GECI2YBP.js';import {a}from'../chunk-NIMNTEGV.js';import {a as a$1}from'../chunk-XVB3ZZEB.js';import'../chunk-ELDDNERR.js';import {c}from'../chunk-MNGGDB2G.js';import'../chunk-5SZUSNGZ.js';import {h,E,m,c as c$1,r,p,f,k,G}from'../chunk-XCFIOTCV.js';function C(e,t){if(!h(e)||a(e))throw new TypeError(`\u274C 'generateRoute' Failed:
1
+ import {c as c$2,d}from'../chunk-NSVLG7NY.js';import {c as c$3}from'../chunk-HXST7RJB.js';import {a}from'../chunk-Z6FLCEN6.js';import {a as a$1}from'../chunk-JISH2VGG.js';import'../chunk-ELDDNERR.js';import {c}from'../chunk-467VEMJH.js';import'../chunk-5SZUSNGZ.js';import {g,E,j,c as c$1,r,p,f,m,G,C}from'../chunk-MJAW5RAK.js';function N(e,t){if(!g(e)||a(e))throw new TypeError(`\u274C 'generateRoute' Failed:
2
2
  - Invalid 'route' value.
3
- - Must be of type \`string\` and non-empty string, but received: "${E(e)}": \`${c(e)}\`.`);if(!/[\\[\]]/.test(e))return e;if(m(t,{message:({validType:o})=>`\u274C 'generateRoute' Failed cause in route "${e}":
3
+ - Must be of type \`string\` and non-empty string, but received: "${E(e)}": \`${c(e)}\`.`);if(!/[\\[\]]/.test(e))return e;if(j(t,{message:({validType:o})=>`\u274C 'generateRoute' Failed cause in route "${e}":
4
4
  - Missing or invalid parameters \`${o}\` for route: "${e}", must be of type \`${o}\` mapping parameters.`}),c$1(t))throw new TypeError(`\u274C 'generateRoute' Failed cause in route "${e}":
5
- - Missing parameters \`plain-object\` for route: "${e}".`);let n=["?","&","#","=","/","'",'"',"(",")","+",";","%","@",":"],r$1=[],s=Array.from(e.matchAll(/\[(\w+)\]/g)).map(o=>o[1]);for(let o of s){let i=t[o];if(!h(i)){r$1.push(`- Invalid parameter: "${o}" must be of type \`string\`, but received: \`${E(i)}\`.`);continue}if(a(i)){r$1.push(`- Parameter "${o}" cannot be empty string.`);continue}let p=n.filter(g=>i.includes(g));if(/\s/.test(i)&&p.push("white-space(s)"),p.length>0){let g=p.map(a=>a==="`"?"backtick - (`)":`\`${a}\``);n.includes("white-space(s)")||n.push("white-space(s)");let c=n.map(a=>a==="`"?"backtick - (`)":`\`${a}\``);r$1.push(`- Parameter "${o}" contains invalid characters (${g.join(", ")}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters: (${c.join(", ")}).`);}}if(r(r$1))throw new Error(`\u274C 'generateRoute' Failed cause in route "${e}":
5
+ - Missing parameters \`plain-object\` for route: "${e}".`);let n=["?","&","#","=","/","'",'"',"(",")","+",";","%","@",":"],r$1=[],s=Array.from(e.matchAll(/\[(\w+)\]/g)).map(o=>o[1]);for(let o of s){let i=t[o];if(!g(i)){r$1.push(`- Invalid parameter: "${o}" must be of type \`string\`, but received: \`${E(i)}\`.`);continue}if(a(i)){r$1.push(`- Parameter "${o}" cannot be empty string.`);continue}let p=n.filter(g=>i.includes(g));if(/\s/.test(i)&&p.push("white-space(s)"),p.length>0){let g=p.map(a=>a==="`"?"backtick - (`)":`\`${a}\``);n.includes("white-space(s)")||n.push("white-space(s)");let m=n.map(a=>a==="`"?"backtick - (`)":`\`${a}\``);r$1.push(`- Parameter "${o}" contains invalid characters (${g.join(", ")}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters: (${m.join(", ")}).`);}}if(r(r$1))throw new Error(`\u274C 'generateRoute' Failed cause in route "${e}":
6
6
  ${r$1.join(`
7
- `)}.`);return e.replace(/\[(\w+)\]/g,(o,i)=>(p(t[i])?t[i]:"").trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")}var M=(e="",t)=>{try{let p=function(c,a){return `${c.replace(/\/+$/,"")}/${a.replace(/^\/+/,"")}`};var n=p;a$1(e,{message({currentType:c,validType:a}){return `First parameter \`pathname\` must be of type \`${a}\`, but received: \`${c}\`.`}}),f(t)||(t={});let{prefix:r="/api",withOrigin:s=!0}=t;if(!k(r)&&!h(r))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: ${E(r)}.`);G(s,{message:({currentType:c,validType:a})=>`Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${a}\`, but received: \`${c}\`.`}),e=c$2(e),r=c$2(r);let o=r.endsWith("/")?r:r+"/";(e===r||e===r+"/"||e.startsWith(o))&&(e=e.slice(r.length),e=c$2(e));let i=U({suffix:r});return p(s?i:new URL(i).pathname,e).replace(/\/+$/,"")}catch(r){throw new Error("Failed to generate backend API URL in `createBeApiUrl()`, Error:"+r)}};var U=({suffix:e="/"}={})=>{a$1(e,{message({currentType:t,validType:n}){return `Parameter \`suffix\` property of the first parameter must be of type \`${n}\`, but received: \`${t}\`.`}});try{let t=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(t){t=c$3(t);let s=new URL(t);!!!s.port&&process.env.NEXT_PUBLIC_PORT_BE&&(t=s.origin+d(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}));}else t="http://localhost"+d(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});e=c$3(e).length?c$3(e):"/";let n=new URL(t.replace(/\/+$/,"")).origin,r=e==="/"?"/":`${e.startsWith("/")?"":"/"}${e.replace(/\/+$/,"")}`;return `${n}${r}`}catch(t){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+t)}};var Z=()=>{try{let e=process.env.NEXT_PUBLIC_BASE_URL?.trim(),t=process.env.NEXT_PUBLIC_PORT_FE?.trim(),n=e||"http://localhost";n=c$3(n).replace(/\/+$/,"");let r=/:\/\/[^/]+:\d+/.test(n);!r&&t?n+=d(t,{prefixColon:!0}):!r&&!e&&(n+=":3000");let s=new URL(n);return `${s.protocol}//${s.hostname}${s.port?`:${s.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}};
8
- export{M as createBeApiUrl,C as generateRoute,Z as getBaseUrl,U as getBeApiUrl};
7
+ `)}.`);return e.replace(/\[(\w+)\]/g,(o,i)=>(p(t[i])?t[i]:"").trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")}var q=(e,t={})=>{try{let p=function(m,a){return `${m.replace(/\/+$/,"")}/${a.replace(/^\/+/,"")}`};var n=p;a$1(c$1(e)?"":e,{message({currentType:m,validType:a}){return `First parameter (\`pathname\`) must be of type \`${a}\`, but received: \`${m}\`.`}}),f(t)||(t={});let{prefix:r="/api",withOrigin:s=!0}=t;if(!m(r)&&!g(r))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${E(r)}\`.`);G(s,{message:({currentType:m,validType:a})=>`Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${a}\`, but received: \`${m}\`.`}),e=c$2(e),r=c$2(r);let o=r.endsWith("/")?r:r+"/";(e===r||e===r+"/"||e.startsWith(o))&&(e=e.slice(r.length),e=c$2(e));let i=b({suffix:r});return p(s?i:new URL(i).pathname,e).replace(/\/+$/,"")}catch(r){throw C(r)?r:new Error("Failed to generate backend API URL in `createBeApiUrl()`, Error: "+new Error(String(r)).message.trim())}};var b=({suffix:e="/"}={})=>{a$1(e,{message({currentType:t,validType:n}){return `Parameter \`suffix\` property of the first parameter must be of type \`${n}\`, but received: \`${t}\`.`}});try{let t=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(t){t=c$3(t);let s=new URL(t);!!!s.port&&process.env.NEXT_PUBLIC_PORT_BE&&(t=s.origin+d(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}));}else t="http://localhost"+d(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});e=c$3(e).length?c$3(e):"/";let n=new URL(t.replace(/\/+$/,"")).origin,r=e==="/"?"/":`${e.startsWith("/")?"":"/"}${e.replace(/\/+$/,"")}`;return `${n}${r}`}catch(t){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+t)}};var te=()=>{try{let e=process.env.NEXT_PUBLIC_BASE_URL?.trim(),t=process.env.NEXT_PUBLIC_PORT_FE?.trim(),n=e||"http://localhost";n=c$3(n).replace(/\/+$/,"");let r=/:\/\/[^/]+:\d+/.test(n);!r&&t?n+=d(t,{prefixColon:!0}):!r&&!e&&(n+=":3000");let s=new URL(n);return `${s.protocol}//${s.hostname}${s.port?`:${s.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}};
8
+ export{q as createBeApiUrl,N as generateRoute,te as getBaseUrl,b as getBeApiUrl};
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkCN53M4QZ_cjs=require('../../chunk-CN53M4QZ.cjs');require('server-only');var server=require('next/server');var g=(t,r=true)=>{if(!chunkCN53M4QZ_cjs.b(server.NextRequest))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `Next.js` environment.");if(!(t instanceof server.NextRequest))throw new TypeError("First parameter `request` must be an instance of NextRequest.");chunkCN53M4QZ_cjs.G(r,{message:({currentType:a,validType:d})=>`Second parameter \`includeFullUrl\` must be of type \`${d}\`, but received: \`${a}\`.`});let e=(t.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(e[0]==="::ffff:127.0.0.1"||e[0]==="::1")&&(e[0]="127.0.0.1");let o=e.length>1?e[e.length-1].trim():e[0];if(!r)return o;let p=t.headers.get("x-forwarded-proto")||"http",f=t.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV==="production"?p:"http"}://${o}:${f}`};
1
+ 'use strict';var chunkLVUSFXQS_cjs=require('../../chunk-LVUSFXQS.cjs');require('server-only');var server=require('next/server');var g=(t,r=true)=>{if(!chunkLVUSFXQS_cjs.b(server.NextRequest))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.");if(!(t instanceof server.NextRequest))throw new TypeError("First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.");chunkLVUSFXQS_cjs.G(r,{message:({currentType:a,validType:d})=>`Second parameter (\`includeFullUrl\`) must be of type \`${d}\`, but received: \`${a}\`.`});let e=(t.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(e[0]==="::ffff:127.0.0.1"||e[0]==="::1")&&(e[0]="127.0.0.1");let o=e.length>1?e[e.length-1].trim():e[0];if(!r)return o;let p=t.headers.get("x-forwarded-proto")||"http",f=t.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV==="production"?p:"http"}://${o}:${f}`};
2
2
  exports.getClientIpOrUrl=g;
@@ -1,22 +1,16 @@
1
1
  import{NextRequest}from'next/server';
2
2
  /** ---------------------------------
3
- * * ***Retrieves the real client IP address and constructs the full URL using headers like***
4
- * ***`x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-port`.***
3
+ * * ***Utility for NextJS Server: `getClientIpOrUrl`.***
5
4
  * ---------------------------------
6
- *
7
- * * ⚠️ **Notes:**
8
- * - Only supported in **Next.js** environments (specifically in `server-only` contexts).
9
- * - Should be used in **middleware** or **server actions** that have access to `NextRequest`.
10
- *
11
- *
12
- * @param {NextRequest} request - The incoming Next.js request object.
13
- * @param {boolean} [includeFullUrl=true] - Whether to return the full URL (`protocol://ip:port`) or just the IP address.
14
- *
5
+ * **Retrieves the real client IP address and constructs the full URL using headers like `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-port`.**
6
+ * - **ℹ️ Note:**
7
+ * - Only supported in **Next.js** environments (specifically in `server-only` contexts).
8
+ * - Should be used in **middleware** or **server actions** that have access to ***[`NextRequest - NextJS`](https://nextjs.org/docs/app/api-reference/functions/next-request)***.
9
+ * @param {NextRequest} request - The incoming ***`NextJS`*** request object.
10
+ * @param {boolean|undefined} [includeFullUrl=true] - Whether to return the full URL (`protocol`, `IP`, and `port` like `protocol://ip:port`) or just the IP address, defaultValue: `true`.
15
11
  * @returns {string} The extracted client IP address or the full constructed URL.
16
- *
17
12
  * @throws {Error} If the function is used outside a Next.js server environment.
18
13
  * @throws {TypeError} If the arguments do not match the expected types.
19
- *
20
14
  * @example
21
15
  * // Basic usage in Next.js middleware
22
16
  * import { NextRequest } from "next/server";
@@ -27,16 +21,8 @@ import{NextRequest}from'next/server';
27
21
  * console.log("Client IP:", clientIp);
28
22
  * }
29
23
  *
30
- * @example
31
24
  * // Get full URL
32
25
  * const url = getClientIpOrUrl(request);
33
26
  * console.log("Client full URL:", url);
34
27
  */
35
- declare const getClientIpOrUrl:(
36
- /** * The incoming Next.js request object. */
37
- request:NextRequest,
38
- /** * Whether to return the full URL (protocol, IP, and port) or just the IP address.
39
- *
40
- * @default true
41
- */
42
- includeFullUrl?:boolean)=>string;export{getClientIpOrUrl};
28
+ declare const getClientIpOrUrl:(request:NextRequest,includeFullUrl?:boolean)=>string;export{getClientIpOrUrl};
@@ -1,2 +1,2 @@
1
- import {b,G}from'../../chunk-XCFIOTCV.js';import'server-only';import {NextRequest}from'next/server';var g=(t,r=true)=>{if(!b(NextRequest))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `Next.js` environment.");if(!(t instanceof NextRequest))throw new TypeError("First parameter `request` must be an instance of NextRequest.");G(r,{message:({currentType:a,validType:d})=>`Second parameter \`includeFullUrl\` must be of type \`${d}\`, but received: \`${a}\`.`});let e=(t.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(e[0]==="::ffff:127.0.0.1"||e[0]==="::1")&&(e[0]="127.0.0.1");let o=e.length>1?e[e.length-1].trim():e[0];if(!r)return o;let p=t.headers.get("x-forwarded-proto")||"http",f=t.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV==="production"?p:"http"}://${o}:${f}`};
1
+ import {b,G}from'../../chunk-MJAW5RAK.js';import'server-only';import {NextRequest}from'next/server';var g=(t,r=true)=>{if(!b(NextRequest))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.");if(!(t instanceof NextRequest))throw new TypeError("First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.");G(r,{message:({currentType:a,validType:d})=>`Second parameter (\`includeFullUrl\`) must be of type \`${d}\`, but received: \`${a}\`.`});let e=(t.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(e[0]==="::ffff:127.0.0.1"||e[0]==="::1")&&(e[0]="127.0.0.1");let o=e.length>1?e[e.length-1].trim():e[0];if(!r)return o;let p=t.headers.get("x-forwarded-proto")||"http",f=t.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV==="production"?p:"http"}://${o}:${f}`};
2
2
  export{g as getClientIpOrUrl};
@@ -1 +1 @@
1
- 'use strict';var chunkFSSV24W7_cjs=require('../chunk-FSSV24W7.cjs');require('../chunk-GRVZXQXL.cjs'),require('../chunk-KCQDDZJE.cjs'),require('../chunk-62HX5Z45.cjs'),require('../chunk-RV2VULM7.cjs'),require('../chunk-U5Y2FXMN.cjs'),require('../chunk-7YWAQOA4.cjs'),require('../chunk-CN53M4QZ.cjs');Object.defineProperty(exports,"findDuplicates",{enumerable:true,get:function(){return chunkFSSV24W7_cjs.a}});Object.defineProperty(exports,"omitKeys",{enumerable:true,get:function(){return chunkFSSV24W7_cjs.b}});Object.defineProperty(exports,"omitKeysDeep",{enumerable:true,get:function(){return chunkFSSV24W7_cjs.c}});Object.defineProperty(exports,"omitProps",{enumerable:true,get:function(){return chunkFSSV24W7_cjs.d}});
1
+ 'use strict';var chunkPYUVKHUF_cjs=require('../chunk-PYUVKHUF.cjs');require('../chunk-IJTZWWRJ.cjs'),require('../chunk-PFLNHD4B.cjs'),require('../chunk-ISJ33O2J.cjs'),require('../chunk-RV2VULM7.cjs'),require('../chunk-O7SJR4CY.cjs'),require('../chunk-7YWAQOA4.cjs'),require('../chunk-LVUSFXQS.cjs');Object.defineProperty(exports,"findDuplicates",{enumerable:true,get:function(){return chunkPYUVKHUF_cjs.a}});Object.defineProperty(exports,"omitKeys",{enumerable:true,get:function(){return chunkPYUVKHUF_cjs.b}});Object.defineProperty(exports,"omitKeysDeep",{enumerable:true,get:function(){return chunkPYUVKHUF_cjs.c}});