@rzl-zone/utils-js 3.7.1 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -1
- package/dist/assertions/index.cjs +11 -11
- package/dist/assertions/index.d.ts +169 -58
- package/dist/assertions/index.js +5 -5
- package/dist/{chunk-EK7FSI7F.cjs → chunk-2XGQQZ6A.cjs} +3 -3
- package/dist/{chunk-YS27V6LS.js → chunk-3LE6NX57.js} +5 -176
- package/dist/{chunk-PZQC3FZY.js → chunk-44X74C26.js} +4 -4
- package/dist/{chunk-4ACKNPL5.js → chunk-5KDVIEVO.js} +2 -2
- package/dist/{chunk-JY4HLZ4W.js → chunk-5O66AUEC.js} +2 -2
- package/dist/chunk-5Y6JL47L.js +302 -0
- package/dist/{chunk-KIYALQQF.cjs → chunk-62FS7WMB.cjs} +35 -35
- package/dist/{chunk-VJVCXEH7.cjs → chunk-6AMDHVS2.cjs} +9 -181
- package/dist/{chunk-6PKW4WCT.js → chunk-6WVOUVWD.js} +27 -15
- package/dist/{chunk-BYUT376O.cjs → chunk-76ATVDCR.cjs} +3 -3
- package/dist/{chunk-F3WBQKRI.cjs → chunk-7C7TQC5J.cjs} +29 -7
- package/dist/{chunk-QUITZ3GP.js → chunk-7EIFPHV3.js} +32 -16
- package/dist/{chunk-6RFNZ2ZZ.cjs → chunk-7NXFGJJE.cjs} +14 -14
- package/dist/{chunk-TFDXRT6D.cjs → chunk-ALRISPTL.cjs} +3 -3
- package/dist/chunk-BAV5T2E3.cjs +1 -1
- package/dist/{chunk-4ZOXSUXB.js → chunk-C7GC2PFX.js} +3 -3
- package/dist/chunk-DVMHRLKP.cjs +1 -1
- package/dist/{chunk-XFTUHS4Y.js → chunk-DXPM4NOU.js} +10 -8
- package/dist/{chunk-DPLL67OT.js → chunk-EJV5AF4L.js} +2 -2
- package/dist/{chunk-NREACG6M.cjs → chunk-FWWPEL7J.cjs} +3 -3
- package/dist/{chunk-LEX4TQW2.js → chunk-GHU356XQ.js} +4 -6
- package/dist/chunk-GKDSBOYE.js +209 -0
- package/dist/{chunk-YC7AK3KX.cjs → chunk-H44QVAZL.cjs} +31 -31
- package/dist/{chunk-AKKM6MOX.cjs → chunk-I33PB44Q.cjs} +15 -15
- package/dist/{chunk-LIU4S3JA.cjs → chunk-IX6PF5ZP.cjs} +4 -4
- package/dist/{chunk-3KTD3QDI.js → chunk-J4TT33ZX.js} +29 -7
- package/dist/{chunk-SZJ7OI4S.js → chunk-J6VLFVIL.js} +3 -3
- package/dist/{chunk-KTQLDIIT.cjs → chunk-JI57K7D4.cjs} +173 -163
- package/dist/{chunk-OFBFGFVH.js → chunk-JYOCB6OV.js} +2 -2
- package/dist/chunk-KHO2SBNA.cjs +1 -1
- package/dist/{chunk-66WLOZOD.cjs → chunk-KUVRZ2JW.cjs} +53 -51
- package/dist/chunk-L5RDAVVH.js +1 -1
- package/dist/{chunk-VCVND6CH.js → chunk-M5QB2GM5.js} +2 -2
- package/dist/{chunk-3LEWQV3R.js → chunk-MBFVTGYS.js} +8 -8
- package/dist/{chunk-UKAUXY2U.cjs → chunk-MMRHKYT6.cjs} +12 -12
- package/dist/{chunk-U5VR4TJN.js → chunk-MS2KSKD7.js} +9 -9
- package/dist/{chunk-7ZNEUWYP.js → chunk-MZ3T6L7Z.js} +2 -2
- package/dist/{chunk-ATLFMKAF.cjs → chunk-NAOVH4OH.cjs} +7 -7
- package/dist/chunk-NJ24M6ZH.cjs +308 -0
- package/dist/chunk-OCTHWEZK.cjs +249 -0
- package/dist/chunk-ONZFBJVW.js +1 -1
- package/dist/{chunk-FI76UZRF.js → chunk-OSSFLQDD.js} +3 -4
- package/dist/{chunk-7WBMA2VE.cjs → chunk-OYFUBKEG.cjs} +4 -5
- package/dist/{chunk-B4SDEBN7.cjs → chunk-PWKOFPAH.cjs} +3 -3
- package/dist/{chunk-2CQI36UD.cjs → chunk-QGTFQ7RO.cjs} +8 -6
- package/dist/chunk-QNKGP5DY.js +1 -1
- package/dist/chunk-QXTJVDWE.js +676 -0
- package/dist/{chunk-B6UIKBHR.cjs → chunk-QZI5PVCI.cjs} +4 -4
- package/dist/{chunk-WNO3EPYT.js → chunk-R2DR7SPJ.js} +102 -26
- package/dist/{chunk-TDYGYHSH.js → chunk-SN5HAK3Y.js} +4 -4
- package/dist/{chunk-D53CE4BT.js → chunk-SRWL4YCP.js} +11 -8
- package/dist/{chunk-7QQV66RX.cjs → chunk-TJ5OY6MC.cjs} +10 -10
- package/dist/{chunk-6WMB5AJR.js → chunk-TXOVQZPU.js} +3 -4
- package/dist/chunk-UDA26MCU.cjs +1 -1
- package/dist/{chunk-R3PBF6F7.cjs → chunk-UFYMRRJH.cjs} +73 -61
- package/dist/{chunk-5NN4ZDE2.cjs → chunk-UV5BKAYW.cjs} +6 -8
- package/dist/{chunk-GAJBF6DR.js → chunk-UXT4XSUK.js} +2 -2
- package/dist/{chunk-TDPYR5JY.js → chunk-VBSLIIDB.js} +24 -14
- package/dist/chunk-VCYXNIZ2.cjs +678 -0
- package/dist/chunk-VJDDGRIK.cjs +1 -1
- package/dist/{chunk-VNADVWSJ.js → chunk-WB3FT62A.js} +6 -4
- package/dist/{chunk-K63WO3XA.cjs → chunk-WKM6UVMG.cjs} +4 -5
- package/dist/{chunk-OS5OT5JA.cjs → chunk-WLEZ2KSG.cjs} +142 -126
- package/dist/{chunk-ZN53RM3R.js → chunk-WRGN6UBK.js} +2 -2
- package/dist/chunk-WVSPXFTY.js +1 -1
- package/dist/{chunk-2VO2CBTU.js → chunk-X6ULJZ3X.js} +2 -2
- package/dist/{chunk-CKUEZF4R.cjs → chunk-XYWC4EQ3.cjs} +71 -71
- package/dist/{chunk-A3YI6Y2P.js → chunk-YHFRCVTN.js} +3 -3
- package/dist/{chunk-RMJC3B5P.cjs → chunk-YQHJB7KR.cjs} +30 -27
- package/dist/{chunk-YGB2BQPB.cjs → chunk-YVRUY4EW.cjs} +8 -8
- package/dist/chunk-YWHHVDT4.js +1 -1
- package/dist/chunk-ZTHJQJ5F.cjs +211 -0
- package/dist/conversions/index.cjs +34 -34
- package/dist/conversions/index.d.ts +10 -12
- package/dist/conversions/index.js +15 -15
- package/dist/events/index.cjs +8 -8
- package/dist/events/index.d.ts +9 -9
- package/dist/events/index.js +4 -4
- package/dist/formatters/index.cjs +19 -19
- package/dist/formatters/index.d.ts +19 -24
- package/dist/formatters/index.js +9 -9
- package/dist/generators/index.cjs +12 -8
- package/dist/generators/index.d.ts +155 -26
- package/dist/generators/index.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/{isPlainObject-FWmcJF6k.d.ts → isPlainObject-BTPjv6zB.d.ts} +2 -2
- package/dist/next/index.cjs +39 -36
- package/dist/next/index.d.ts +11 -11
- package/dist/next/index.js +12 -9
- package/dist/next/server/index.cjs +4 -4
- package/dist/next/server/index.d.ts +4 -4
- package/dist/next/server/index.js +2 -2
- package/dist/operations/index.cjs +11 -11
- package/dist/operations/index.d.ts +8 -9
- package/dist/operations/index.js +8 -8
- package/dist/parsers/index.cjs +6 -4
- package/dist/parsers/index.d.ts +224 -32
- package/dist/parsers/index.js +5 -3
- package/dist/predicates/index.cjs +77 -76
- package/dist/predicates/index.d.ts +15 -28
- package/dist/predicates/index.js +14 -13
- package/dist/promises/index.cjs +6 -6
- package/dist/promises/index.d.ts +5 -7
- package/dist/promises/index.js +4 -4
- package/dist/rzl-utils.global.js +2 -2
- package/dist/strings/index.cjs +23 -23
- package/dist/strings/index.d.ts +1 -1
- package/dist/strings/index.js +7 -7
- package/dist/tailwind/index.cjs +13 -13
- package/dist/tailwind/index.d.ts +18 -18
- package/dist/tailwind/index.js +5 -5
- package/dist/urls/index.cjs +23 -21
- package/dist/urls/index.d.ts +188 -121
- package/dist/urls/index.js +16 -14
- package/package.json +1 -1
- package/dist/chunk-ABA2ZSBQ.js +0 -152
- package/dist/chunk-BG3AS5BU.cjs +0 -173
- package/dist/chunk-K3SONK25.cjs +0 -157
- package/dist/chunk-KPCDDYTZ.js +0 -417
- package/dist/chunk-QAPYHLHC.cjs +0 -419
package/dist/next/index.cjs
CHANGED
|
@@ -2,40 +2,43 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
require('../chunk-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
12
|
+
var chunkOCTHWEZK_cjs = require('../chunk-OCTHWEZK.cjs');
|
|
13
|
+
require('../chunk-6AMDHVS2.cjs');
|
|
14
|
+
require('../chunk-ZTHJQJ5F.cjs');
|
|
15
|
+
var chunkIX6PF5ZP_cjs = require('../chunk-IX6PF5ZP.cjs');
|
|
16
|
+
var chunkFWWPEL7J_cjs = require('../chunk-FWWPEL7J.cjs');
|
|
17
|
+
var chunkWKM6UVMG_cjs = require('../chunk-WKM6UVMG.cjs');
|
|
18
|
+
var chunkH44QVAZL_cjs = require('../chunk-H44QVAZL.cjs');
|
|
18
19
|
require('../chunk-UDA26MCU.cjs');
|
|
19
|
-
var
|
|
20
|
+
var chunk7C7TQC5J_cjs = require('../chunk-7C7TQC5J.cjs');
|
|
20
21
|
|
|
21
22
|
function generateRoute(route, params) {
|
|
22
|
-
if (!
|
|
23
|
+
if (!chunk7C7TQC5J_cjs.isString(route) || chunkFWWPEL7J_cjs.isEmptyString(route)) {
|
|
23
24
|
throw new TypeError(
|
|
24
25
|
`\u274C 'generateRoute' Failed:
|
|
25
26
|
- Invalid 'route' value.
|
|
26
|
-
- Must be of type \`string\` and non-empty string, but received: "${
|
|
27
|
+
- Must be of type \`string\` and non-empty string, but received: "${chunk7C7TQC5J_cjs.getPreciseType(
|
|
27
28
|
route
|
|
28
|
-
)}": \`${
|
|
29
|
+
)}": \`${chunkH44QVAZL_cjs.safeStableStringify(route, {
|
|
30
|
+
keepUndefined: true
|
|
31
|
+
})}\`.`
|
|
29
32
|
);
|
|
30
33
|
}
|
|
31
34
|
if (!/[\\[\]]/.test(route)) {
|
|
32
35
|
return route;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
chunk7C7TQC5J_cjs.assertIsPlainObject(params, {
|
|
35
38
|
message: ({ validType }) => `\u274C 'generateRoute' Failed cause in route "${route}":
|
|
36
39
|
- Missing or invalid parameters \`${validType}\` for route: "${route}", must be of type \`${validType}\` mapping parameters.`
|
|
37
40
|
});
|
|
38
|
-
if (
|
|
41
|
+
if (chunk7C7TQC5J_cjs.isNil(params)) {
|
|
39
42
|
throw new TypeError(
|
|
40
43
|
`\u274C 'generateRoute' Failed cause in route "${route}":
|
|
41
44
|
- Missing parameters \`plain-object\` for route: "${route}".`
|
|
@@ -64,15 +67,15 @@ function generateRoute(route, params) {
|
|
|
64
67
|
const requiredKeys = Array.from(route.matchAll(/\[(\w+)\]/g)).map((m) => m[1]);
|
|
65
68
|
for (const key of requiredKeys) {
|
|
66
69
|
const value = params[key];
|
|
67
|
-
if (!
|
|
70
|
+
if (!chunk7C7TQC5J_cjs.isString(value)) {
|
|
68
71
|
errors.push(
|
|
69
|
-
`- Invalid parameter: "${key}" must be of type \`string\`, but received: \`${
|
|
72
|
+
`- Invalid parameter: "${key}" must be of type \`string\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
|
|
70
73
|
value
|
|
71
74
|
)}\`.`
|
|
72
75
|
);
|
|
73
76
|
continue;
|
|
74
77
|
}
|
|
75
|
-
if (
|
|
78
|
+
if (chunkFWWPEL7J_cjs.isEmptyString(value)) {
|
|
76
79
|
errors.push(`- Parameter "${key}" cannot be empty string.`);
|
|
77
80
|
continue;
|
|
78
81
|
}
|
|
@@ -97,14 +100,14 @@ function generateRoute(route, params) {
|
|
|
97
100
|
);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
if (
|
|
103
|
+
if (chunk7C7TQC5J_cjs.isNonEmptyArray(errors)) {
|
|
101
104
|
throw new Error(
|
|
102
105
|
`\u274C 'generateRoute' Failed cause in route "${route}":
|
|
103
106
|
${errors.join("\n")}.`
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
109
|
return route.replace(/\[(\w+)\]/g, (_, key) => {
|
|
107
|
-
const paramKey =
|
|
110
|
+
const paramKey = chunk7C7TQC5J_cjs.isNonEmptyString(params[key]) ? params[key] : "";
|
|
108
111
|
return paramKey.trim().replace(/^\/+|\/+$/g, "");
|
|
109
112
|
}).replace(/\/+/g, "/");
|
|
110
113
|
}
|
|
@@ -115,40 +118,40 @@ var createBeApiUrl = (pathname, options = {}) => {
|
|
|
115
118
|
return `${a.replace(/\/+$/, "")}/${b.replace(/^\/+/, "")}`;
|
|
116
119
|
};
|
|
117
120
|
var joinPath = joinPath2;
|
|
118
|
-
|
|
121
|
+
chunkWKM6UVMG_cjs.assertIsString(chunk7C7TQC5J_cjs.isNil(pathname) ? "" : pathname, {
|
|
119
122
|
message({ currentType, validType }) {
|
|
120
123
|
return `First parameter (\`pathname\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
121
124
|
}
|
|
122
125
|
});
|
|
123
|
-
if (!
|
|
126
|
+
if (!chunk7C7TQC5J_cjs.isPlainObject(options)) {
|
|
124
127
|
options = {};
|
|
125
128
|
}
|
|
126
129
|
let {
|
|
127
130
|
prefix = "/api",
|
|
128
131
|
withOrigin = true
|
|
129
132
|
} = options;
|
|
130
|
-
if (!
|
|
133
|
+
if (!chunk7C7TQC5J_cjs.isUndefined(prefix) && !chunk7C7TQC5J_cjs.isString(prefix)) {
|
|
131
134
|
throw new TypeError(
|
|
132
|
-
`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${
|
|
135
|
+
`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${chunk7C7TQC5J_cjs.getPreciseType(
|
|
133
136
|
prefix
|
|
134
137
|
)}\`.`
|
|
135
138
|
);
|
|
136
139
|
}
|
|
137
|
-
|
|
140
|
+
chunk7C7TQC5J_cjs.assertIsBoolean(withOrigin, {
|
|
138
141
|
message: ({ currentType, validType }) => `Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
139
142
|
});
|
|
140
|
-
pathname =
|
|
141
|
-
prefix =
|
|
143
|
+
pathname = chunkOCTHWEZK_cjs.normalizePathname(pathname);
|
|
144
|
+
prefix = chunkOCTHWEZK_cjs.normalizePathname(prefix);
|
|
142
145
|
const normalizedPrefix = prefix.endsWith("/") ? prefix : prefix + "/";
|
|
143
146
|
if (pathname === prefix || pathname === prefix + "/" || pathname.startsWith(normalizedPrefix)) {
|
|
144
147
|
pathname = pathname.slice(prefix.length);
|
|
145
|
-
pathname =
|
|
148
|
+
pathname = chunkOCTHWEZK_cjs.normalizePathname(pathname);
|
|
146
149
|
}
|
|
147
150
|
const baseApiUrl = getBeApiUrl({ suffix: prefix });
|
|
148
151
|
const fullPath = withOrigin ? joinPath2(baseApiUrl, pathname) : joinPath2(new URL(baseApiUrl).pathname, pathname);
|
|
149
152
|
return fullPath.replace(/\/+$/, "");
|
|
150
153
|
} catch (err) {
|
|
151
|
-
if (
|
|
154
|
+
if (chunk7C7TQC5J_cjs.isError(err)) {
|
|
152
155
|
throw err;
|
|
153
156
|
} else
|
|
154
157
|
throw new Error(
|
|
@@ -158,9 +161,9 @@ var createBeApiUrl = (pathname, options = {}) => {
|
|
|
158
161
|
};
|
|
159
162
|
|
|
160
163
|
var getBeApiUrl = (options = {}) => {
|
|
161
|
-
if (!
|
|
162
|
-
let suffix =
|
|
163
|
-
|
|
164
|
+
if (!chunk7C7TQC5J_cjs.isPlainObject(options)) options = {};
|
|
165
|
+
let suffix = chunk7C7TQC5J_cjs.hasOwnProp(options, "suffix") ? options.suffix : "/";
|
|
166
|
+
chunkWKM6UVMG_cjs.assertIsString(suffix, {
|
|
164
167
|
message({ currentType, validType }) {
|
|
165
168
|
return `Parameter \`suffix\` property of the first parameter must be of type \`${validType}\`, but received: \`${currentType}\`.`;
|
|
166
169
|
}
|
|
@@ -168,20 +171,20 @@ var getBeApiUrl = (options = {}) => {
|
|
|
168
171
|
try {
|
|
169
172
|
let rawBaseUrl = process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();
|
|
170
173
|
if (rawBaseUrl) {
|
|
171
|
-
rawBaseUrl =
|
|
174
|
+
rawBaseUrl = chunkIX6PF5ZP_cjs.removeSpaces(rawBaseUrl);
|
|
172
175
|
const urlObj = new URL(rawBaseUrl);
|
|
173
176
|
const hasPort = !!urlObj.port;
|
|
174
177
|
if (!hasPort && process.env.NEXT_PUBLIC_PORT_BE) {
|
|
175
|
-
rawBaseUrl = urlObj.origin +
|
|
178
|
+
rawBaseUrl = urlObj.origin + chunkOCTHWEZK_cjs.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE, {
|
|
176
179
|
prefixColon: true
|
|
177
180
|
});
|
|
178
181
|
}
|
|
179
182
|
} else {
|
|
180
|
-
rawBaseUrl = "http://localhost" +
|
|
183
|
+
rawBaseUrl = "http://localhost" + chunkOCTHWEZK_cjs.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE || "8000", {
|
|
181
184
|
prefixColon: true
|
|
182
185
|
});
|
|
183
186
|
}
|
|
184
|
-
suffix =
|
|
187
|
+
suffix = chunkIX6PF5ZP_cjs.removeSpaces(suffix).length ? chunkIX6PF5ZP_cjs.removeSpaces(suffix) : "/";
|
|
185
188
|
const baseApiUrl = new URL(rawBaseUrl.replace(/\/+$/, "")).origin;
|
|
186
189
|
const finalSuffix = suffix === "/" ? "/" : `${suffix.startsWith("/") ? "" : "/"}${suffix.replace(/\/+$/, "")}`;
|
|
187
190
|
return `${baseApiUrl}${finalSuffix}`;
|
|
@@ -197,10 +200,10 @@ var getBaseUrl = () => {
|
|
|
197
200
|
const baseEnv = process.env.NEXT_PUBLIC_BASE_URL?.trim();
|
|
198
201
|
const portEnv = process.env.NEXT_PUBLIC_PORT_FE?.trim();
|
|
199
202
|
let baseUrl = baseEnv || "http://localhost";
|
|
200
|
-
baseUrl =
|
|
203
|
+
baseUrl = chunkIX6PF5ZP_cjs.removeSpaces(baseUrl).replace(/\/+$/, "");
|
|
201
204
|
const hasPort = /:\/\/[^/]+:\d+/.test(baseUrl);
|
|
202
205
|
if (!hasPort && portEnv) {
|
|
203
|
-
baseUrl +=
|
|
206
|
+
baseUrl += chunkOCTHWEZK_cjs.formatEnvPort(portEnv, { prefixColon: true });
|
|
204
207
|
} else if (!hasPort && !baseEnv) {
|
|
205
208
|
baseUrl += ":3000";
|
|
206
209
|
}
|
package/dist/next/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -57,10 +57,10 @@ type HasDynamicSegments<T>=T extends`${string}[${string}]${string}`?true:false;t
|
|
|
57
57
|
* @param {T} route - The route string containing dynamic segments.
|
|
58
58
|
* @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
|
|
59
59
|
* @returns {string} The formatted URL with all dynamic segments replaced.
|
|
60
|
-
* @throws {Error}
|
|
61
|
-
* @throws {Error}
|
|
62
|
-
* @throws {Error}
|
|
63
|
-
* @throws {Error}
|
|
60
|
+
* @throws **{@link Error | `Error`}** if the route contains dynamic segments but no parameters object is provided.
|
|
61
|
+
* @throws **{@link Error | `Error`}** if a required parameter is missing from the `params` object.
|
|
62
|
+
* @throws **{@link Error | `Error`}** if a parameter value is an empty string.
|
|
63
|
+
* @throws **{@link Error | `Error`}** if any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
|
|
64
64
|
* @example
|
|
65
65
|
* // Basic usage
|
|
66
66
|
* generateRoute("/user/[id]", { id: "123" });
|
|
@@ -115,9 +115,9 @@ withOrigin?:boolean;};
|
|
|
115
115
|
* @param {OptionsCreateBeApiUrl["prefix"]} [options.prefix="/api"] - The prefix for the API path (default is `"/api"`).
|
|
116
116
|
* @param {OptionsCreateBeApiUrl["withOrigin"]} [options.withOrigin=true] - Whether to include the full base URL or return only the API path.
|
|
117
117
|
* @returns {string} The formatted API URL.
|
|
118
|
-
* @throws {TypeError}
|
|
119
|
-
* @throws {TypeError}
|
|
120
|
-
* @throws {Error}
|
|
118
|
+
* @throws **{@link TypeError | `TypeError`}** if `withOrigin` is not a boolean.
|
|
119
|
+
* @throws **{@link TypeError | `TypeError`}** if `prefix` and `pathname` is not a string.
|
|
120
|
+
* @throws **{@link Error | `Error`}** if constructing the API URL fails due to an invalid base URL.
|
|
121
121
|
* @example
|
|
122
122
|
* createBeApiUrl("/users")
|
|
123
123
|
* // ➔ "http://localhost:8000/api/users"
|
|
@@ -163,8 +163,8 @@ suffix?:string;};
|
|
|
163
163
|
* @param {OptionsGetBeApiUrl|undefined} options - Configuration options.
|
|
164
164
|
* @param {OptionsGetBeApiUrl["suffix"]} [options.suffix="/"] - The suffix to append to the base API URL.
|
|
165
165
|
* @returns {string} The formatted backend API base URL.
|
|
166
|
-
* @throws {TypeError}
|
|
167
|
-
* @throws {Error}
|
|
166
|
+
* @throws **{@link TypeError | `TypeError`}** if `suffix` is not a `string`.
|
|
167
|
+
* @throws **{@link Error | `Error`}** if `NEXT_PUBLIC_BACKEND_API_URL` is invalid.
|
|
168
168
|
* @example
|
|
169
169
|
* // With NEXT_PUBLIC_BACKEND_API_URL set at `*.env` file
|
|
170
170
|
* NEXT_PUBLIC_BACKEND_API_URL = "https://api.example.com";
|
|
@@ -195,7 +195,7 @@ declare const getBeApiUrl:(options?:OptionsGetBeApiUrl)=>string;
|
|
|
195
195
|
* - ***⚠️ Warning:***
|
|
196
196
|
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
197
197
|
* @returns {string} The resolved base URL of the application.
|
|
198
|
-
* @throws {Error}
|
|
198
|
+
* @throws **{@link Error | `Error`}** if the constructed URL is invalid or malformed.
|
|
199
199
|
* @example
|
|
200
200
|
* // With environment variable set at `*.env` file
|
|
201
201
|
* NEXT_PUBLIC_BASE_URL = "https://example.com";
|
package/dist/next/index.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
|
-
import { normalizePathname, formatEnvPort } from '../chunk-
|
|
11
|
-
import '../chunk-
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
10
|
+
import { normalizePathname, formatEnvPort } from '../chunk-R2DR7SPJ.js';
|
|
11
|
+
import '../chunk-3LE6NX57.js';
|
|
12
|
+
import '../chunk-GKDSBOYE.js';
|
|
13
|
+
import { removeSpaces } from '../chunk-5KDVIEVO.js';
|
|
14
|
+
import { isEmptyString } from '../chunk-5O66AUEC.js';
|
|
15
|
+
import { assertIsString } from '../chunk-OSSFLQDD.js';
|
|
16
|
+
import { safeStableStringify } from '../chunk-X6ULJZ3X.js';
|
|
16
17
|
import '../chunk-QNKGP5DY.js';
|
|
17
|
-
import { isString, getPreciseType, assertIsPlainObject, isNil, isNonEmptyArray, isNonEmptyString, isPlainObject, isUndefined, assertIsBoolean, isError, hasOwnProp } from '../chunk-
|
|
18
|
+
import { isString, getPreciseType, assertIsPlainObject, isNil, isNonEmptyArray, isNonEmptyString, isPlainObject, isUndefined, assertIsBoolean, isError, hasOwnProp } from '../chunk-J4TT33ZX.js';
|
|
18
19
|
|
|
19
20
|
function generateRoute(route, params) {
|
|
20
21
|
if (!isString(route) || isEmptyString(route)) {
|
|
@@ -23,7 +24,9 @@ function generateRoute(route, params) {
|
|
|
23
24
|
- Invalid 'route' value.
|
|
24
25
|
- Must be of type \`string\` and non-empty string, but received: "${getPreciseType(
|
|
25
26
|
route
|
|
26
|
-
)}": \`${safeStableStringify(route
|
|
27
|
+
)}": \`${safeStableStringify(route, {
|
|
28
|
+
keepUndefined: true
|
|
29
|
+
})}\`.`
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
32
|
if (!/[\\[\]]/.test(route)) {
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var chunk7C7TQC5J_cjs = require('../../chunk-7C7TQC5J.cjs');
|
|
13
13
|
require('server-only');
|
|
14
14
|
var server = require('next/server');
|
|
15
15
|
|
|
16
16
|
var getClientIpOrUrl = (request, includeFullUrl = true) => {
|
|
17
|
-
if (!
|
|
17
|
+
if (!chunk7C7TQC5J_cjs.isFunction(server.NextRequest)) {
|
|
18
18
|
throw new Error(
|
|
19
19
|
"Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment."
|
|
20
20
|
);
|
|
@@ -24,7 +24,7 @@ var getClientIpOrUrl = (request, includeFullUrl = true) => {
|
|
|
24
24
|
"First parameter (`request`) must be an `instance of NextRequest` from `NextJS`."
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
chunk7C7TQC5J_cjs.assertIsBoolean(includeFullUrl, {
|
|
28
28
|
message: ({ currentType, validType }) => `Second parameter (\`includeFullUrl\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
29
29
|
});
|
|
30
30
|
const forwardedIps = (request.headers.get("x-forwarded-for") ?? "127.0.0.1").trim().split(",");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -14,12 +14,12 @@ import{NextRequest}from'next/server';
|
|
|
14
14
|
* **Retrieves the real client IP address and constructs the full URL using headers like `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-port`.**
|
|
15
15
|
* - **ℹ️ Note:**
|
|
16
16
|
* - Only supported in **Next.js** environments (specifically in `server-only` contexts).
|
|
17
|
-
* - Should be used in **middleware** or **server actions** that have access to ***[`NextRequest - NextJS`](https://nextjs.org/docs/app/api-reference/functions/next-request)***.
|
|
17
|
+
* - Should be used in **middleware**, **route-handler** or **server actions** that have access to ***[`NextRequest - NextJS`](https://nextjs.org/docs/app/api-reference/functions/next-request)***.
|
|
18
18
|
* @param {NextRequest} request - The incoming ***`NextJS`*** request object, must be instanceof `NextRequest` from `next/server`.
|
|
19
19
|
* @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`.
|
|
20
20
|
* @returns {string} The extracted client IP address or the full constructed URL.
|
|
21
|
-
* @throws {Error}
|
|
22
|
-
* @throws {TypeError}
|
|
21
|
+
* @throws **{@link Error | `Error`}** if the function is used outside a Next.js server environment.
|
|
22
|
+
* @throws **{@link TypeError | `TypeError`}** if the arguments do not match the expected types.
|
|
23
23
|
* @example
|
|
24
24
|
* // Basic usage in Next.js middleware
|
|
25
25
|
* import { NextRequest } from "next/server";
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
|
-
import { isFunction, assertIsBoolean } from '../../chunk-
|
|
10
|
+
import { isFunction, assertIsBoolean } from '../../chunk-J4TT33ZX.js';
|
|
11
11
|
import 'server-only';
|
|
12
12
|
import { NextRequest } from 'next/server';
|
|
13
13
|
|
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
require('../chunk-
|
|
14
|
-
require('../chunk-
|
|
15
|
-
require('../chunk-
|
|
16
|
-
require('../chunk-
|
|
12
|
+
var chunkYQHJB7KR_cjs = require('../chunk-YQHJB7KR.cjs');
|
|
13
|
+
require('../chunk-KUVRZ2JW.cjs');
|
|
14
|
+
require('../chunk-TJ5OY6MC.cjs');
|
|
15
|
+
require('../chunk-NAOVH4OH.cjs');
|
|
16
|
+
require('../chunk-OYFUBKEG.cjs');
|
|
17
17
|
require('../chunk-BAV5T2E3.cjs');
|
|
18
|
-
require('../chunk-
|
|
18
|
+
require('../chunk-H44QVAZL.cjs');
|
|
19
19
|
require('../chunk-UDA26MCU.cjs');
|
|
20
|
-
require('../chunk-
|
|
20
|
+
require('../chunk-7C7TQC5J.cjs');
|
|
21
21
|
|
|
22
22
|
Object.defineProperty(exports, "findDuplicates", {
|
|
23
23
|
enumerable: true,
|
|
24
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunkYQHJB7KR_cjs.findDuplicates; }
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "omitKeys", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunkYQHJB7KR_cjs.omitKeys; }
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "omitKeysDeep", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function () { return
|
|
32
|
+
get: function () { return chunkYQHJB7KR_cjs.omitKeysDeep; }
|
|
33
33
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -13,7 +13,7 @@ import{NumberRangeUnion}from'@rzl-zone/ts-types-plus';
|
|
|
13
13
|
* ----------------------------------------------------------------------
|
|
14
14
|
* **Finds duplicate values in an array by deep equality comparison.**
|
|
15
15
|
* - **Behavior:**
|
|
16
|
-
* - Uses
|
|
16
|
+
* - Uses ***`isEqual` utility function*** to compare elements
|
|
17
17
|
* (handles objects, arrays, dates, NaN, etc.).
|
|
18
18
|
* - Returns a new array containing only the *first occurrences* of duplicated values.
|
|
19
19
|
* - Does **not mutate** the original array.
|
|
@@ -22,7 +22,7 @@ import{NumberRangeUnion}from'@rzl-zone/ts-types-plus';
|
|
|
22
22
|
* @param {T[]} values - The array to check for duplicates.
|
|
23
23
|
* @returns {T[]} An array of the duplicate values found in the input,
|
|
24
24
|
* preserving order of their first duplicate appearance.
|
|
25
|
-
* @throws {TypeError}
|
|
25
|
+
* @throws **{@link TypeError | `TypeError`}** if the provided `values` argument is not an array.
|
|
26
26
|
* @example
|
|
27
27
|
* findDuplicates([1, 2, 2, 3, 4, 4]);
|
|
28
28
|
* // ➔ [2, 4]
|
|
@@ -47,15 +47,15 @@ declare const findDuplicates:<T>(values:T[])=>T[];
|
|
|
47
47
|
* - It will return a new object without mutating the original.
|
|
48
48
|
* - It also validates that ***`keysToOmit`*** does not contain duplicate keys.
|
|
49
49
|
* - **ℹ️ Internally:**
|
|
50
|
-
* - It uses
|
|
50
|
+
* - It uses ***`isEqual`*** to check for duplicates in
|
|
51
51
|
* the ***`keysToOmit`*** array.
|
|
52
52
|
* @template I The type of the input object.
|
|
53
53
|
* @template K The keys to omit from the object.
|
|
54
54
|
* @param {I} object - The source object to omit keys from.
|
|
55
55
|
* @param {K[]} keysToOmit - An array of keys to exclude from the returned object.
|
|
56
56
|
* @returns {Omit<I, K>} A new object without the specified keys.
|
|
57
|
-
* @throws {TypeError}
|
|
58
|
-
* @throws {Error}
|
|
57
|
+
* @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.
|
|
58
|
+
* @throws **{@link Error | `Error`}** if duplicate keys are found in `keysToOmit`.
|
|
59
59
|
* @example
|
|
60
60
|
* omitKeys({ a: 1, b: 2, c: 3 }, ["b", "c"]);
|
|
61
61
|
* //➔ { a: 1 }
|
|
@@ -90,9 +90,8 @@ declare const omitKeys:<I extends Record<string,unknown>,K extends keyof I>(obje
|
|
|
90
90
|
* @returns {Partial<I>}
|
|
91
91
|
* A new deeply cloned object with the specified keys omitted, with resulting
|
|
92
92
|
* empty objects or arrays fully removed (even if it collapses to `{}`).
|
|
93
|
-
* @throws {TypeError}
|
|
94
|
-
*
|
|
95
|
-
* @throws {Error} If `keysToOmit` contains duplicate paths will throw Error.
|
|
93
|
+
* @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.
|
|
94
|
+
* @throws **{@link Error | `Error`}** if `keysToOmit` contains duplicate paths.
|
|
96
95
|
* @example
|
|
97
96
|
* omitKeysDeep({ arr: [{ a: 1 }] }, ["arr.0.a"]);
|
|
98
97
|
* // ➔ {} (array becomes empty and removed)
|
package/dist/operations/index.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
|
-
export { findDuplicates, omitKeys, omitKeysDeep } from '../chunk-
|
|
11
|
-
import '../chunk-
|
|
12
|
-
import '../chunk-
|
|
13
|
-
import '../chunk-
|
|
14
|
-
import '../chunk-
|
|
10
|
+
export { findDuplicates, omitKeys, omitKeysDeep } from '../chunk-SRWL4YCP.js';
|
|
11
|
+
import '../chunk-DXPM4NOU.js';
|
|
12
|
+
import '../chunk-J6VLFVIL.js';
|
|
13
|
+
import '../chunk-M5QB2GM5.js';
|
|
14
|
+
import '../chunk-TXOVQZPU.js';
|
|
15
15
|
import '../chunk-YWHHVDT4.js';
|
|
16
|
-
import '../chunk-
|
|
16
|
+
import '../chunk-X6ULJZ3X.js';
|
|
17
17
|
import '../chunk-QNKGP5DY.js';
|
|
18
|
-
import '../chunk-
|
|
18
|
+
import '../chunk-J4TT33ZX.js';
|
package/dist/parsers/index.cjs
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.0.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
require('../chunk-
|
|
12
|
+
var chunkVCYXNIZ2_cjs = require('../chunk-VCYXNIZ2.cjs');
|
|
13
|
+
require('../chunk-ZTHJQJ5F.cjs');
|
|
14
|
+
require('../chunk-WKM6UVMG.cjs');
|
|
15
|
+
require('../chunk-7C7TQC5J.cjs');
|
|
14
16
|
|
|
15
17
|
Object.defineProperty(exports, "extractFileName", {
|
|
16
18
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
19
|
+
get: function () { return chunkVCYXNIZ2_cjs.extractFileName; }
|
|
18
20
|
});
|