@rzl-zone/utils-js 3.0.2-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 (198) 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 +398 -418
  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 +1368 -1515
  73. package/dist/conversions/index.js +1 -1
  74. package/dist/env/index.cjs +1 -1
  75. package/dist/env/index.d.ts +14 -17
  76. package/dist/env/index.js +1 -1
  77. package/dist/events/index.cjs +1 -1
  78. package/dist/events/index.d.ts +111 -108
  79. package/dist/events/index.js +1 -1
  80. package/dist/extends-Bk_SBGdT.d.ts +367 -0
  81. package/dist/formatting/index.cjs +1 -1
  82. package/dist/formatting/index.d.ts +878 -840
  83. package/dist/formatting/index.js +1 -1
  84. package/dist/generator/index.cjs +1 -1
  85. package/dist/generator/index.d.ts +173 -150
  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 +169 -0
  90. package/dist/never-BfayMBF9.d.ts +64 -64
  91. package/dist/next/index.cjs +1 -8
  92. package/dist/next/index.d.ts +196 -176
  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 +26 -40
  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 +121 -176
  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 +35 -36
  105. package/dist/parsers/index.js +1 -1
  106. package/dist/predicates/index.cjs +1 -1
  107. package/dist/predicates/index.d.ts +1797 -1677
  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 -38
  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 +351 -0
  115. package/dist/strings/index.cjs +1 -1
  116. package/dist/strings/index.d.ts +712 -787
  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 +384 -409
  125. package/dist/urls/index.js +1 -1
  126. package/package.json +61 -18
  127. package/dist/array-CIZRbqTF.d.ts +0 -223
  128. package/dist/chunk-2TRAPBZ7.cjs +0 -1
  129. package/dist/chunk-3D74QO5D.cjs +0 -1
  130. package/dist/chunk-4DK3RCC4.js +0 -2
  131. package/dist/chunk-4JOQ45HL.js +0 -1
  132. package/dist/chunk-55CZALRS.js +0 -1
  133. package/dist/chunk-56QBKKRE.js +0 -1
  134. package/dist/chunk-5JFV3GDE.cjs +0 -4
  135. package/dist/chunk-5SZUSNGZ.js +0 -1
  136. package/dist/chunk-62HX5Z45.cjs +0 -1
  137. package/dist/chunk-7NA6DUHR.cjs +0 -2
  138. package/dist/chunk-7YWAQOA4.cjs +0 -1
  139. package/dist/chunk-BVPMMWDL.cjs +0 -1
  140. package/dist/chunk-BYZAD3XN.cjs +0 -1
  141. package/dist/chunk-CEFYHEM4.cjs +0 -1
  142. package/dist/chunk-CN53M4QZ.cjs +0 -1
  143. package/dist/chunk-D47MHBSD.cjs +0 -1
  144. package/dist/chunk-DGH75GJD.js +0 -1
  145. package/dist/chunk-E5NUI7PN.js +0 -1
  146. package/dist/chunk-ELDDNERR.js +0 -1
  147. package/dist/chunk-EXZ47NOW.js +0 -1
  148. package/dist/chunk-FDITZ5C6.cjs +0 -1
  149. package/dist/chunk-FF76ISQ2.js +0 -1
  150. package/dist/chunk-FIEZKTAZ.cjs +0 -1
  151. package/dist/chunk-FSSV24W7.cjs +0 -1
  152. package/dist/chunk-GCGU2WB7.js +0 -1
  153. package/dist/chunk-GECI2YBP.js +0 -1
  154. package/dist/chunk-GQE4OVHC.cjs +0 -1
  155. package/dist/chunk-GRVZXQXL.cjs +0 -1
  156. package/dist/chunk-I4AVNHPA.cjs +0 -1
  157. package/dist/chunk-JFRL7NKU.js +0 -4
  158. package/dist/chunk-JWHM3WZQ.cjs +0 -1
  159. package/dist/chunk-KCQDDZJE.cjs +0 -1
  160. package/dist/chunk-L54ZPSYJ.js +0 -1
  161. package/dist/chunk-LVKAYEZ4.js +0 -1
  162. package/dist/chunk-MBDWTK54.cjs +0 -1
  163. package/dist/chunk-MNGGDB2G.js +0 -1
  164. package/dist/chunk-MY7BA4GI.cjs +0 -1
  165. package/dist/chunk-N2IJPIND.cjs +0 -1
  166. package/dist/chunk-NIMNTEGV.js +0 -1
  167. package/dist/chunk-NNM7QCNB.js +0 -1
  168. package/dist/chunk-PUQXRLZH.cjs +0 -1
  169. package/dist/chunk-PVJF2JHM.js +0 -1
  170. package/dist/chunk-QCFXEUKL.js +0 -1
  171. package/dist/chunk-QFCGBBSY.js +0 -1
  172. package/dist/chunk-QQYAUPSK.cjs +0 -1
  173. package/dist/chunk-RN3TP3S3.js +0 -1
  174. package/dist/chunk-RV2VULM7.cjs +0 -1
  175. package/dist/chunk-SW6HYEW7.cjs +0 -1
  176. package/dist/chunk-SYJC7UAW.js +0 -1
  177. package/dist/chunk-TC4VBE4Y.cjs +0 -1
  178. package/dist/chunk-TUXDINHF.cjs +0 -1
  179. package/dist/chunk-U5Y2FXMN.cjs +0 -1
  180. package/dist/chunk-UUPQI6ND.cjs +0 -1
  181. package/dist/chunk-VYCGZ2S6.js +0 -1
  182. package/dist/chunk-W5EDKJK3.js +0 -1
  183. package/dist/chunk-WHAVUFEU.js +0 -1
  184. package/dist/chunk-XCFIOTCV.js +0 -1
  185. package/dist/chunk-XE27XPJR.js +0 -1
  186. package/dist/chunk-XH6MCRLP.js +0 -1
  187. package/dist/chunk-XVB3ZZEB.js +0 -1
  188. package/dist/chunk-ZBSIGJFO.cjs +0 -1
  189. package/dist/chunk-ZYAML74V.js +0 -1
  190. package/dist/extends-Mp81Hq9-.d.ts +0 -145
  191. package/dist/index.cjs +0 -1
  192. package/dist/index.d.ts +0 -1
  193. package/dist/index.js +0 -1
  194. package/dist/is-array-Ckm_47hw.d.ts +0 -1557
  195. package/dist/isPlainObject-BKYaI6a8.d.ts +0 -182
  196. package/dist/stylings/index.cjs +0 -1
  197. package/dist/stylings/index.d.ts +0 -49
  198. package/dist/stylings/index.js +0 -1
