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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +56 -27
  2. package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +23 -23
  3. package/dist/any-BmdI8UbK.d.ts +56 -56
  4. package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +66 -66
  5. package/dist/assertions/index.cjs +1 -1
  6. package/dist/assertions/index.d.ts +396 -396
  7. package/dist/assertions/index.js +1 -1
  8. package/dist/chunk-26XIKDJI.cjs +1 -0
  9. package/dist/chunk-2NWHDDM5.js +1 -0
  10. package/dist/chunk-2UIRWYE3.js +1 -0
  11. package/dist/chunk-3KBHD3BS.cjs +1 -0
  12. package/dist/chunk-4HD2O5A4.js +1 -0
  13. package/dist/chunk-5C2SMIGX.cjs +1 -0
  14. package/dist/chunk-5I2B5DOG.js +1 -0
  15. package/dist/chunk-6HQDHIOD.js +1 -0
  16. package/dist/chunk-735HJXBT.cjs +1 -0
  17. package/dist/chunk-7BXIZM57.cjs +1 -0
  18. package/dist/chunk-7KJBDGEP.js +1 -0
  19. package/dist/chunk-7U44T63D.cjs +1 -0
  20. package/dist/chunk-AJ65QFV2.js +1 -0
  21. package/dist/chunk-APHDUCVQ.js +1 -0
  22. package/dist/chunk-BSVZRN7C.js +1 -0
  23. package/dist/chunk-C6JFHUR2.cjs +1 -0
  24. package/dist/chunk-CPLBRGST.js +1 -0
  25. package/dist/chunk-CTBRLEOG.js +1 -0
  26. package/dist/chunk-DUK2K4FB.js +1 -0
  27. package/dist/chunk-DVMHRLKP.cjs +1 -0
  28. package/dist/chunk-E63WVPZE.cjs +1 -0
  29. package/dist/chunk-EBMHQW7X.cjs +1 -0
  30. package/dist/chunk-EGNZCW4K.js +1 -0
  31. package/dist/chunk-FEKDB32T.js +1 -0
  32. package/dist/chunk-FIAAX3UE.js +1 -0
  33. package/dist/chunk-FUS3DVLB.cjs +1 -0
  34. package/dist/chunk-GGRMHIFJ.cjs +1 -0
  35. package/dist/chunk-HQ5GQTEE.js +1 -0
  36. package/dist/chunk-I5X5IN4H.js +1 -0
  37. package/dist/chunk-I7YGXQPI.cjs +1 -0
  38. package/dist/chunk-INUFZJLX.cjs +1 -0
  39. package/dist/chunk-IREHUBF7.js +1 -0
  40. package/dist/chunk-J2RGTPGK.cjs +1 -0
  41. package/dist/chunk-KHO2SBNA.cjs +1 -0
  42. package/dist/chunk-KXIXXSWX.cjs +1 -0
  43. package/dist/chunk-LBMEEJWA.js +1 -0
  44. package/dist/chunk-MC3LXMCQ.js +1 -0
  45. package/dist/chunk-MMSYCIJ2.cjs +1 -1
  46. package/dist/chunk-NU3N4WHD.cjs +1 -0
  47. package/dist/chunk-ODZQXH7E.cjs +1 -0
  48. package/dist/chunk-ONZFBJVW.js +1 -0
  49. package/dist/chunk-PXDRHFIE.js +1 -0
  50. package/dist/chunk-Q6NHYWVX.js +1 -0
  51. package/dist/chunk-QNKGP5DY.js +1 -0
  52. package/dist/chunk-S6Z6I2EG.cjs +1 -0
  53. package/dist/chunk-SMADKXZE.js +1 -0
  54. package/dist/chunk-TSLYDPBJ.js +1 -0
  55. package/dist/chunk-TVXADXCC.cjs +1 -0
  56. package/dist/chunk-UDA26MCU.cjs +1 -0
  57. package/dist/chunk-UET567YM.cjs +1 -0
  58. package/dist/chunk-VEYMQ3UA.js +1 -0
  59. package/dist/chunk-W2W3L2M5.js +1 -0
  60. package/dist/chunk-WBWTXKMC.cjs +1 -0
  61. package/dist/chunk-WVSPXFTY.js +1 -0
  62. package/dist/chunk-XC2PYCT4.cjs +1 -0
  63. package/dist/chunk-XIXA5KDF.cjs +1 -0
  64. package/dist/chunk-Y4O5KZF6.cjs +1 -0
  65. package/dist/chunk-YRM7IJLX.js +1 -0
  66. package/dist/chunk-YT3MSZKK.cjs +1 -0
  67. package/dist/chunk-YXHCULSO.cjs +1 -0
  68. package/dist/chunk-YZR5OGJA.cjs +1 -0
  69. package/dist/chunk-Z4DXK7A6.cjs +1 -0
  70. package/dist/chunk-ZXIWDFEQ.js +1 -0
  71. package/dist/conversions/index.cjs +1 -1
  72. package/dist/conversions/index.d.ts +1347 -1297
  73. package/dist/conversions/index.js +1 -1
  74. package/dist/env/index.cjs +1 -1
  75. package/dist/env/index.d.ts +14 -14
  76. package/dist/env/index.js +1 -1
  77. package/dist/events/index.cjs +1 -1
  78. package/dist/events/index.d.ts +109 -109
  79. package/dist/events/index.js +1 -1
  80. package/dist/extends-Bk_SBGdT.d.ts +330 -330
  81. package/dist/formatting/index.cjs +1 -1
  82. package/dist/formatting/index.d.ts +855 -855
  83. package/dist/formatting/index.js +1 -1
  84. package/dist/generator/index.cjs +1 -1
  85. package/dist/generator/index.d.ts +155 -155
  86. package/dist/generator/index.js +1 -1
  87. package/dist/if-CvT4R7Kh.d.ts +16 -16
  88. package/dist/is-array-Cymwrsmm.d.ts +1119 -0
  89. package/dist/isPlainObject-BVhBAPHX.d.ts +154 -154
  90. package/dist/never-BfayMBF9.d.ts +64 -64
  91. package/dist/next/index.cjs +1 -8
  92. package/dist/next/index.d.ts +183 -183
  93. package/dist/next/index.js +1 -8
  94. package/dist/next/server/index.cjs +1 -2
  95. package/dist/next/server/index.d.ts +25 -25
  96. package/dist/next/server/index.js +1 -2
  97. package/dist/nils-DMz3kU7M.d.ts +155 -155
  98. package/dist/omit-VvmIsZmX.d.ts +25 -25
  99. package/dist/operations/index.cjs +1 -1
  100. package/dist/operations/index.d.ts +120 -120
  101. package/dist/operations/index.js +1 -1
  102. package/dist/or-DyZCRvaU.d.ts +89 -0
  103. package/dist/parsers/index.cjs +1 -1
  104. package/dist/parsers/index.d.ts +34 -34
  105. package/dist/parsers/index.js +1 -1
  106. package/dist/predicates/index.cjs +1 -1
  107. package/dist/predicates/index.d.ts +1774 -1680
  108. package/dist/predicates/index.js +1 -1
  109. package/dist/prettify-C4xLcYOP.d.ts +328 -328
  110. package/dist/promise/index.cjs +1 -1
  111. package/dist/promise/index.d.ts +29 -29
  112. package/dist/promise/index.js +1 -1
  113. package/dist/rzl-utils.global.js +1 -4
  114. package/dist/string-XA-til3C.d.ts +318 -318
  115. package/dist/strings/index.cjs +1 -1
  116. package/dist/strings/index.d.ts +690 -690
  117. package/dist/strings/index.js +1 -1
  118. package/dist/tailwind/index.cjs +1 -0
  119. package/dist/tailwind/index.d.ts +565 -0
  120. package/dist/tailwind/index.js +1 -0
  121. package/dist/type-data-DDs-u2kq.d.ts +241 -241
  122. package/dist/types/index.d.ts +3266 -3266
  123. package/dist/urls/index.cjs +1 -1
  124. package/dist/urls/index.d.ts +373 -373
  125. package/dist/urls/index.js +1 -1
  126. package/package.json +24 -23
  127. package/dist/chunk-25G6B35W.js +0 -1
  128. package/dist/chunk-2AUUPGMN.js +0 -1
  129. package/dist/chunk-2JQQQ625.js +0 -1
  130. package/dist/chunk-445TAVT4.cjs +0 -1
  131. package/dist/chunk-467VEMJH.js +0 -1
  132. package/dist/chunk-56QBKKRE.js +0 -1
  133. package/dist/chunk-5SZUSNGZ.js +0 -1
  134. package/dist/chunk-6Q4I2RPC.cjs +0 -1
  135. package/dist/chunk-6SMJMZ7G.cjs +0 -1
  136. package/dist/chunk-7YWAQOA4.cjs +0 -1
  137. package/dist/chunk-BLCANGFS.js +0 -1
  138. package/dist/chunk-CK3BZGEU.js +0 -1
  139. package/dist/chunk-D43GV6EF.cjs +0 -1
  140. package/dist/chunk-DFSTVQFI.cjs +0 -1
  141. package/dist/chunk-DYRDBYPF.cjs +0 -1
  142. package/dist/chunk-ELDDNERR.js +0 -1
  143. package/dist/chunk-EXXLUO7L.cjs +0 -1
  144. package/dist/chunk-FIEZKTAZ.cjs +0 -1
  145. package/dist/chunk-G72VSVGO.js +0 -1
  146. package/dist/chunk-GAJTFCUA.js +0 -1
  147. package/dist/chunk-GOJNH55O.cjs +0 -1
  148. package/dist/chunk-HXST7RJB.js +0 -1
  149. package/dist/chunk-HXTACM3O.cjs +0 -1
  150. package/dist/chunk-IJTZWWRJ.cjs +0 -1
  151. package/dist/chunk-ISJ33O2J.cjs +0 -1
  152. package/dist/chunk-JISH2VGG.js +0 -1
  153. package/dist/chunk-JQZUWBIX.js +0 -1
  154. package/dist/chunk-K4PLGD7C.js +0 -1
  155. package/dist/chunk-KZQB7H4E.cjs +0 -1
  156. package/dist/chunk-LUVV5KSD.cjs +0 -2
  157. package/dist/chunk-LVUSFXQS.cjs +0 -1
  158. package/dist/chunk-ME5OV5HN.js +0 -1
  159. package/dist/chunk-MF5Y5K4N.cjs +0 -1
  160. package/dist/chunk-MJAW5RAK.js +0 -1
  161. package/dist/chunk-MWLEM7ED.js +0 -1
  162. package/dist/chunk-NNM7QCNB.js +0 -1
  163. package/dist/chunk-NSVLG7NY.js +0 -4
  164. package/dist/chunk-NUHOOAUN.cjs +0 -1
  165. package/dist/chunk-NUVGETPD.js +0 -2
  166. package/dist/chunk-O5VXBNUQ.cjs +0 -4
  167. package/dist/chunk-O7SJR4CY.cjs +0 -1
  168. package/dist/chunk-OX6RLS2F.cjs +0 -1
  169. package/dist/chunk-PFLNHD4B.cjs +0 -1
  170. package/dist/chunk-PSWITZK5.js +0 -1
  171. package/dist/chunk-PUQXRLZH.cjs +0 -1
  172. package/dist/chunk-PYUVKHUF.cjs +0 -1
  173. package/dist/chunk-REFMEB4A.js +0 -1
  174. package/dist/chunk-RHE3M2NJ.cjs +0 -1
  175. package/dist/chunk-RHIBYOFQ.js +0 -1
  176. package/dist/chunk-RV2VULM7.cjs +0 -1
  177. package/dist/chunk-S7GMG4TB.js +0 -1
  178. package/dist/chunk-SW6HYEW7.cjs +0 -1
  179. package/dist/chunk-SYJC7UAW.js +0 -1
  180. package/dist/chunk-TQMZ2LPI.js +0 -1
  181. package/dist/chunk-U4TZO7WV.js +0 -1
  182. package/dist/chunk-UUMKL74S.js +0 -1
  183. package/dist/chunk-VQLAPEL3.js +0 -1
  184. package/dist/chunk-VTR75UID.cjs +0 -1
  185. package/dist/chunk-XFCJDSB2.cjs +0 -1
  186. package/dist/chunk-XOYX4PLZ.cjs +0 -1
  187. package/dist/chunk-Z6FLCEN6.js +0 -1
  188. package/dist/chunk-ZO5364A6.cjs +0 -1
  189. package/dist/index.cjs +0 -1
  190. package/dist/index.d.ts +0 -1
  191. package/dist/index.js +0 -1
  192. package/dist/is-array--YjXV-Wx.d.ts +0 -1207
  193. package/dist/stylings/index.cjs +0 -1
  194. package/dist/stylings/index.d.ts +0 -41
  195. package/dist/stylings/index.js +0 -1
