@rzl-zone/utils-js 3.2.6-beta.0 → 3.3.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 +14 -16
- package/dist/NumberRangeUnion-B6bhM2s7.d.ts +33 -0
- package/dist/{any-BmdI8UbK.d.ts → any-v4TsK9ES.d.ts} +25 -26
- package/dist/{arrays-normalize-recursive-CnjYJ9xg.d.ts → arrays-normalize-recursive-BqmVuFlD.d.ts} +20 -20
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -70
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-2CQX5CBG.js +1 -0
- package/dist/chunk-2IOOEY45.cjs +1 -0
- package/dist/chunk-3IBQ5MOM.js +1 -0
- package/dist/{chunk-OGPPP2S3.js → chunk-3VA554KW.js} +1 -1
- package/dist/{chunk-FV7SEBKD.cjs → chunk-5757UBXJ.cjs} +1 -1
- package/dist/{chunk-MTUBDVJ2.js → chunk-5IGC6PBH.js} +1 -1
- package/dist/{chunk-O7UT5AN3.cjs → chunk-5KJFVIQT.cjs} +1 -1
- package/dist/chunk-6JFCSH7J.js +1 -0
- package/dist/{chunk-VHAPTHEA.cjs → chunk-6JFZL7YE.cjs} +1 -1
- package/dist/chunk-7ODAAXX5.cjs +1 -0
- package/dist/{chunk-6C3ATUGM.cjs → chunk-CAH33WOQ.cjs} +1 -1
- package/dist/{chunk-ECRNH4FW.js → chunk-CKTLUNWX.js} +1 -1
- package/dist/chunk-CMW2TBOQ.js +1 -0
- package/dist/chunk-D3ENH7H6.cjs +1 -0
- package/dist/{chunk-3YCFMGRB.js → chunk-DEZZUYE2.js} +1 -1
- package/dist/chunk-DWF2R5GD.cjs +1 -0
- package/dist/chunk-E55EQK2U.cjs +1 -0
- package/dist/chunk-E74U6CYP.cjs +1 -0
- package/dist/{chunk-XC3QHAK2.cjs → chunk-EL6A35UR.cjs} +1 -1
- package/dist/chunk-F6IPNNSJ.cjs +1 -0
- package/dist/chunk-FJZGG54N.cjs +1 -0
- package/dist/chunk-FWCKOJZM.js +1 -0
- package/dist/{chunk-IMCLPT5V.cjs → chunk-FWHNWL2P.cjs} +1 -1
- package/dist/chunk-GGEADHZO.js +1 -0
- package/dist/{chunk-IRGE5W7L.js → chunk-GQR4R5WY.js} +1 -1
- package/dist/chunk-H66AC7GK.cjs +1 -0
- package/dist/{chunk-M47QIBXI.cjs → chunk-HQWOFR56.cjs} +1 -1
- package/dist/{chunk-VCFXNV3Q.cjs → chunk-HYRQMTRH.cjs} +1 -1
- package/dist/{chunk-EUANTHVN.js → chunk-IRFL4MAX.js} +1 -1
- package/dist/{chunk-GGWPB23G.cjs → chunk-IVL7CKVH.cjs} +1 -1
- package/dist/chunk-IZPBKKPO.js +1 -0
- package/dist/chunk-JBQMXC5I.cjs +1 -0
- package/dist/chunk-JEQEF5WD.js +1 -0
- package/dist/chunk-JMJQCN74.js +1 -0
- package/dist/chunk-JYQTCICM.js +1 -0
- package/dist/chunk-KVAL5PAG.cjs +1 -0
- package/dist/chunk-LS6U7FAY.cjs +1 -0
- package/dist/chunk-NBZWMBO6.js +1 -0
- package/dist/chunk-NRF6LWBC.cjs +1 -0
- package/dist/chunk-OI5XKNZO.js +1 -0
- package/dist/chunk-OYTYSY7G.js +1 -0
- package/dist/chunk-PET42Z7W.js +1 -0
- package/dist/chunk-PZQ6I4JJ.cjs +1 -0
- package/dist/chunk-QBKAEVYG.js +1 -0
- package/dist/{chunk-YV3K2EKJ.js → chunk-RIPKY4RU.js} +1 -1
- package/dist/chunk-RZW35UN5.cjs +1 -0
- package/dist/chunk-SBFNXGTJ.js +1 -0
- package/dist/{chunk-T4CIAKEK.js → chunk-SBKGWRS5.js} +1 -1
- package/dist/{chunk-5Z2G23WP.js → chunk-SIM77PU4.js} +1 -1
- package/dist/chunk-T2T7K3KR.js +1 -0
- package/dist/chunk-T7PU2V7X.cjs +1 -0
- package/dist/chunk-V45XJKHW.cjs +1 -0
- package/dist/chunk-W2WNBUDE.js +1 -0
- package/dist/chunk-XABCB3Y7.cjs +1 -0
- package/dist/chunk-XEDXFSGI.js +1 -0
- package/dist/chunk-YKPSRP5G.js +1 -0
- package/dist/chunk-YLA3DURS.cjs +1 -0
- package/dist/chunk-ZETAZZLD.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +515 -321
- package/dist/conversions/index.js +1 -1
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +25 -20
- package/dist/events/index.js +1 -1
- package/dist/{extends-Bk_SBGdT.d.ts → extends-DtdRjDyU.d.ts} +63 -87
- package/dist/{formatting → formatters}/index.cjs +1 -1
- package/dist/formatters/index.d.ts +2106 -0
- package/dist/formatters/index.js +1 -0
- package/dist/generators/index.cjs +1 -0
- package/dist/{generator → generators}/index.d.ts +57 -59
- package/dist/generators/index.js +1 -0
- package/dist/{if-CvT4R7Kh.d.ts → if-ChM35c_q.d.ts} +6 -5
- package/dist/index.d.ts +14 -0
- package/dist/{is-array--YjXV-Wx.d.ts → is-array-BJeHxPM3.d.ts} +287 -542
- package/dist/{isPlainObject-BVhBAPHX.d.ts → isPlainObject-DGJkcFYw.d.ts} +6 -6
- package/dist/{never-BfayMBF9.d.ts → never-D89PbPh5.d.ts} +10 -19
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.d.ts +15 -12
- package/dist/next/index.js +1 -1
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +1 -1
- package/dist/next/server/index.js +1 -1
- package/dist/{nils-DMz3kU7M.d.ts → nils-CO8zLHSB.d.ts} +39 -65
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +4 -4
- package/dist/operations/index.js +1 -1
- package/dist/or-C6qzKt2I.d.ts +82 -0
- package/dist/override-CL2olHE5.d.ts +59 -0
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.js +1 -1
- package/dist/pick-BSMX6Xe2.d.ts +15 -0
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +425 -106
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-3o8_Kw6b.d.ts +564 -0
- package/dist/promises/index.cjs +1 -0
- package/dist/promises/index.d.ts +107 -0
- package/dist/promises/index.js +1 -0
- package/dist/promises-LU7K00H0.d.ts +72 -0
- package/dist/rzl-utils.global.js +1 -1
- package/dist/{string-XA-til3C.d.ts → string-B1jlOnws.d.ts} +82 -121
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +209 -210
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +1 -1
- package/dist/tailwind/index.d.ts +23 -17
- package/dist/tailwind/index.js +1 -1
- package/dist/types/index.d.ts +899 -1181
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +113 -108
- package/dist/urls/index.js +1 -1
- package/package.json +33 -40
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +0 -26
- package/dist/chunk-2HSNUPEO.cjs +0 -1
- package/dist/chunk-4Z75R3IT.cjs +0 -1
- package/dist/chunk-AJ25PWXX.cjs +0 -1
- package/dist/chunk-BHIBDDQF.js +0 -1
- package/dist/chunk-CE4JI2YB.js +0 -1
- package/dist/chunk-CMJ6UYWW.cjs +0 -1
- package/dist/chunk-D3VSHABU.cjs +0 -1
- package/dist/chunk-DG2GWBTS.cjs +0 -1
- package/dist/chunk-EKS4IZJR.cjs +0 -1
- package/dist/chunk-EOZKYR5S.cjs +0 -1
- package/dist/chunk-EW3I4O7X.js +0 -1
- package/dist/chunk-F3E77L46.js +0 -1
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GVWGQNLF.js +0 -1
- package/dist/chunk-H3FXL4DU.cjs +0 -1
- package/dist/chunk-HHPDLSX2.cjs +0 -1
- package/dist/chunk-JARPXKBM.cjs +0 -1
- package/dist/chunk-JFJUPYDT.cjs +0 -1
- package/dist/chunk-JLP56WSM.js +0 -1
- package/dist/chunk-K3MV4AIN.cjs +0 -1
- package/dist/chunk-KOVO72OM.js +0 -1
- package/dist/chunk-LJ4M3VGE.js +0 -1
- package/dist/chunk-LJVGJLP4.js +0 -1
- package/dist/chunk-MISCBZJC.js +0 -1
- package/dist/chunk-MMSYCIJ2.cjs +0 -1
- package/dist/chunk-OLPKAX7F.cjs +0 -1
- package/dist/chunk-ORZFHBEY.js +0 -1
- package/dist/chunk-OWV2P376.js +0 -1
- package/dist/chunk-RV2WK5E6.js +0 -1
- package/dist/chunk-SBF43G3B.cjs +0 -1
- package/dist/chunk-X74TUJSE.cjs +0 -1
- package/dist/chunk-XLDAIZRK.js +0 -1
- package/dist/chunk-XZJ7C4N6.js +0 -1
- package/dist/chunk-ZHV5ZYVN.cjs +0 -1
- package/dist/chunk-ZL7J6GTP.js +0 -1
- package/dist/chunk-ZTCLKKMB.js +0 -1
- package/dist/env/index.cjs +0 -1
- package/dist/env/index.d.ts +0 -16
- package/dist/env/index.js +0 -1
- package/dist/formatting/index.d.ts +0 -950
- package/dist/formatting/index.js +0 -1
- package/dist/generator/index.cjs +0 -1
- package/dist/generator/index.js +0 -1
- package/dist/omit-VvmIsZmX.d.ts +0 -28
- package/dist/prettify-C4xLcYOP.d.ts +0 -353
- package/dist/promise/index.cjs +0 -1
- package/dist/promise/index.d.ts +0 -31
- package/dist/promise/index.js +0 -1
- package/dist/type-data-DDs-u2kq.d.ts +0 -261
- /package/dist/{chunk-5C2SMIGX.cjs → chunk-BAV5T2E3.cjs} +0 -0
- /package/dist/{chunk-MC3LXMCQ.js → chunk-L5RDAVVH.js} +0 -0
- /package/dist/{chunk-J2RGTPGK.cjs → chunk-VJDDGRIK.cjs} +0 -0
- /package/dist/{chunk-FIAAX3UE.js → chunk-YWHHVDT4.js} +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import{N as NonPlainObject}from'./
|
|
2
|
-
/**
|
|
1
|
+
import{N as NonPlainObject}from'./prettify-3o8_Kw6b.js';
|
|
2
|
+
/** ---------------------------------------------------------------------------
|
|
3
|
+
* * ***Type Options for {@link getPreciseType | `getPreciseType`}.***
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
*/
|
|
3
6
|
type GetPreciseTypeOptions={
|
|
4
7
|
/** -------------------------------------------------------
|
|
5
8
|
* * ***Specifies the format in which the returned string type should be transformed.***
|
|
6
9
|
* -------------------------------------------------------
|
|
7
|
-
*
|
|
8
|
-
* ℹ️ For special string literals in `SPECIAL_CASES` (`"-Infinity" | "Infinity" | "NaN"`), which will remain unchanged.
|
|
10
|
+
* **ℹ️ For special string literals in `SPECIAL_CASES` (`"-Infinity" | "Infinity" | "NaN"`), which will remain unchanged.**
|
|
9
11
|
* @default "toLowerCase"
|
|
10
|
-
*
|
|
11
12
|
* @description
|
|
12
13
|
* Supported formats:
|
|
13
14
|
* - `"toLowerCase"` (default) — converts all letters to lowercase.
|
|
@@ -26,7 +27,6 @@ type GetPreciseTypeOptions={
|
|
|
26
27
|
* - ➔ `"Result Example Type"`
|
|
27
28
|
* - `"slugify"` — URL-friendly slug (lowercase with hyphens).
|
|
28
29
|
* - ➔ `"result-example-type"`
|
|
29
|
-
*
|
|
30
30
|
* @note
|
|
31
31
|
* ⚠️ If an invalid value is provided, the function will automatically fallback to the default `"toLowerCase"`.
|
|
32
32
|
*/
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import{I as If}from'./if-
|
|
1
|
+
import{I as If}from'./if-ChM35c_q.js';
|
|
2
2
|
/** -------------------------------------------------------
|
|
3
|
-
* * ***IsNever
|
|
3
|
+
* * ***Utility Type: `IsNever`.***
|
|
4
4
|
* -------------------------------------------------------
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* ****Conditional**: returns `true` if `T` is `never`, otherwise `false`.**
|
|
7
6
|
* @template T - Type to check.
|
|
8
7
|
* @example
|
|
9
8
|
* ```ts
|
|
@@ -13,11 +12,10 @@ import{I as If}from'./if-CvT4R7Kh.js';
|
|
|
13
12
|
*/
|
|
14
13
|
type IsNever<T>=[T] extends [never]?true:false;
|
|
15
14
|
/** -------------------------------------------------------
|
|
16
|
-
* * ***IfNever
|
|
15
|
+
* * ***Utility Type: `IfNever`.***
|
|
17
16
|
* -------------------------------------------------------
|
|
18
|
-
*
|
|
17
|
+
* ****Conditional**: Selects one of two branches depending on whether `T` is `never`.**
|
|
19
18
|
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
20
|
-
*
|
|
21
19
|
* @template T - Type to check.
|
|
22
20
|
* @template IfTrue - The branch type if `T` is `never`, (default: `true`).
|
|
23
21
|
* @template IfFalse - The branch type if `T` is not `never`, (default: `false`).
|
|
@@ -35,14 +33,9 @@ type IsNever<T>=[T] extends [never]?true:false;
|
|
|
35
33
|
*/
|
|
36
34
|
type IfNever<T,IfTrue=true,IfFalse=false>=If<IsNever<T>,IfTrue,IfFalse>;
|
|
37
35
|
/** -------------------------------------------------------
|
|
38
|
-
* * ***NeverifyPropertiesOptions
|
|
36
|
+
* * ***Utility Type: `NeverifyPropertiesOptions`.***
|
|
39
37
|
* -------------------------------------------------------
|
|
40
|
-
* Configuration options for the ***{@link NeverifyProperties}*** type utility
|
|
41
|
-
*
|
|
42
|
-
* @property makeOptional - Whether to make all properties optional.
|
|
43
|
-
* - If `true`, resulting properties will be optional (`?`).
|
|
44
|
-
* - Default: `false`.
|
|
45
|
-
*
|
|
38
|
+
* **Configuration options for the ***{@link NeverifyProperties | `NeverifyProperties`}*** type utility.**
|
|
46
39
|
* @example
|
|
47
40
|
* ```ts
|
|
48
41
|
* type Opt1 = NeverifyPropertiesOptions;
|
|
@@ -50,24 +43,22 @@ type IfNever<T,IfTrue=true,IfFalse=false>=If<IsNever<T>,IfTrue,IfFalse>;
|
|
|
50
43
|
* ```
|
|
51
44
|
*/
|
|
52
45
|
type NeverifyPropertiesOptions={
|
|
53
|
-
/** Whether to make all properties optional, defaultValue: `false
|
|
46
|
+
/** * ***Whether to make all properties optional, defaultValue: `false`.***
|
|
54
47
|
*
|
|
55
48
|
* @default false
|
|
56
49
|
*/
|
|
57
50
|
makeOptional:boolean;};
|
|
58
51
|
/** -------------------------------------------------------
|
|
59
|
-
* * ***NeverifyProperties
|
|
52
|
+
* * ***Utility Type: `NeverifyProperties`.***
|
|
60
53
|
* -------------------------------------------------------
|
|
61
|
-
* Turns all properties of an object to type `never
|
|
54
|
+
* **Turns all properties of an object to type `never`.**
|
|
62
55
|
* - If `Options["makeOptional"]` is `true`, properties will be optional.
|
|
63
|
-
*
|
|
64
56
|
* @template T - Object type to transform.
|
|
65
57
|
* @template Options - Configuration options (default: `{ makeOptional: false }`).
|
|
66
58
|
* @example
|
|
67
59
|
* ```ts
|
|
68
60
|
* type A = NeverifyProperties<{ a: string; b: string }>;
|
|
69
61
|
* // ➔ { a: never; b: never }
|
|
70
|
-
*
|
|
71
62
|
* type B = NeverifyProperties<{ a: string; b: string }, { makeOptional: true }>;
|
|
72
63
|
* // ➔ { a?: never; b?: never }
|
|
73
64
|
* ```
|
package/dist/next/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../chunk-
|
|
1
|
+
"use strict";var e=require("../chunk-H66AC7GK.cjs"),r=require("../chunk-KVAL5PAG.cjs"),t=require("../chunk-E55EQK2U.cjs"),s=require("../chunk-HYRQMTRH.cjs"),n=require("../chunk-T7PU2V7X.cjs");require("../chunk-UDA26MCU.cjs");var i=require("../chunk-PZQ6I4JJ.cjs");var a=(t={})=>{i.isPlainObject(t)||(t={});let n=i.hasOwnProp(t,"suffix")?t.suffix:"/";s.assertIsString(n,{message:({currentType:e,validType:r})=>`Parameter \`suffix\` property of the first parameter must be of type \`${r}\`, but received: \`${e}\`.`});try{let t=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(t){t=r.removeSpaces(t);const s=new URL(t);!!!s.port&&process.env.NEXT_PUBLIC_PORT_BE&&(t=s.origin+e.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}))}else t="http://localhost"+e.formatEnvPort(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});n=r.removeSpaces(n).length?r.removeSpaces(n):"/";const s=new URL(t.replace(/\/+$/,"")).origin;return`${s}${"/"===n?"/":`${n.startsWith("/")?"":"/"}${n.replace(/\/+$/,"")}`}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+e)}};exports.createBeApiUrl=(r,t={})=>{try{let n=function(e,r){return`${e.replace(/\/+$/,"")}/${r.replace(/^\/+/,"")}`};s.assertIsString(i.isNil(r)?"":r,{message:({currentType:e,validType:r})=>`First parameter (\`pathname\`) must be of type \`${r}\`, but received: \`${e}\`.`}),i.isPlainObject(t)||(t={});let{prefix:o="/api",withOrigin:c=!0}=t;if(!i.isUndefined(o)&&!i.isString(o))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${i.getPreciseType(o)}\`.`);i.assertIsBoolean(c,{message:({currentType:e,validType:r})=>`Parameter \`withOrigin\` property of the \`options\` (second parameter) must be of type \`${r}\`, but received: \`${e}\`.`}),r=e.normalizePathname(r),o=e.normalizePathname(o);const p=o.endsWith("/")?o:o+"/";(r===o||r===o+"/"||r.startsWith(p))&&(r=r.slice(o.length),r=e.normalizePathname(r));const u=a({suffix:o});return n(c?u:new URL(u).pathname,r).replace(/\/+$/,"")}catch(e){throw i.isError(e)?e:new Error("Failed to generate backend API URL in `createBeApiUrl()`, Error: "+new Error(String(e)).message.trim())}},exports.generateRoute=function(e,r){if(!i.isString(e)||t.isEmptyString(e))throw new TypeError(`❌ 'generateRoute' Failed:\n- Invalid 'route' value.\n- Must be of type \`string\` and non-empty string, but received: "${i.getPreciseType(e)}": \`${n.safeStableStringify(e)}\`.`);if(!/[\\[\]]/.test(e))return e;if(i.assertIsPlainObject(r,{message:({validType:r})=>`❌ 'generateRoute' Failed cause in route "${e}":\n- Missing or invalid parameters \`${r}\` for route: "${e}", must be of type \`${r}\` mapping parameters.`}),i.isNil(r))throw new TypeError(`❌ 'generateRoute' Failed cause in route "${e}":\n- Missing parameters \`plain-object\` for route: "${e}".`);const s=["?","&","#","=","/","'",'"',"(",")","+",";","%","@",":"],a=[],o=Array.from(e.matchAll(/\[(\w+)\]/g)).map(e=>e[1]);for(const e of o){const n=r[e];if(!i.isString(n)){a.push(`- Invalid parameter: "${e}" must be of type \`string\`, but received: \`${i.getPreciseType(n)}\`.`);continue}if(t.isEmptyString(n)){a.push(`- Parameter "${e}" cannot be empty string.`);continue}const o=s.filter(e=>n.includes(e));if(/\s/.test(n)&&o.push("white-space(s)"),o.length>0){const r=o.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);s.includes("white-space(s)")||s.push("white-space(s)");const t=s.map(e=>"`"===e?"backtick - (`)":`\`${e}\``);a.push(`- Parameter "${e}" contains invalid characters (${r.join(", ")}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters: (${t.join(", ")}).`)}}if(i.isNonEmptyArray(a))throw new Error(`❌ 'generateRoute' Failed cause in route "${e}":\n${a.join("\n")}.`);return e.replace(/\[(\w+)\]/g,(e,t)=>(i.isNonEmptyString(r[t])?r[t]:"").trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")},exports.getBaseUrl=()=>{try{const t=process.env.NEXT_PUBLIC_BASE_URL?.trim(),s=process.env.NEXT_PUBLIC_PORT_FE?.trim();let n=t||"http://localhost";n=r.removeSpaces(n).replace(/\/+$/,"");const i=/:\/\/[^/]+:\d+/.test(n);!i&&s?n+=e.formatEnvPort(s,{prefixColon:!0}):i||t||(n+=":3000");const a=new URL(n);return`${a.protocol}//${a.hostname}${a.port?`:${a.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}},exports.getBeApiUrl=a;
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{I as IsAny}from'../any-
|
|
1
|
+
import{I as IsAny}from'../any-v4TsK9ES.js';import'../if-ChM35c_q.js';
|
|
2
2
|
/** ---------------------------------------------------------
|
|
3
3
|
* * ***Extracts dynamic route parameters from a given route string.***
|
|
4
4
|
* ---------------------------------------------------------
|
|
@@ -39,8 +39,9 @@ type ExtractRouteParams<T>=T extends string?HasDynamicSegments<T>extends true?T
|
|
|
39
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
|
-
* * ***
|
|
42
|
+
* * ***Utility for NextJS: `generateRoute`.***
|
|
43
43
|
* ---------------------------------
|
|
44
|
+
* **Generates a URL by replacing dynamic route parameters with provided values.**
|
|
44
45
|
* - ***⚠️ Warning:***
|
|
45
46
|
* - ***This function only support when using ***[`NextJS`](https://nextjs.org/)***.***
|
|
46
47
|
* @template T - The route string containing dynamic segments in the format `[param]`.
|
|
@@ -86,9 +87,11 @@ prefix?:string;
|
|
|
86
87
|
* @default true */
|
|
87
88
|
withOrigin?:boolean;};
|
|
88
89
|
/** ---------------------------------
|
|
89
|
-
* * ***
|
|
90
|
+
* * ***Utility for NextJS: `createBeApiUrl`.***
|
|
90
91
|
* ---------------------------------
|
|
91
|
-
*
|
|
92
|
+
* **Constructs a backend API URL by appending a given pathname to the base API URL.**
|
|
93
|
+
* - **ℹ️ Note:**
|
|
94
|
+
* - This function builds on top of `getBeApiUrl()`.
|
|
92
95
|
* - **Determines the base API URL from:**
|
|
93
96
|
* - `NEXT_PUBLIC_BACKEND_API_URL` environment variable (or defaults to `"http://localhost:8000"`).
|
|
94
97
|
* - Automatically appends `NEXT_PUBLIC_PORT_BE` if the base URL does not already include a port.
|
|
@@ -130,14 +133,14 @@ declare const createBeApiUrl:(
|
|
|
130
133
|
* @default ""
|
|
131
134
|
*/
|
|
132
135
|
pathname:string|null|undefined,options?:OptionsCreateBeApiUrl)=>string;type OptionsGetBeApiUrl={
|
|
133
|
-
/** * The Suffix origin base api url, e.g:`http://localhost.com/api`, default: `"/"
|
|
136
|
+
/** * ***The Suffix origin base api url, e.g:`http://localhost.com/api`, default: `"/"`.***
|
|
134
137
|
*
|
|
135
138
|
* @default "/" */
|
|
136
139
|
suffix?:string;};
|
|
137
140
|
/** ---------------------------------------------------
|
|
138
|
-
* * ***
|
|
141
|
+
* * ***Utility for NextJS: `getBeApiUrl`.***
|
|
139
142
|
* ---------------------------------------------------
|
|
140
|
-
* **This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.**
|
|
143
|
+
* **This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable (retrieves the base API URL of the backend).**
|
|
141
144
|
* - **Behavior:**
|
|
142
145
|
* - If the variable is not set, it defaults to `"http://localhost:8000"`.
|
|
143
146
|
* - It also allows adding an optional suffix to the returned URL.
|
|
@@ -147,7 +150,7 @@ suffix?:string;};
|
|
|
147
150
|
* This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
|
|
148
151
|
* - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
|
|
149
152
|
* - 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").
|
|
153
|
+
* - Supports appending optional suffix (like `"/api"`).
|
|
151
154
|
* @param {OptionsGetBeApiUrl|undefined} options - Configuration options.
|
|
152
155
|
* @param {OptionsGetBeApiUrl["suffix"]} [options.suffix="/"] - The suffix to append to the base API URL.
|
|
153
156
|
* @returns {string} The formatted backend API base URL.
|
|
@@ -170,11 +173,11 @@ suffix?:string;};
|
|
|
170
173
|
* getBeApiUrl({ suffix: "/v1" });
|
|
171
174
|
* // ➔ "http://localhost:8000/v1"
|
|
172
175
|
*/
|
|
173
|
-
declare const getBeApiUrl:(
|
|
176
|
+
declare const getBeApiUrl:(options?:OptionsGetBeApiUrl)=>string;
|
|
174
177
|
/** ---------------------------------------------------
|
|
175
|
-
* * ***
|
|
178
|
+
* * ***Utility for NextJS: `getBaseUrl`.***
|
|
176
179
|
* ---------------------------------------------------
|
|
177
|
-
* **
|
|
180
|
+
* **Retrieves the base URL of the application.**
|
|
178
181
|
* - **Behavior:**
|
|
179
182
|
* - It determines the base URL from the `NEXT_PUBLIC_BASE_URL` environment variable.
|
|
180
183
|
* - If `NEXT_PUBLIC_BASE_URL` is not set, it defaults to `"http://localhost:3000"`.
|
|
@@ -190,7 +193,7 @@ declare const getBeApiUrl:({suffix}?:OptionsGetBeApiUrl)=>string;
|
|
|
190
193
|
* getBaseUrl();
|
|
191
194
|
* // ➔ "https://example.com"
|
|
192
195
|
*
|
|
193
|
-
* // With custom port via NEXT_PUBLIC_PORT_FE
|
|
196
|
+
* // With custom port via NEXT_PUBLIC_PORT_FE at `*.env` file
|
|
194
197
|
* NEXT_PUBLIC_BASE_URL = "http://localhost";
|
|
195
198
|
* NEXT_PUBLIC_PORT_FE = "4000";
|
|
196
199
|
* getBaseUrl();
|
package/dist/next/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizePathname as e,formatEnvPort as r}from"../chunk-
|
|
1
|
+
import{normalizePathname as e,formatEnvPort as r}from"../chunk-GGEADHZO.js";import{removeSpaces as t}from"../chunk-XEDXFSGI.js";import{isEmptyString as o}from"../chunk-W2WNBUDE.js";import{assertIsString as n}from"../chunk-SBKGWRS5.js";import{safeStableStringify as s}from"../chunk-PET42Z7W.js";import"../chunk-QNKGP5DY.js";import{isString as a,getPreciseType as i,assertIsPlainObject as p,isNil as c,isNonEmptyArray as u,isNonEmptyString as l,isPlainObject as m,isUndefined as f,assertIsBoolean as h,isError as $,hasOwnProp as d}from"../chunk-CMW2TBOQ.js";function g(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: "${i(e)}": \`${s(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 s=r[e];if(!a(s)){n.push(`- Invalid parameter: "${e}" must be of type \`string\`, but received: \`${i(s)}\`.`);continue}if(o(s)){n.push(`- Parameter "${e}" cannot be empty string.`);continue}const p=t.filter(e=>s.includes(e));if(/\s/.test(s)&&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 E=(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:s="/api",withOrigin:p=!0}=t;if(!f(s)&&!a(s))throw new TypeError(`Parameter \`prefix\` property of the \`options\` (second parameter) must be of type \`string\`, but received: \`${i(s)}\`.`);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),s=e(s);const u=s.endsWith("/")?s:s+"/";(r===s||r===s+"/"||r.startsWith(u))&&(r=r.slice(s.length),r=e(r));const l=w({suffix:s});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())}},w=(e={})=>{m(e)||(e={});let o=d(e,"suffix")?e.suffix:"/";n(o,{message:({currentType:e,validType:r})=>`Parameter \`suffix\` property of the first parameter must be of type \`${r}\`, but received: \`${e}\`.`});try{let e=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(e){e=t(e);const o=new URL(e);!!!o.port&&process.env.NEXT_PUBLIC_PORT_BE&&(e=o.origin+r(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}))}else e="http://localhost"+r(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});o=t(o).length?t(o):"/";const n=new URL(e.replace(/\/+$/,"")).origin;return`${n}${"/"===o?"/":`${o.startsWith("/")?"":"/"}${o.replace(/\/+$/,"")}`}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`, failed to generate from `getBeApiUrl()`, Error:"+e)}},y=()=>{try{const e=process.env.NEXT_PUBLIC_BASE_URL?.trim(),o=process.env.NEXT_PUBLIC_PORT_FE?.trim();let n=e||"http://localhost";n=t(n).replace(/\/+$/,"");const s=/:\/\/[^/]+:\d+/.test(n);!s&&o?n+=r(o,{prefixColon:!0}):s||e||(n+=":3000");const a=new URL(n);return`${a.protocol}//${a.hostname}${a.port?`:${a.port}`:""}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`, failed to generate from `getBaseUrl()`, Error:"+e)}};export{E as createBeApiUrl,g as generateRoute,y as getBaseUrl,w as getBeApiUrl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../../chunk-
|
|
1
|
+
"use strict";var e=require("../../chunk-PZQ6I4JJ.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}`};
|
|
@@ -6,7 +6,7 @@ import{NextRequest}from'next/server';
|
|
|
6
6
|
* - **ℹ️ Note:**
|
|
7
7
|
* - Only supported in **Next.js** environments (specifically in `server-only` contexts).
|
|
8
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
|
|
9
|
+
* @param {NextRequest} request - The incoming ***`NextJS`*** request object, must be instanceof `NextRequest` from `next/server`.
|
|
10
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
11
|
* @returns {string} The extracted client IP address or the full constructed URL.
|
|
12
12
|
* @throws {Error} If the function is used outside a Next.js server environment.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isFunction as e,assertIsBoolean as r}from"../../chunk-
|
|
1
|
+
import{isFunction as e,assertIsBoolean as r}from"../../chunk-CMW2TBOQ.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};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
/** --------------------------------------------------
|
|
2
|
-
* * ***Nullish
|
|
2
|
+
* * ***Utility Type: `Nullish`.***
|
|
3
3
|
* --------------------------------------------------
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Useful as a shorthand when working with optional or missing values.
|
|
4
|
+
* **Useful as a shorthand when working with optional or missing values.**
|
|
5
|
+
* - **Represents all values considered **`nullish`**:**
|
|
6
|
+
* - `null`
|
|
7
|
+
* - `undefined`
|
|
9
8
|
*/
|
|
10
9
|
type Nullish=null|undefined;
|
|
11
10
|
/** --------------------------------------------------
|
|
12
|
-
* * ***Nullable
|
|
11
|
+
* * ***Utility Type: `Nullable`.***
|
|
13
12
|
* --------------------------------------------------
|
|
14
|
-
* Represents a type that can be either `T` or `null
|
|
15
|
-
*
|
|
13
|
+
* **Represents a type that can be either `T` or `null`.**
|
|
16
14
|
* @template T - The base type.
|
|
17
|
-
*
|
|
18
15
|
* @example
|
|
19
16
|
* ```ts
|
|
20
17
|
* type A = Nullable<string>; // ➔ string | null
|
|
@@ -22,12 +19,10 @@ type Nullish=null|undefined;
|
|
|
22
19
|
*/
|
|
23
20
|
type Nullable<T>=T|null;
|
|
24
21
|
/** --------------------------------------------------
|
|
25
|
-
* * ***Nilable
|
|
22
|
+
* * ***Utility Type: `Nilable`.***
|
|
26
23
|
* --------------------------------------------------
|
|
27
|
-
* Represents a type that can be either `T`, `null`, or `undefined
|
|
28
|
-
*
|
|
24
|
+
* **Represents a type that can be either `T`, `null`, or `undefined`.**
|
|
29
25
|
* @template T - The base type.
|
|
30
|
-
*
|
|
31
26
|
* @example
|
|
32
27
|
* ```ts
|
|
33
28
|
* type A = Nilable<number>; // ➔ number | null | undefined
|
|
@@ -35,12 +30,10 @@ type Nullable<T>=T|null;
|
|
|
35
30
|
*/
|
|
36
31
|
type Nilable<T>=T|null|undefined;
|
|
37
32
|
/** --------------------------------------------------
|
|
38
|
-
* * ***Undefinedable
|
|
33
|
+
* * ***Utility Type: `Undefinedable`.***
|
|
39
34
|
* --------------------------------------------------
|
|
40
|
-
* Represents a type that can be either `T` or `undefined
|
|
41
|
-
*
|
|
35
|
+
* **Represents a type that can be either `T` or `undefined`.**
|
|
42
36
|
* @template T - The base type.
|
|
43
|
-
*
|
|
44
37
|
* @example
|
|
45
38
|
* ```ts
|
|
46
39
|
* type A = Undefinedable<boolean>; // ➔ boolean | undefined
|
|
@@ -48,95 +41,79 @@ type Nilable<T>=T|null|undefined;
|
|
|
48
41
|
*/
|
|
49
42
|
type Undefinedable<T>=T|undefined;
|
|
50
43
|
/** -------------------------------------------------------
|
|
51
|
-
* * ***NonNil
|
|
44
|
+
* * ***Utility Type: `NonNil`.***
|
|
52
45
|
* -------------------------------------------------------
|
|
53
|
-
* Removes both `null` and `undefined` from the given type `T
|
|
54
|
-
*
|
|
46
|
+
* **Removes both `null` and `undefined` from the given type `T`.**
|
|
55
47
|
* @template T - The type to filter.
|
|
56
|
-
*
|
|
57
48
|
* @example
|
|
58
49
|
* ```ts
|
|
59
50
|
* type A = NonNil<string | null | undefined>;
|
|
60
51
|
* // ➔ string
|
|
61
|
-
*
|
|
62
52
|
* type B = NonNil<number | null>;
|
|
63
53
|
* // ➔ number
|
|
64
|
-
*
|
|
65
54
|
* type C = NonNil<undefined | null>;
|
|
66
55
|
* // ➔ never
|
|
67
|
-
*
|
|
68
56
|
* type D = NonNil<boolean | undefined>;
|
|
69
57
|
* // ➔ boolean
|
|
70
58
|
* ```
|
|
71
59
|
*/
|
|
72
60
|
type NonNil<T>=T extends null|undefined?never:T;
|
|
73
61
|
/** -------------------------------------------------------
|
|
74
|
-
* * ***NonNull
|
|
62
|
+
* * ***Utility Type: `NonNull`.***
|
|
75
63
|
* -------------------------------------------------------
|
|
76
|
-
* Removes `null` from the given type `T
|
|
77
|
-
*
|
|
64
|
+
* **Removes `null` from the given type `T`.**
|
|
78
65
|
* @template T - The type to filter.
|
|
79
|
-
*
|
|
80
66
|
* @example
|
|
81
67
|
* ```ts
|
|
82
68
|
* type A = NonNull<string | null>;
|
|
83
69
|
* // ➔ string
|
|
84
|
-
*
|
|
85
70
|
* type B = NonNull<number | null | undefined>;
|
|
86
71
|
* // ➔ number | undefined
|
|
87
|
-
*
|
|
88
72
|
* type C = NonNull<null>;
|
|
89
73
|
* // ➔ never
|
|
90
74
|
* ```
|
|
91
75
|
*/
|
|
92
76
|
type NonNull<T>=T extends null?never:T;
|
|
93
77
|
/** -------------------------------------------------------
|
|
94
|
-
* * ***NonUndefined
|
|
78
|
+
* * ***Utility Type: `NonUndefined`.***
|
|
95
79
|
* -------------------------------------------------------
|
|
96
|
-
* Remove `undefined` from the given type `T
|
|
97
|
-
*
|
|
80
|
+
* **Remove `undefined` from the given type `T`.**
|
|
98
81
|
* @template T - The type to filter.
|
|
99
|
-
*
|
|
100
82
|
* @example
|
|
101
83
|
* ```ts
|
|
102
84
|
* type A = NonUndefined<string | undefined>;
|
|
103
85
|
* // ➔ string
|
|
104
|
-
*
|
|
105
86
|
* type B = NonUndefined<number | null | undefined>;
|
|
106
87
|
* // ➔ number | null
|
|
107
|
-
*
|
|
108
88
|
* type C = NonUndefined<undefined>;
|
|
109
89
|
* // ➔ never
|
|
110
90
|
* ```
|
|
111
91
|
*/
|
|
112
92
|
type NonUndefined<T>=T extends undefined?never:T;
|
|
113
93
|
/** --------------------------------------------------
|
|
114
|
-
* * ***KeepNil
|
|
94
|
+
* * ***Utility Type: `KeepNil`.***
|
|
115
95
|
* --------------------------------------------------
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* **only if** they exist in the input type `T`.
|
|
119
|
-
* Otherwise, resolves to `never`.
|
|
120
|
-
*
|
|
96
|
+
* **Keeps `null` and/or `undefined` in the output type **only if** they
|
|
97
|
+
* exist in the input type `T`, otherwise, resolves to `never`.**
|
|
121
98
|
* @template T - Input type to check for `null` and `undefined`.
|
|
122
|
-
*
|
|
123
99
|
* @example
|
|
124
100
|
* ```ts
|
|
125
|
-
* type A = KeepNil<string | null>;
|
|
126
|
-
*
|
|
127
|
-
* type
|
|
128
|
-
*
|
|
101
|
+
* type A = KeepNil<string | null>;
|
|
102
|
+
* // ➔ null
|
|
103
|
+
* type B = KeepNil<number | undefined>;
|
|
104
|
+
* // ➔ undefined
|
|
105
|
+
* type C = KeepNil<string | null | undefined>;
|
|
106
|
+
* // ➔ null | undefined
|
|
107
|
+
* type D = KeepNil<boolean>;
|
|
108
|
+
* // ➔ never
|
|
129
109
|
* ```
|
|
130
110
|
*/
|
|
131
111
|
type KeepNil<T>=(null extends T?null:never)|(undefined extends T?undefined:never);
|
|
132
112
|
/** --------------------------------------------------
|
|
133
|
-
* * ***KeepNull
|
|
113
|
+
* * ***Utility Type: `KeepNull`.***
|
|
134
114
|
* --------------------------------------------------
|
|
135
|
-
* Keeps `null` in the output type **only if** the input type `T` includes `null
|
|
136
|
-
* Otherwise resolves to `never`.
|
|
137
|
-
*
|
|
115
|
+
* **Keeps `null` in the output type **only if** the input type `T` includes `null`, otherwise resolves to `never`.**
|
|
138
116
|
* @template T - Input type to check for `null`.
|
|
139
|
-
*
|
|
140
117
|
* @example
|
|
141
118
|
* ```ts
|
|
142
119
|
* type A = KeepNull<string | null>; // ➔ null
|
|
@@ -145,13 +122,10 @@ type KeepNil<T>=(null extends T?null:never)|(undefined extends T?undefined:never
|
|
|
145
122
|
*/
|
|
146
123
|
type KeepNull<T>=null extends T?null:never;
|
|
147
124
|
/** --------------------------------------------------
|
|
148
|
-
* * ***KeepUndef
|
|
125
|
+
* * ***Utility Type: `KeepUndef`.***
|
|
149
126
|
* --------------------------------------------------
|
|
150
|
-
* Keeps `undefined` in the output type **only if** the input type `T` includes `undefined
|
|
151
|
-
* Otherwise resolves to `never`.
|
|
152
|
-
*
|
|
127
|
+
* **Keeps `undefined` in the output type **only if** the input type `T` includes `undefined`, otherwise resolves to `never`.**
|
|
153
128
|
* @template T - Input type to check for `undefined`.
|
|
154
|
-
*
|
|
155
129
|
* @example
|
|
156
130
|
* ```ts
|
|
157
131
|
* type A = KeepUndef<number | undefined>; // ➔ undefined
|
|
@@ -160,17 +134,17 @@ type KeepNull<T>=null extends T?null:never;
|
|
|
160
134
|
*/
|
|
161
135
|
type KeepUndef<T>=undefined extends T?undefined:never;
|
|
162
136
|
/** -------------------------------------------------------
|
|
163
|
-
* * ***NullToUndefined
|
|
137
|
+
* * ***Utility Type: `NullToUndefined`.***
|
|
164
138
|
* -------------------------------------------------------
|
|
165
|
-
* Transforms `null` or `undefined` types into `undefined`, otherwise, returns
|
|
166
|
-
*
|
|
139
|
+
* **Transforms `null` or `undefined` types into `undefined`, otherwise, returns
|
|
140
|
+
* the original type `T` unchanged.**
|
|
167
141
|
* @template T - The input type to transform.
|
|
168
142
|
* @example
|
|
169
143
|
* ```ts
|
|
170
|
-
* type A = NullToUndefined<null>;
|
|
171
|
-
* type B = NullToUndefined<undefined>;
|
|
172
|
-
* type C = NullToUndefined<string>;
|
|
173
|
-
* type D = NullToUndefined<null[]>;
|
|
144
|
+
* type A = NullToUndefined<null>; // ➔ undefined
|
|
145
|
+
* type B = NullToUndefined<undefined>; // ➔ undefined
|
|
146
|
+
* type C = NullToUndefined<string>; // ➔ string
|
|
147
|
+
* type D = NullToUndefined<null[]>; // ➔ null[]
|
|
174
148
|
* type E = NullToUndefined<(string | null)[]>; // ➔ (string | null)[]
|
|
175
149
|
* ```
|
|
176
150
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../chunk-
|
|
1
|
+
"use strict";var e=require("../chunk-LS6U7FAY.cjs");require("../chunk-FJZGG54N.cjs"),require("../chunk-JBQMXC5I.cjs"),require("../chunk-ZETAZZLD.cjs"),require("../chunk-6JFZL7YE.cjs"),require("../chunk-BAV5T2E3.cjs"),require("../chunk-T7PU2V7X.cjs"),require("../chunk-UDA26MCU.cjs"),require("../chunk-PZQ6I4JJ.cjs"),Object.defineProperty(exports,"findDuplicates",{enumerable:!0,get:function(){return e.findDuplicates}}),Object.defineProperty(exports,"omitKeys",{enumerable:!0,get:function(){return e.omitKeys}}),Object.defineProperty(exports,"omitKeysDeep",{enumerable:!0,get:function(){return e.omitKeysDeep}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{N as NumberRangeUnion}from'../NumberRangeUnion-
|
|
1
|
+
import{N as NumberRangeUnion}from'../NumberRangeUnion-B6bhM2s7.js';
|
|
2
2
|
/** ----------------------------------------------------------------------
|
|
3
3
|
* * ***Utility: `findDuplicates`.***
|
|
4
4
|
* ----------------------------------------------------------------------
|
|
@@ -61,8 +61,8 @@ declare const omitKeys:<I extends Record<string,unknown>,K extends keyof I>(obje
|
|
|
61
61
|
* ------------------------------------------------------
|
|
62
62
|
* **Recursively omits properties from an object using dot notation paths.**
|
|
63
63
|
* - **Behavior:**
|
|
64
|
-
* -
|
|
65
|
-
*
|
|
64
|
+
* - Removes resulting empty objects (`{}`) and arrays (`[]`), cascading upwards
|
|
65
|
+
* to remove empty parents until root if needed.
|
|
66
66
|
* - **⚠️ Be careful:**
|
|
67
67
|
* - If after omission an object or array becomes empty, it will be removed entirely
|
|
68
68
|
* including all the way up to the root if necessary, resulting in `{}`.
|
|
@@ -73,7 +73,7 @@ declare const omitKeys:<I extends Record<string,unknown>,K extends keyof I>(obje
|
|
|
73
73
|
* manually type `"arr.99.key"` and it will work the same.
|
|
74
74
|
* @template I - Type of the input object
|
|
75
75
|
* @param {I} object
|
|
76
|
-
* The object to process
|
|
76
|
+
* The object to process, should be a plain nested object or array structure.
|
|
77
77
|
* @param {DotPath<I>[]} keysToOmit
|
|
78
78
|
* An array of string paths in dot notation indicating the properties to remove, paths
|
|
79
79
|
* can include numeric indices to target array elements, e.g. `"arr.0.x"` to
|
package/dist/operations/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{findDuplicates,omitKeys,omitKeysDeep}from"../chunk-
|
|
1
|
+
export{findDuplicates,omitKeys,omitKeysDeep}from"../chunk-OYTYSY7G.js";import"../chunk-2CQX5CBG.js";import"../chunk-NBZWMBO6.js";import"../chunk-6JFCSH7J.js";import"../chunk-CKTLUNWX.js";import"../chunk-YWHHVDT4.js";import"../chunk-PET42Z7W.js";import"../chunk-QNKGP5DY.js";import"../chunk-CMW2TBOQ.js";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import{E as Extends,I as IfExtends}from'./extends-DtdRjDyU.js';
|
|
2
|
+
/** -------------------------------------------------------
|
|
3
|
+
* * ***Utility Type: `And`.***
|
|
4
|
+
* -------------------------------------------------------
|
|
5
|
+
* **Performs a **logical AND** operation between two boolean types.**
|
|
6
|
+
* - **Behavior:**
|
|
7
|
+
* - Returns `true` if **both** conditions extend `true`.
|
|
8
|
+
* - Returns `false` for otherwise.
|
|
9
|
+
* @template Condition1 - The first condition.
|
|
10
|
+
* @template Condition2 - The second condition.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type Case1 = And<true, true>;
|
|
14
|
+
* // ➔ true
|
|
15
|
+
* type Case2 = And<false, true>;
|
|
16
|
+
* // ➔ false
|
|
17
|
+
* type Case3 = And<true, false>;
|
|
18
|
+
* // ➔ false
|
|
19
|
+
* type Case4 = And<false, false>;
|
|
20
|
+
* // ➔ false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type And<Condition1,Condition2>=IfExtends<Condition1,true,Extends<Condition2,true>>;
|
|
24
|
+
/** -------------------------------------------------------
|
|
25
|
+
* * ***Utility Type: `AndArr`.***
|
|
26
|
+
* -------------------------------------------------------
|
|
27
|
+
* **Performs a **logical AND** operation across all elements in an array of
|
|
28
|
+
* boolean types.**
|
|
29
|
+
* - **Behavior:**
|
|
30
|
+
* - Returns `true` if **all elements** extend `true`.
|
|
31
|
+
* - Returns `false` if **any element** is not `true`.
|
|
32
|
+
* @template Conditions - A readonly array of boolean conditions.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* type Case1 = AndArr<[true, true, true]>;
|
|
36
|
+
* // ➔ true
|
|
37
|
+
* type Case2 = AndArr<[true, true, false]>;
|
|
38
|
+
* // ➔ false
|
|
39
|
+
* type Case3 = AndArr<[false, false, false]>;
|
|
40
|
+
* // ➔ false
|
|
41
|
+
* type Case4 = AndArr<[]>;
|
|
42
|
+
* // ➔ false
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
type AndArr<Conditions extends readonly unknown[]>=Extends<[],Conditions>extends true?false:Extends<Conditions[number],true>;
|
|
46
|
+
/** -------------------------------------------------------
|
|
47
|
+
* * ***Utility Type: `Or`.***
|
|
48
|
+
* -------------------------------------------------------
|
|
49
|
+
* **Computes the logical OR of two type-level boolean conditions.**
|
|
50
|
+
* @template Condition1 - First boolean condition.
|
|
51
|
+
* @template Condition2 - Second boolean condition.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* type Case1 = Or<true, true>; // ➔ true
|
|
55
|
+
* type Case2 = Or<false, true>; // ➔ true
|
|
56
|
+
* type Case3 = Or<false, false>; // ➔ false
|
|
57
|
+
* type Case4 = Or<true, false>; // ➔ true
|
|
58
|
+
* ```
|
|
59
|
+
* @remarks
|
|
60
|
+
* - Uses {@link IfExtends | **`IfExtends`**} to determine if either condition is `true`.
|
|
61
|
+
* - Returns `true` if at least one of the two conditions is `true`.
|
|
62
|
+
* - Returns `false` only if both are `false`.
|
|
63
|
+
*/
|
|
64
|
+
type Or<Condition1,Condition2>=IfExtends<Condition1,true,true,IfExtends<Condition2,true>>;
|
|
65
|
+
/** -------------------------------------------------------
|
|
66
|
+
* * ***Utility Type: `OrArr`.***
|
|
67
|
+
* -------------------------------------------------------
|
|
68
|
+
* **Computes the logical OR of all elements inside a tuple or array of boolean types.**
|
|
69
|
+
* @template Conditions - An array of boolean type elements.
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* type Case1 = OrArr<[true, true, true]>; // ➔ true
|
|
73
|
+
* type Case2 = OrArr<[true, true, false]>; // ➔ true
|
|
74
|
+
* type Case3 = OrArr<[false, false, false]>; // ➔ false
|
|
75
|
+
* type Case4 = OrArr<[]>; // ➔ false
|
|
76
|
+
* ```
|
|
77
|
+
* @remarks
|
|
78
|
+
* - Uses TypeScript's indexed access types and conditional type inference.
|
|
79
|
+
* - Returns `true` if at least one element in the array is `true`.
|
|
80
|
+
* - Returns `false` if all elements are `false` or array is empty.
|
|
81
|
+
*/
|
|
82
|
+
type OrArr<Conditions extends readonly unknown[]>=true extends Conditions[number]?true:false;export type{And as A,OrArr as O,AndArr as a,Or as b};
|