@@ -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,
5
- * 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
- *
10
- * @template T - The route string containing potential dynamic segments.
11
- *
12
- * @example
13
- * ```ts
14
- * type Params1 = ExtractRouteParams<"/user/[id]">;
15
- * // Result: { id: string }
16
- *
17
- * type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
18
- * // Result: { slug: string; commentId: string }
19
- *
20
- * type Params3 = ExtractRouteParams<"/dashboard">;
21
- * // Result: {} (no dynamic parameters)
22
- * ```
23
- */
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
+ */
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
- *
32
- * @template T - The route string to be evaluated.
33
- *
34
- * @example
35
- * ```ts
36
- * type HasParams1 = HasDynamicSegments<"/user/[id]">;
37
- * // Result: true
38
- *
39
- * type HasParams2 = HasDynamicSegments<"/settings/profile">;
40
- * // Result: false
41
- *
42
- * type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
43
- * // Result: true
44
- * ```
45
- */
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
+ */
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
- * * ***Generates a URL by replacing dynamic route parameters with provided values.***
49
- * ---------------------------------
50
- *
51
- * * ⚠️ ***Notes: This Function only support when using `NextJS`***
52
- *
53
- * @template T - The route string containing dynamic segments in the format `[param]`.
54
- *
55
- * @param {T} route - The route string containing dynamic segments.
56
- * @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
57
- *
58
- * @returns {string} The formatted URL with all dynamic segments replaced.
59
- *
60
- * @throws {Error} If the route contains dynamic segments but no parameters object is provided.
61
- * @throws {Error} If a required parameter is missing from the `params` object.
62
- * @throws {Error} If a parameter value is an empty string.
63
- * @throws {Error} If any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
64
- *
65
- * @example
66
- * // Basic usage
67
- * generateRoute("/user/[id]", { id: "123" });
68
- * // Returns: "/user/123"
69
- *
70
- * @example
71
- * // No dynamic segments, returns as-is
72
- * generateRoute("/dashboard");
73
- * // Returns: "/dashboard"
74
- *
75
- * @example
76
- * // Throws an error due to missing parameters object
77
- * generateRoute("/profile/[username]");
78
- * // Error: Missing parameters object for route: "/profile/[username]"
79
- *
80
- * @example
81
- * // Throws an error due to an empty parameter value
82
- * generateRoute("/post/[category]/[slug]", { category: "tech", slug: "" });
83
- * // ❌ Error: ❌ Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
84
- *
85
- * @example
86
- * // Throws an error due to parameter containing invalid characters
87
- * generateRoute("/search/[query]", { query: "how to?learn" });
88
- * // ❌ Error: ❌ Parameter "query" contains invalid character "?" in route: "/search/[query]"
89
- *
90
- * @example
91
- * // Handles leading/trailing slashes correctly
92
- * generateRoute("/blog/[category]/[slug]", { category: "/news/", slug: "/latest-update/" });
93
- * // ❌ Error: ❌ Parameter "category" and "slug" contains slashes "/" which is not allowed.
94
- */
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;
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
+ 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
- * * ***Constructs a backend API URL by appending a given pathname to the base API URL.***
98
- * ---------------------------------
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.
114
- * @returns {string} The formatted API URL.
115
- *
116
- * @throws {TypeError} If `withOrigin` is not a boolean.
117
- * @throws {TypeError} If `prefix` and `pathname` is not a string.
118
- * @throws {Error} If constructing the API URL fails due to an invalid base URL.
119
- *
120
- * @example
121
- * createBeApiUrl("/users")
122
- * // -> "http://localhost:8000/api/users"
123
- *
124
- * createBeApiUrl("/users", { withOrigin: false })
125
- * // -> "/api/users"
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
- 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)`.
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`***
149
- *
150
- * This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
151
- * - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
152
- * - If `NEXT_PUBLIC_BACKEND_API_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_BE` if available.
153
- * - 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.
158
- * @returns {string} The formatted backend API base URL.
159
- * @throws {TypeError} If `suffix` is not a `string`.
160
- * @throws {Error} If `NEXT_PUBLIC_BACKEND_API_URL` is invalid.
161
- */
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
- /** ---------------------------------
168
- * * ***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
- *
180
- * @returns {string} The resolved base URL of the application.
181
- * @throws {Error} If the constructed URL is invalid or malformed.
182
- *
183
- */
129
+ *
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: `"/"`.
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
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
+ declare const getBeApiUrl:({suffix}?:OptionsGetBeApiUrl)=>string;
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
+ */
184
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-JFRL7NKU.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:
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}":
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}":
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};
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 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}`};
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,42 +1,28 @@
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`.***
5
- * ---------------------------------
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
- *
15
- * @returns {string} The extracted client IP address or the full constructed URL.
16
- *
17
- * @throws {Error} If the function is used outside a Next.js server environment.
18
- * @throws {TypeError} If the arguments do not match the expected types.
19
- *
20
- * @example
21
- * // Basic usage in Next.js middleware
22
- * import { NextRequest } from "next/server";
23
- * import { getClientIpOrUrl } from "@rzl-zone/utils-js/next/server";
24
- *
25
- * export function middleware(request: NextRequest) {
26
- * const clientIp = getClientIpOrUrl(request, false);
27
- * console.log("Client IP:", clientIp);
28
- * }
29
- *
30
- * @example
31
- * // Get full URL
32
- * const url = getClientIpOrUrl(request);
33
- * console.log("Client full URL:", url);
34
- */
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};
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
+ declare const getClientIpOrUrl:(request:NextRequest,includeFullUrl?:boolean)=>string;export{getClientIpOrUrl};
@@ -1,2 +1 @@
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}`};
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};