@@ -1,204 +1,204 @@
1
1
  import{I as IsAny}from'../any-BmdI8UbK.js';import'../if-CvT4R7Kh.js';
2
2
  /** ---------------------------------------------------------
3
- * * ***Extracts dynamic route parameters from a given route string.***
4
- * ---------------------------------------------------------
5
- * **This utility type recursively searches for dynamic segments within a route,
6
- * extracting each parameter and constructing an object where each key represents
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
- * @template T - The route string containing potential dynamic segments.
11
- * @example
12
- * ```ts
13
- * type Params1 = ExtractRouteParams<"/user/[id]">;
14
- * // ➔ { id: string }
15
- * type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
16
- * // ➔ { slug: string; commentId: string }
17
- * type Params3 = ExtractRouteParams<"/dashboard">;
18
- * // ➔ {} (no dynamic parameters)
19
- * ```
20
- */
3
+ * * ***Extracts dynamic route parameters from a given route string.***
4
+ * ---------------------------------------------------------
5
+ * **This utility type recursively searches for dynamic segments within a route,
6
+ * extracting each parameter and constructing an object where each key represents
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
+ * @template T - The route string containing potential dynamic segments.
11
+ * @example
12
+ * ```ts
13
+ * type Params1 = ExtractRouteParams<"/user/[id]">;
14
+ * // ➔ { id: string }
15
+ * type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
16
+ * // ➔ { slug: string; commentId: string }
17
+ * type Params3 = ExtractRouteParams<"/dashboard">;
18
+ * // ➔ {} (no dynamic parameters)
19
+ * ```
20
+ */
21
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
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/)***.***
29
- * @template T - The route string to be evaluated.
30
- * @example
31
- * ```ts
32
- * type HasParams1 = HasDynamicSegments<"/user/[id]">;
33
- * // ➔ true
34
- * type HasParams2 = HasDynamicSegments<"/settings/profile">;
35
- * // ➔ false
36
- * type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
37
- * // ➔ true
38
- * ```
39
- */
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/)***.***
29
+ * @template T - The route string to be evaluated.
30
+ * @example
31
+ * ```ts
32
+ * type HasParams1 = HasDynamicSegments<"/user/[id]">;
33
+ * // ➔ true
34
+ * type HasParams2 = HasDynamicSegments<"/settings/profile">;
35
+ * // ➔ false
36
+ * type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
37
+ * // ➔ true
38
+ * ```
39
+ */
40
40
  type HasDynamicSegments<T>=T extends`${string}[${string}]${string}`?true:false;type GenerateRouteResult<T>=true extends IsAny<T>?unknown:T extends string?string:unknown;
41
41
  /** ---------------------------------
42
- * * ***Generates a URL by replacing dynamic route parameters with provided values.***
43
- * ---------------------------------
44
- * - ***⚠️ Warning:***
45
- * - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
46
- * @template T - The route string containing dynamic segments in the format `[param]`.
47
- * @param {T} route - The route string containing dynamic segments.
48
- * @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
49
- * @returns {string} The formatted URL with all dynamic segments replaced.
50
- * @throws {Error} If the route contains dynamic segments but no parameters object is provided.
51
- * @throws {Error} If a required parameter is missing from the `params` object.
52
- * @throws {Error} If a parameter value is an empty string.
53
- * @throws {Error} If any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
54
- * @example
55
- * // Basic usage
56
- * generateRoute("/user/[id]", { id: "123" });
57
- * // ➔ "/user/123"
58
- *
59
- * // No dynamic segments, returns as-is
60
- * generateRoute("/dashboard");
61
- * // ➔ "/dashboard"
62
- *
63
- * // Throws an error due to missing parameters object
64
- * generateRoute("/profile/[username]");
65
- * // ➔ ❌ Error: ❌ Missing parameters object for route: "/profile/[username]"
66
- *
67
- * // Throws an error due to an empty parameter value
68
- * generateRoute("/post/[category]/[slug]", { category: "tech", slug: "" });
69
- * // ➔ ❌ Error: ❌ Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
70
- *
71
- * // Throws an error due to parameter containing invalid characters
72
- * generateRoute("/search/[query]", { query: "how to?learn" });
73
- * // ➔ ❌ Error: ❌ Parameter "query" contains invalid character "?" in route: "/search/[query]"
74
- *
75
- * // Handles leading/trailing slashes correctly
76
- * generateRoute("/blog/[category]/[slug]", { category: "/news/", slug: "/latest-update/" });
77
- * // ➔ ❌ Error: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
78
- */
42
+ * * ***Generates a URL by replacing dynamic route parameters with provided values.***
43
+ * ---------------------------------
44
+ * - ***⚠️ Warning:***
45
+ * - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
46
+ * @template T - The route string containing dynamic segments in the format `[param]`.
47
+ * @param {T} route - The route string containing dynamic segments.
48
+ * @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
49
+ * @returns {string} The formatted URL with all dynamic segments replaced.
50
+ * @throws {Error} If the route contains dynamic segments but no parameters object is provided.
51
+ * @throws {Error} If a required parameter is missing from the `params` object.
52
+ * @throws {Error} If a parameter value is an empty string.
53
+ * @throws {Error} If any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
54
+ * @example
55
+ * // Basic usage
56
+ * generateRoute("/user/[id]", { id: "123" });
57
+ * // ➔ "/user/123"
58
+ *
59
+ * // No dynamic segments, returns as-is
60
+ * generateRoute("/dashboard");
61
+ * // ➔ "/dashboard"
62
+ *
63
+ * // Throws an error due to missing parameters object
64
+ * generateRoute("/profile/[username]");
65
+ * // ➔ ❌ Error: ❌ Missing parameters object for route: "/profile/[username]"
66
+ *
67
+ * // Throws an error due to an empty parameter value
68
+ * generateRoute("/post/[category]/[slug]", { category: "tech", slug: "" });
69
+ * // ➔ ❌ Error: ❌ Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
70
+ *
71
+ * // Throws an error due to parameter containing invalid characters
72
+ * generateRoute("/search/[query]", { query: "how to?learn" });
73
+ * // ➔ ❌ Error: ❌ Parameter "query" contains invalid character "?" in route: "/search/[query]"
74
+ *
75
+ * // Handles leading/trailing slashes correctly
76
+ * generateRoute("/blog/[category]/[slug]", { category: "/news/", slug: "/latest-update/" });
77
+ * // ➔ ❌ Error: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
78
+ */
79
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
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" */
81
+ *
82
+ * @default "/api" */
83
83
  prefix?:string;
84
84
  /** * Option to getting `prefix` and `pathname` of api url only `(removing origin base api url)`, default: `true`.
85
- *
86
- * @default true */
85
+ *
86
+ * @default true */
87
87
  withOrigin?:boolean;};
88
88
  /** ---------------------------------
89
- * * ***Constructs a backend API URL by appending a given pathname to the base API URL.***
90
- * ---------------------------------
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.
105
- * @returns {string} The formatted API URL.
106
- * @throws {TypeError} If `withOrigin` is not a boolean.
107
- * @throws {TypeError} If `prefix` and `pathname` is not a string.
108
- * @throws {Error} If constructing the API URL fails due to an invalid base URL.
109
- * @example
110
- * createBeApiUrl("/users")
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"
120
- * createBeApiUrl("/users", { withOrigin: false })
121
- * // ➔ "/api/users"
122
- * createBeApiUrl(null, { withOrigin: false })
123
- * // ➔ "/api"
124
- * createBeApiUrl(undefined, { withOrigin: false })
125
- * // ➔ "/api"
126
- */
89
+ * * ***Constructs a backend API URL by appending a given pathname to the base API URL.***
90
+ * ---------------------------------
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.
105
+ * @returns {string} The formatted API URL.
106
+ * @throws {TypeError} If `withOrigin` is not a boolean.
107
+ * @throws {TypeError} If `prefix` and `pathname` is not a string.
108
+ * @throws {Error} If constructing the API URL fails due to an invalid base URL.
109
+ * @example
110
+ * createBeApiUrl("/users")
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"
120
+ * createBeApiUrl("/users", { withOrigin: false })
121
+ * // ➔ "/api/users"
122
+ * createBeApiUrl(null, { withOrigin: false })
123
+ * // ➔ "/api"
124
+ * createBeApiUrl(undefined, { withOrigin: false })
125
+ * // ➔ "/api"
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
- *
130
- * @default ""
131
- */
129
+ *
130
+ * @default ""
131
+ */
132
132
  pathname:string|null|undefined,options?:OptionsCreateBeApiUrl)=>string;type OptionsGetBeApiUrl={
133
133
  /** * The Suffix origin base api url, e.g:`http://localhost.com/api`, default: `"/"`.
134
- *
135
- * @default "/" */
134
+ *
135
+ * @default "/" */
136
136
  suffix?:string;};
137
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
147
- * This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
148
- * - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
149
- * - If `NEXT_PUBLIC_BACKEND_API_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_BE` if available.
150
- * - Supports appending optional suffix (like "/api").
151
- * @param {OptionsGetBeApiUrl|undefined} options - Configuration options.
152
- * @param {OptionsGetBeApiUrl["suffix"]} [options.suffix="/"] - The suffix to append to the base API URL.
153
- * @returns {string} The formatted backend API base URL.
154
- * @throws {TypeError} If `suffix` is not a `string`.
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"
172
- */
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
147
+ * This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
148
+ * - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
149
+ * - If `NEXT_PUBLIC_BACKEND_API_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_BE` if available.
150
+ * - Supports appending optional suffix (like "/api").
151
+ * @param {OptionsGetBeApiUrl|undefined} options - Configuration options.
152
+ * @param {OptionsGetBeApiUrl["suffix"]} [options.suffix="/"] - The suffix to append to the base API URL.
153
+ * @returns {string} The formatted backend API base URL.
154
+ * @throws {TypeError} If `suffix` is not a `string`.
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"
172
+ */
173
173
  declare const getBeApiUrl:({suffix}?:OptionsGetBeApiUrl)=>string;
174
174
  /** ---------------------------------------------------
175
- * * ***Retrieves the base URL of the application.***
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/)***.***
185
- * @returns {string} The resolved base URL of the application.
186
- * @throws {Error} If the constructed URL is invalid or malformed.
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"
203
- */
175
+ * * ***Retrieves the base URL of the application.***
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/)***.***
185
+ * @returns {string} The resolved base URL of the application.
186
+ * @throws {Error} If the constructed URL is invalid or malformed.
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"
203
+ */
204
204
  declare const getBaseUrl:()=>string;export{type ExtractRouteParams,type HasDynamicSegments,createBeApiUrl,generateRoute,getBaseUrl,getBeApiUrl};
@@ -1,8 +1 @@
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
- - 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(j(t,{message:({validType:o})=>`\u274C 'generateRoute' Failed cause in route "${e}":
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(!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
- ${r$1.join(`
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
+ import{normalizePathname as e,formatEnvPort as r}from"../chunk-6HQDHIOD.js";import{removeSpaces as t}from"../chunk-Q6NHYWVX.js";import{isEmptyString as o}from"../chunk-TSLYDPBJ.js";import{assertIsString as n}from"../chunk-W2W3L2M5.js";import"../chunk-WVSPXFTY.js";import{safeStableStringify as i}from"../chunk-AJ65QFV2.js";import"../chunk-QNKGP5DY.js";import{isString as a,getPreciseType as s,assertIsPlainObject as p,isNil as c,isNonEmptyArray as u,isNonEmptyString as l,isPlainObject as m,isUndefined as f,assertIsBoolean as h,isError as $}from"../chunk-2UIRWYE3.js";function d(e,r){if(!a(e)||o(e))throw new TypeError(`❌ 'generateRoute' Failed:\n- Invalid 'route' value.\n- Must be of type \`string\` and non-empty string, but received: "${s(e)}": \`${i(e)}\`.`);if(!/[\\[\]]/.test(e))return e;if(p(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.`}),c(r))throw new TypeError(`❌ 'generateRoute' Failed cause in route "${e}":\n- Missing parameters \`plain-object\` for route: "${e}".`);const t=["?","&","#","=","/","'",'"',"(",")","+",";","%","@",":"],n=[],m=Array.from(e.matchAll(/\[(\w+)\]/g)).map(e=>e[1]);for(const e of m){const i=r[e];if(!a(i)){n.push(`- Invalid parameter: "${e}" must be of type \`string\`, but received: \`${s(i)}\`.`);continue}if(o(i)){n.push(`- Parameter "${e}" cannot be empty string.`);continue}const p=t.filter(e=>i.includes(e));if(/\s/.test(i)&&p.push("white-space(s)"),p.length>0){const r=p.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);t.includes("white-space(s)")||t.push("white-space(s)");const o=t.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);n.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: (${o.join(", ")}).`)}}if(u(n))throw new Error(`❌ 'generateRoute' Failed cause in route "${e}":\n${n.join("\n")}.`);return e.replace(/\[(\w+)\]/g,(e,t)=>(l(r[t])?r[t]:"").trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")}var g=(r,t={})=>{try{let o=function(e,r){return`${e.replace(/\/+$/,"")}/${r.replace(/^\/+/,"")}`};n(c(r)?"":r,{message:({currentType:e,validType:r})=>`First parameter (\`pathname\`) must be of type \`${r}\`, but received: \`${e}\`.`}),m(t)||(t={});let{prefix:i="/api",withOrigin:p=!0}=t;if(!f(i)&&!a(i))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${s(i)}\`.`);h(p,{message:({currentType:e,validType:r})=>`Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${r}\`, but received: \`${e}\`.`}),r=e(r),i=e(i);const u=i.endsWith("/")?i:i+"/";(r===i||r===i+"/"||r.startsWith(u))&&(r=r.slice(i.length),r=e(r));const l=v({suffix:i});return o(p?l:new URL(l).pathname,r).replace(/\/+$/,"")}catch(e){throw $(e)?e:new Error("Failed to generate backend API URL in `createBeApiUrl()`, Error: "+new Error(String(e)).message.trim())}},v=({suffix:e="/"}={})=>{var o;n(e,{message:({currentType:e,validType:r})=>`Parameter \`suffix\` property of the first parameter must be of type \`${r}\`, but received: \`${e}\`.`});try{let n=null==(o=process.env.NEXT_PUBLIC_BACKEND_API_URL)?void 0:o.trim();if(n){n=t(n);const e=new URL(n);!!!e.port&&process.env.NEXT_PUBLIC_PORT_BE&&(n=e.origin+r(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}))}else n="http://localhost"+r(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});e=t(e).length?t(e):"/";const i=new URL(n.replace(/\/+$/,"")).origin;return`${i}${"/"===e?"/":`${e.startsWith("/")?"":"/"}${e.replace(/\/+$/,"")}`}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+e)}},w=()=>{var e,o;try{const n=null==(e=process.env.NEXT_PUBLIC_BASE_URL)?void 0:e.trim(),i=null==(o=process.env.NEXT_PUBLIC_PORT_FE)?void 0:o.trim();let a=n||"http://localhost";a=t(a).replace(/\/+$/,"");const s=/:\/\/[^/]+:\d+/.test(a);!s&&i?a+=r(i,{prefixColon:!0}):s||n||(a+=":3000");const p=new URL(a);return`${p.protocol}//${p.hostname}${p.port?`:${p.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}};export{g as createBeApiUrl,d as generateRoute,w as getBaseUrl,v as getBeApiUrl};
@@ -1,2 +1 @@
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
- exports.getClientIpOrUrl=g;
1
+ "use strict";var e=require("../../chunk-INUFZJLX.cjs");require("server-only");var r=require("next/server");exports.getClientIpOrUrl=(t,n=!0)=>{if(!e.isFunction(r.NextRequest))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.");if(!(t instanceof r.NextRequest))throw new TypeError("First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.");e.assertIsBoolean(n,{message:({currentType:e,validType:r})=>`Second parameter (\`includeFullUrl\`) must be of type \`${r}\`, but received: \`${e}\`.`});const s=(t.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");"::ffff:127.0.0.1"!==s[0]&&"::1"!==s[0]||(s[0]="127.0.0.1");const o=s.length>1?s[s.length-1].trim():s[0];if(!n)return o;const i=t.headers.get("x-forwarded-proto")||"http",u=t.headers.get("x-forwarded-port")||"3000";return`${"production"===process.env.NODE_ENV?i:"http"}://${o}:${u}`};
@@ -1,28 +1,28 @@
1
1
  import{NextRequest}from'next/server';
2
2
  /** ---------------------------------
3
- * * ***Utility for NextJS Server: `getClientIpOrUrl`.***
4
- * ---------------------------------
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`.
11
- * @returns {string} The extracted client IP address or the full constructed URL.
12
- * @throws {Error} If the function is used outside a Next.js server environment.
13
- * @throws {TypeError} If the arguments do not match the expected types.
14
- * @example
15
- * // Basic usage in Next.js middleware
16
- * import { NextRequest } from "next/server";
17
- * import { getClientIpOrUrl } from "@rzl-zone/utils-js/next/server";
18
- *
19
- * export function middleware(request: NextRequest) {
20
- * const clientIp = getClientIpOrUrl(request, false);
21
- * console.log("Client IP:", clientIp);
22
- * }
23
- *
24
- * // Get full URL
25
- * const url = getClientIpOrUrl(request);
26
- * console.log("Client full URL:", url);
27
- */
3
+ * * ***Utility for NextJS Server: `getClientIpOrUrl`.***
4
+ * ---------------------------------
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`.
11
+ * @returns {string} The extracted client IP address or the full constructed URL.
12
+ * @throws {Error} If the function is used outside a Next.js server environment.
13
+ * @throws {TypeError} If the arguments do not match the expected types.
14
+ * @example
15
+ * // Basic usage in Next.js middleware
16
+ * import { NextRequest } from "next/server";
17
+ * import { getClientIpOrUrl } from "@rzl-zone/utils-js/next/server";
18
+ *
19
+ * export function middleware(request: NextRequest) {
20
+ * const clientIp = getClientIpOrUrl(request, false);
21
+ * console.log("Client IP:", clientIp);
22
+ * }
23
+ *
24
+ * // Get full URL
25
+ * const url = getClientIpOrUrl(request);
26
+ * console.log("Client full URL:", url);
27
+ */
28
28
  declare const getClientIpOrUrl:(request:NextRequest,includeFullUrl?:boolean)=>string;export{getClientIpOrUrl};
@@ -1,2 +1 @@
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
- export{g as getClientIpOrUrl};
1
+ import{isFunction as e,assertIsBoolean as r}from"../../chunk-2UIRWYE3.js";import"server-only";import{NextRequest as t}from"next/server";var o=(o,n=!0)=>{if(!e(t))throw new Error("Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.");if(!(o instanceof t))throw new TypeError("First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.");r(n,{message:({currentType:e,validType:r})=>`Second parameter (\`includeFullUrl\`) must be of type \`${r}\`, but received: \`${e}\`.`});const s=(o.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");"::ffff:127.0.0.1"!==s[0]&&"::1"!==s[0]||(s[0]="127.0.0.1");const i=s.length>1?s[s.length-1].trim():s[0];if(!n)return i;const p=o.headers.get("x-forwarded-proto")||"http",a=o.headers.get("x-forwarded-port")||"3000";return`${"production"===process.env.NODE_ENV?p:"http"}://${i}:${a}`};export{o as getClientIpOrUrl};