full-utils 2.0.2 → 2.0.4
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/dist/browser.cjs +2 -2
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.mjs +2 -2
- package/dist/browser.mjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -13
- package/dist/index.d.ts +15 -13
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.mjs +2 -2
- package/dist/node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -62,36 +62,36 @@
|
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
64
|
* // Basic values
|
|
65
|
-
*
|
|
65
|
+
* formatStrToFuncArgsArr('1, true, "hello"'); // => [1, true, "hello"]
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* // Bracket-wrapped list
|
|
69
|
-
*
|
|
69
|
+
* formatStrToFuncArgsArr('[1, 2, 3]'); // => [1, 2, 3]
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
72
|
* // Nested structures and quoting
|
|
73
|
-
*
|
|
73
|
+
* formatStrToFuncArgsArr('{"a":1,"b":[2,3]}, "te,xt", (x,y)'); // => [ {a:1,b:[2,3]}, "te,xt", "(x,y)" ]
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
* // Booleans, null/undefined, and Infinity
|
|
77
|
-
*
|
|
77
|
+
* formatStrToFuncArgsArr('yes, NO, null, undefined, Infinity, -Infinity');
|
|
78
78
|
* // => [true, false, null, undefined, Infinity, -Infinity]
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
81
|
* // Macro-like token (returned as-is)
|
|
82
|
-
*
|
|
82
|
+
* formatStrToFuncArgsArr('$env(PATH)'); // => ["$env(PATH)"]
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
85
85
|
* // Escapes inside quotes
|
|
86
|
-
*
|
|
86
|
+
* formatStrToFuncArgsArr('"He said: \\"Hi\\"", \'It\\\'s ok\', "\\\\path"');
|
|
87
87
|
* // => ['He said: "Hi"', "It's ok", "\\path"]
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
90
|
* // Empty and whitespace inputs
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
91
|
+
* formatStrToFuncArgsArr(' '); // => []
|
|
92
|
+
* formatStrToFuncArgsArr('[]'); // => []
|
|
93
|
+
* formatStrToFuncArgsArr('[ ]'); // => []
|
|
94
|
+
* formatStrToFuncArgsArr(' [ a , b ] '); // => ["a", "b"]
|
|
95
95
|
*
|
|
96
96
|
* @param value - Raw string containing comma-separated arguments.
|
|
97
97
|
* If `value` is **not** a string, the function returns `[value]` unchanged.
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
* @public
|
|
107
107
|
* @since 2.0.0
|
|
108
108
|
*/
|
|
109
|
-
declare function
|
|
109
|
+
declare function formatStrToFuncArgsArr(value: string): unknown[];
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Splits an input array into smaller subarrays (portions) of a given fixed size.
|
|
@@ -3466,7 +3466,7 @@ declare function fixedDecimalToStr(value: FixedDecimal): string;
|
|
|
3466
3466
|
* @since 2.0.0
|
|
3467
3467
|
* @public
|
|
3468
3468
|
*/
|
|
3469
|
-
declare function formatToNum(value: unknown, round?: number): number;
|
|
3469
|
+
declare function formatToNum(value: unknown, round?: number, throwError?: boolean): number;
|
|
3470
3470
|
|
|
3471
3471
|
/**
|
|
3472
3472
|
* Normalizes an arbitrary numeric input into sign, integer, and fractional string parts
|
|
@@ -4150,6 +4150,8 @@ declare function formatToTrim(value: unknown): string;
|
|
|
4150
4150
|
*/
|
|
4151
4151
|
declare function formatToUndefined(value: unknown): {} | undefined;
|
|
4152
4152
|
|
|
4153
|
+
declare function formatArrToSqlWhenCaseStr(d: Array<any>): string;
|
|
4154
|
+
|
|
4153
4155
|
/**
|
|
4154
4156
|
* Converts a numeric value with a given unit (bytes, KB, MB, GB, TB, PB)
|
|
4155
4157
|
* into gigabytes (`GB`).
|
|
@@ -4494,4 +4496,4 @@ declare function toH(value: any, unit?: string): number;
|
|
|
4494
4496
|
*/
|
|
4495
4497
|
declare function extractHost(value?: string): string;
|
|
4496
4498
|
|
|
4497
|
-
export { type FixedDecimal, type JSONLike, type PasswordOptions, type RangeIPv4Options, type TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatDateToString,
|
|
4499
|
+
export { type FixedDecimal, type JSONLike, type PasswordOptions, type RangeIPv4Options, type TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatArrToSqlWhenCaseStr, formatDateToString, formatStrToFuncArgsArr, formatToBool, formatToLowerCase, formatToNormalCase, formatToNull, formatToNum, formatToPhone, formatToTrim, formatToUndefined, ipAddrToNum, isArr, isArrFilled, isBool, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, jsonDecode, jsonEncode, normalizeToDecimalComponents, numToIpAddr, parseIPv4, parseStringLike, parseToFixedDecimal, partsToSeconds, rangeIPv4, rangeIPv4ToArr, roundFixedDecimal, secondsToParts, splitArrToPortions, toGB, toGH, toH, toIPv4, tryParseJSON, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -62,36 +62,36 @@
|
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
64
|
* // Basic values
|
|
65
|
-
*
|
|
65
|
+
* formatStrToFuncArgsArr('1, true, "hello"'); // => [1, true, "hello"]
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* // Bracket-wrapped list
|
|
69
|
-
*
|
|
69
|
+
* formatStrToFuncArgsArr('[1, 2, 3]'); // => [1, 2, 3]
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
72
|
* // Nested structures and quoting
|
|
73
|
-
*
|
|
73
|
+
* formatStrToFuncArgsArr('{"a":1,"b":[2,3]}, "te,xt", (x,y)'); // => [ {a:1,b:[2,3]}, "te,xt", "(x,y)" ]
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
* // Booleans, null/undefined, and Infinity
|
|
77
|
-
*
|
|
77
|
+
* formatStrToFuncArgsArr('yes, NO, null, undefined, Infinity, -Infinity');
|
|
78
78
|
* // => [true, false, null, undefined, Infinity, -Infinity]
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
81
|
* // Macro-like token (returned as-is)
|
|
82
|
-
*
|
|
82
|
+
* formatStrToFuncArgsArr('$env(PATH)'); // => ["$env(PATH)"]
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
85
85
|
* // Escapes inside quotes
|
|
86
|
-
*
|
|
86
|
+
* formatStrToFuncArgsArr('"He said: \\"Hi\\"", \'It\\\'s ok\', "\\\\path"');
|
|
87
87
|
* // => ['He said: "Hi"', "It's ok", "\\path"]
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
90
|
* // Empty and whitespace inputs
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
91
|
+
* formatStrToFuncArgsArr(' '); // => []
|
|
92
|
+
* formatStrToFuncArgsArr('[]'); // => []
|
|
93
|
+
* formatStrToFuncArgsArr('[ ]'); // => []
|
|
94
|
+
* formatStrToFuncArgsArr(' [ a , b ] '); // => ["a", "b"]
|
|
95
95
|
*
|
|
96
96
|
* @param value - Raw string containing comma-separated arguments.
|
|
97
97
|
* If `value` is **not** a string, the function returns `[value]` unchanged.
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
* @public
|
|
107
107
|
* @since 2.0.0
|
|
108
108
|
*/
|
|
109
|
-
declare function
|
|
109
|
+
declare function formatStrToFuncArgsArr(value: string): unknown[];
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Splits an input array into smaller subarrays (portions) of a given fixed size.
|
|
@@ -3466,7 +3466,7 @@ declare function fixedDecimalToStr(value: FixedDecimal): string;
|
|
|
3466
3466
|
* @since 2.0.0
|
|
3467
3467
|
* @public
|
|
3468
3468
|
*/
|
|
3469
|
-
declare function formatToNum(value: unknown, round?: number): number;
|
|
3469
|
+
declare function formatToNum(value: unknown, round?: number, throwError?: boolean): number;
|
|
3470
3470
|
|
|
3471
3471
|
/**
|
|
3472
3472
|
* Normalizes an arbitrary numeric input into sign, integer, and fractional string parts
|
|
@@ -4150,6 +4150,8 @@ declare function formatToTrim(value: unknown): string;
|
|
|
4150
4150
|
*/
|
|
4151
4151
|
declare function formatToUndefined(value: unknown): {} | undefined;
|
|
4152
4152
|
|
|
4153
|
+
declare function formatArrToSqlWhenCaseStr(d: Array<any>): string;
|
|
4154
|
+
|
|
4153
4155
|
/**
|
|
4154
4156
|
* Converts a numeric value with a given unit (bytes, KB, MB, GB, TB, PB)
|
|
4155
4157
|
* into gigabytes (`GB`).
|
|
@@ -4494,4 +4496,4 @@ declare function toH(value: any, unit?: string): number;
|
|
|
4494
4496
|
*/
|
|
4495
4497
|
declare function extractHost(value?: string): string;
|
|
4496
4498
|
|
|
4497
|
-
export { type FixedDecimal, type JSONLike, type PasswordOptions, type RangeIPv4Options, type TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatDateToString,
|
|
4499
|
+
export { type FixedDecimal, type JSONLike, type PasswordOptions, type RangeIPv4Options, type TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatArrToSqlWhenCaseStr, formatDateToString, formatStrToFuncArgsArr, formatToBool, formatToLowerCase, formatToNormalCase, formatToNull, formatToNum, formatToPhone, formatToTrim, formatToUndefined, ipAddrToNum, isArr, isArrFilled, isBool, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, jsonDecode, jsonEncode, normalizeToDecimalComponents, numToIpAddr, parseIPv4, parseStringLike, parseToFixedDecimal, partsToSeconds, rangeIPv4, rangeIPv4ToArr, roundFixedDecimal, secondsToParts, splitArrToPortions, toGB, toGH, toH, toIPv4, tryParseJSON, wait };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function ot(t){if(!m(t))return [t];let r=t.trim();if(r==="")return [];if(r.startsWith("[")&&r.endsWith("]")&&(r=r.slice(1,-1).trim(),r===""))return [];let n="",e=false,o=null,i=false,s=0,p=0,d=0,h=[],x=()=>{let u=n.trim();u!==""&&h.push(u),n="";};for(let u=0;u<r.length;u++){let f=r[u];if(e){if(n+=f,i){i=false;continue}if(f==="\\"){i=true;continue}f===o&&(e=false,o=null);continue}if(f==='"'||f==="'"){e=true,o=f,n+=f;continue}if(f==="("){s++,n+=f;continue}if(f===")"){s=Math.max(0,s-1),n+=f;continue}if(f==="["){p++,n+=f;continue}if(f==="]"){p=Math.max(0,p-1),n+=f;continue}if(f==="{"){d++,n+=f;continue}if(f==="}"){d=Math.max(0,d-1),n+=f;continue}if(f===","&&s===0&&p===0&&d===0){x();continue}n+=f;}return n.length&&x(),h.map(u=>{if(u.startsWith("$")&&u.includes("(")&&u.endsWith(")"))return u;if(u==="null")return null;if(u==="undefined")return;if(E(u))return $(u);let f=w(u);if(Number.isFinite(f))return f;if(u==="Infinity")return 1/0;if(u==="-Infinity")return -1/0;let l=String(u||"");if(l.length>=2&&(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"')))return l.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');if(l.startsWith("{")&&l.endsWith("}")||l.startsWith("[")&&l.endsWith("]"))try{return B(l)}catch{}return l})}function st(t,r){if(!Number.isInteger(r)||r<=0)return [];let n=[],e=0;for(;e<t.length;)n.push(t.slice(e,e+r)),e+=r;return n}function $(t){switch(true){case F(t):return t;case y(t):return true;case R(t):return false;case(a(t)&&["true","1","yes","on"].includes(String(t??"").trim().toLowerCase())):return true;case(a(t)&&["false","0","no","off"].includes(String(t??"").trim().toLowerCase())):return false}return false}async function ct(t=0){await new Promise(r=>setTimeout(()=>r(true),t));}function pt(t=1,r=new Date){let n=Math.min(60,Math.max(1,Math.trunc(Math.abs(t)))),e=r.getMinutes(),o=Math.floor(e/n)*n,i=new Date(r);return i.setMinutes(o,0,0),i}function dt(t=new Date){let r=d=>String(d).padStart(2,"0"),n=t.getFullYear(),e=r(t.getMonth()+1),o=r(t.getDate()),i=r(t.getHours()),s=r(t.getMinutes()),p=r(t.getSeconds());return `${n}-${e}-${o} ${i}:${s}:${p}`}function xt(t){let{days:r=0,hours:n=0,minutes:e=0,seconds:o=0}=t;return r*86400+n*3600+e*60+o}function wt(t){if(!Number.isFinite(t)||t<0)throw new Error("Invalid total seconds");let r=Math.floor(t/86400),n=Math.floor(t%86400/3600),e=Math.floor(t%3600/60),o=t%60;return {days:r,hours:n,minutes:e,seconds:o}}function M(t){let[r,n]=t.split("/"),e=b(r),o=n?Number(n):NaN;if(e===null||!Number.isInteger(o)||o<0||o>32)return null;let i=o===0?0:4294967295<<32-o>>>0,s=e&i,p=s|~i>>>0;return [N(s),N(p)]}function Nt(t){let r=t.split(".").map(i=>Number(i));if(r.length!==4||r.some(i=>!Number.isInteger(i)||i<0||i>255))throw new Error("Invalid IPv4 address");let n=new ArrayBuffer(4),e=new DataView(n),o=0;for(;o<4;)e.setUint8(o,r[o]),o++;return e.getUint32(0,false)}function It(t){if(!y(t))return "";let r=new ArrayBuffer(4),n=new DataView(r);n.setUint32(0,t,false);let e=[],o=0;for(;o<4;)e.push(n.getUint8(o)),o++;return e.join(".")}function b(t){if(!m(t))return null;let r=g(t).split(".");if(r.length!==4)return null;let n=0;for(let e=0;e<4;e++){if(!/^\d{1,3}$/.test(r[e]))return null;let o=Number(r[e]);if(o<0||o>255)return null;n=n<<8|o;}return n>>>0}function*j(t,r,n={}){let{includeNetwork:e=true,includeBroadcast:o=true}=n,i,s,p=false,d=null;if(r===void 0&&t.includes("/")){let u=M(t);if(!u)throw new Error(`Invalid CIDR: "${t}"`);let[f,l]=u,[D,Q]=t.split("/");d=Number(Q),i=b(f),s=b(l),p=true;}else {let u=b(t);if(u===null)throw new Error(`Invalid IPv4: "${t}"`);if(i=u,r&&r.trim()!==""){let f=b(r);if(f===null)throw new Error(`Invalid IPv4: "${r}"`);s=f;}else {let f=i>>>24&255,l=i>>>16&255,D=i>>>8&255;s=(f<<24|l<<16|D<<8|255)>>>0;}}i>s&&([i,s]=[s,i]);let h=-1,x=-1;p&&d!==null&&d<=30&&(h=i,x=s);for(let u=i;u<=s;u=u+1>>>0){if(!e&&u===h){if(u===s)break;continue}if(!o&&u===x){if(u===s)break;continue}if(yield N(u),u===4294967295)break}}function Mt(t,r,n={}){let{limit:e=1e6}=n,o=[],i=0;for(let s of j(t,r,n)){if(i>=e)throw new Error(`Range is too large (> ${e}). Use the generator version instead.`);o.push(s),i++;}return o}function N(t){if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`Invalid IPv4 number: ${t}`);return [t>>>24&255,t>>>16&255,t>>>8&255,t&255].join(".")}function k(t){return Array.isArray(t)}function L(t){return k(t)&&t.length>0}function F(t){return typeof t=="boolean"}function Zt(t){if(t instanceof Date)return !Number.isNaN(t.getTime());if(m(t)||c(t)){let r=new Date(t);return !Number.isNaN(r.getTime())}return false}var K=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/;function Ht(t){return a(t)?K.test(t):false}function Qt(t){return t!=null}function qt(t){return typeof t=="function"}var q=/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;function vt(t){if(!m(t))return false;let r=t.trim();return q.test(r)}function nr(t){return m(t)&&/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(t)}function c(t){return typeof t=="number"&&Number.isFinite(t)}function sr(t){return c(t)&&!Number.isInteger(t)}function mr(t){return c(t)&&t<0}function R(t){return c(t)&&t<=0}function y(t){return c(t)&&t>0}function C(t){return c(t)&&t>=0}function T(t){return typeof t=="object"&&t!==null&&Object.prototype.toString.call(t)==="[object Object]"&&!Array.isArray(t)}function z(t){return T(t)&&Object.keys(t).length>0}function Tr(t,{minLength:r=8,maxLength:n=256,requireUppercase:e=true,requireLowercase:o=true,requireDigit:i=true,requireSpecial:s=true}={}){return !(!m(t)||t.length<r||t.length>n||e&&!/[A-ZА-Я]/.test(t)||o&&!/[a-zа-я]/.test(t)||i&&!/\d/.test(t)||s&&!/[~!?@#$%^&*_\-+()\[\]{}><\\\/|"'.,:;=]/.test(t))}function Fr(t){if(!a(t)&&!c(t))return false;let r=String(t).trim();return !(r.startsWith("-")||(r.match(/\+/g)||[]).length>1||r.includes("+")&&!r.startsWith("+")||!/^\+?[0-9-]+$/.test(r)||r.length<3||r.length>20||!/[0-9]$/.test(r)||r.includes("--"))}function m(t){return typeof t=="string"}function E(t){if(!a(t))return false;let r=t.trim().toLowerCase();return r==="true"||r==="false"}function a(t){return m(t)&&t.trim().length>0}function Er(t){if(!a(t))return false;let r=t.trim().toLowerCase();return r==="asc"||r==="desc"}function Mr(t){return m(t)&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)}var Y=/^(['"`])([\s\S]*)\1$/;function P(t,r){let n=t.trim(),e=W(n);if(e.ok)return e.value;let o=Y.exec(n);return o?o[2]:r?n:null}function W(t){try{return {ok:!0,value:JSON.parse(t)}}catch{}return {ok:false}}function B(t,r=false){if(t===null||c(t)||F(t))return t;if(L(t)){let n=t,e=[];for(let o of n)a(o)?e.push(P(String(o),r)):e.push(o);return e}if(z(t)){let n=t,e={};for(let o of Object.keys(n)){let i=n[o];a(i)?e[o]=P(String(i),r):e[o]=i;}return e}return k(t)||T(t)?t:a(t)?P(String(t),r):null}function Gr(t){try{return T(t)||k(t)?JSON.stringify(t):""}catch{}return ""}function Vr(t,r){let n=Math.trunc(r);if(n===0)return {...t};if(n>0)return {sign:t.sign,digitsInteger:t.digitsInteger,scale:t.scale+n};let e=10n**BigInt(-n);return {sign:t.sign,digitsInteger:t.digitsInteger*e,scale:t.scale+n}}function A(t,r){let n=/^([0-9]+)(?:\.([0-9]*))?e([+\-]?[0-9]+)$/i.exec((()=>{let[i,s]=r.split(/e/i),[p,d=""]=i.split("."),h=p.replace(/^0+/,"")+d,x=parseInt(s,10)-d.length;return `${h||"0"}e${x}`})());if(!n)throw new Error("Failed to parse exponential notation.");let e=n[1],o=parseInt(n[3],10);if(C(o))return e=e+"0".repeat(o),{sign:t,integerPart:e||"0",fractionalPart:""};{let i=-o;if(i>=e.length){let s="0".repeat(i-e.length);return {sign:t,integerPart:"0",fractionalPart:s+e}}else {let s=e.length-i;return {sign:t,integerPart:e.slice(0,s),fractionalPart:e.slice(s)}}}}function J(t){return Number(U(t))}function U(t){let r=t.sign<0?"-":"",n=t.digitsInteger.toString();if(t.scale===0)return r+n;let e=t.scale-n.length;if(e>=0)return r+"0."+"0".repeat(e)+n;let o=n.length-t.scale,i=n.slice(0,o),s=n.slice(o);return r+i+"."+s}function w(t,r=1){return J(r>1?Z(O(t),r,"half-up"):O(t))}function _(t){if(typeof t=="bigint"){let r=t<0n?-1:1,n=(t<0n?-t:t).toString();return {sign:r,integerPart:n,fractionalPart:""}}if(typeof t=="number"){if(!Number.isFinite(t))throw new Error("Input number is not finite.");let r=t<0?-1:1,e=Math.abs(t).toExponential(30);return A(r,e)}if(typeof t=="string"){let r=t.trim().replace(",",".");if(!r)throw new Error("Input string is empty.");let n=1;if((r.startsWith("+")||r.startsWith("-"))&&(n=r.startsWith("-")?-1:1,r=r.slice(1)),/^[0-9]*\.?[0-9]*(e[+\-]?[0-9]+)?$/i.test(r)){if(/e/i.test(r))return A(n,r);let[e="0",o=""]=r.split(".");return {sign:n,integerPart:e,fractionalPart:o}}throw new Error("Invalid numeric string.")}throw new Error("Unsupported input type.")}function O(t){let{sign:r,integerPart:n,fractionalPart:e}=_(t),o=n.replace(/^0+/,"")||"0",i=e.replace(/0+$/,""),s=o+i||"0";return {sign:r,digitsInteger:BigInt(s),scale:i.length}}function Z(t,r,n="half-up"){let e=Math.max(0,Math.trunc(r));if(t.scale<=e)return {...t};let o=t.scale-e,i=10n**BigInt(o),s=t.digitsInteger/i,p=t.digitsInteger%i;if(n==="trunc"||p===0n)return {sign:t.sign,digitsInteger:s,scale:e};let d=i/2n,x=p>=d?s+1n:s;return {sign:t.sign,digitsInteger:x,scale:e}}function G(t){if(!m(t))return "";let r=g(t);return a(r)?r.toLowerCase():""}function an(t){if(!m(t))return "";let r=G(t);return a(r)?r[0].toUpperCase()+r.slice(1):""}function gn(t){return m(t)&&g(t)===""||t===void 0?null:t}function wn(t,r="+7"){if(!m(t))return null;let n=g(t).replace(/[\s\-().]/g,"");return /^00\d{8,15}$/.test(n)?n="+"+n.slice(2):/^\d{10}$/.test(n)?n=r+n:/^\d{9,15}$/.test(n)&&!n.startsWith("0")&&(n="+"+n),/^\+\d{10,15}$/.test(n)?n:null}function g(t){return String(m(t)?t.trim().normalize("NFKC").replace(/[\u200B-\u200D\uFEFF]/g,""):"")}function Fn(t){return m(t)&&g(t)===""||t===null?void 0:t}var X=1024,H=X*1024,S=H*1024,V=S*1024,v=V*1024;function In(t,r=""){let n=w(t);if(!c(n))throw new Error(`toGB: value "${t}" is not numeric`);let e=String(r).trim().toLowerCase().replace(/\s+/g,""),o=e?e[0]:"g",i;switch(o){case "b":i=n/S;break;case "k":i=n/H;break;case "m":i=n/S;break;case "g":i=n;break;case "t":i=n*(V/S);break;case "p":i=n*(v/S);break;default:i=n;break}if(!c(i))throw new Error(`toGB: result is not finite (value="${t}", unit="${r}")`);return Object.is(i,-0)?0:i}function I(t){return String(t).trim().toLowerCase().replace(/\s+/g,"").replace(/(?:\/?s|hash(?:es)?)$/i,"")}var tt={h:1e-9,k:1e-6,m:.001,g:1,t:1e3,p:1e6,e:1e9};function En(t,r=""){let n=w(t);if(!c(n))return 0;let e=I(r),o=e?e[0]:"g",i=tt[o]??1,s=n*i;if(!c(s))throw new Error(`toGH: result is not finite (value="${n}", unit="${e}")`);return Object.is(s,-0)?0:s}var rt={h:1,k:1e3,m:1e6,g:1e9,t:1e12,p:1e15,e:1e18};function jn(t,r=""){let n=w(t);if(!c(n))return 0;let e=I(r),o=e?e[0]:"h",i=rt[o]??1,s=n*i;if(!c(s))throw new Error(`toH: result is not finite (value="${n}", unit="${e}")`);return Object.is(s,-0)?0:s}var nt=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function zn(t=""){if(!a(t))return "";let r=t.trim(),n=nt.test(r)?r:`http://${r}`;try{return new URL(n).hostname}catch{let o=(r.split("@").pop()||r).split(/[/?#]/,1)[0],i=o.match(/^\[([^\]]+)\]/);return i?i[1]:o.split(":",1)[0]||""}}
|
|
2
|
-
export{Vr as changeFixedDecimalScale,
|
|
1
|
+
function it(t){if(!m(t))return [t];let r=t.trim();if(r==="")return [];if(r.startsWith("[")&&r.endsWith("]")&&(r=r.slice(1,-1).trim(),r===""))return [];let n="",e=false,o=null,i=false,s=0,p=0,d=0,h=[],x=()=>{let f=n.trim();f!==""&&h.push(f),n="";};for(let f=0;f<r.length;f++){let u=r[f];if(e){if(n+=u,i){i=false;continue}if(u==="\\"){i=true;continue}u===o&&(e=false,o=null);continue}if(u==='"'||u==="'"){e=true,o=u,n+=u;continue}if(u==="("){s++,n+=u;continue}if(u===")"){s=Math.max(0,s-1),n+=u;continue}if(u==="["){p++,n+=u;continue}if(u==="]"){p=Math.max(0,p-1),n+=u;continue}if(u==="{"){d++,n+=u;continue}if(u==="}"){d=Math.max(0,d-1),n+=u;continue}if(u===","&&s===0&&p===0&&d===0){x();continue}n+=u;}return n.length&&x(),h.map(f=>{if(f.startsWith("$")&&f.includes("(")&&f.endsWith(")"))return f;if(f==="null")return null;if(f==="undefined")return;if(P(f))return F(f);let u=w(f);if(Number.isFinite(u))return u;if(f==="Infinity")return 1/0;if(f==="-Infinity")return -1/0;let l=String(f||"");if(l.length>=2&&(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"')))return l.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');if(l.startsWith("{")&&l.endsWith("}")||l.startsWith("[")&&l.endsWith("]"))try{return R(l)}catch{}return l})}function ft(t,r){if(!Number.isInteger(r)||r<=0)return [];let n=[],e=0;for(;e<t.length;)n.push(t.slice(e,e+r)),e+=r;return n}function F(t){switch(true){case T(t):return t;case I(t):return true;case j(t):return false;case(a(t)&&["true","1","yes","on"].includes(String(t??"").trim().toLowerCase())):return true;case(a(t)&&["false","0","no","off"].includes(String(t??"").trim().toLowerCase())):return false}return false}async function at(t=0){await new Promise(r=>setTimeout(()=>r(true),t));}function lt(t=1,r=new Date){let n=Math.min(60,Math.max(1,Math.trunc(Math.abs(t)))),e=r.getMinutes(),o=Math.floor(e/n)*n,i=new Date(r);return i.setMinutes(o,0,0),i}function gt(t=new Date){let r=d=>String(d).padStart(2,"0"),n=t.getFullYear(),e=r(t.getMonth()+1),o=r(t.getDate()),i=r(t.getHours()),s=r(t.getMinutes()),p=r(t.getSeconds());return `${n}-${e}-${o} ${i}:${s}:${p}`}function ht(t){let{days:r=0,hours:n=0,minutes:e=0,seconds:o=0}=t;return r*86400+n*3600+e*60+o}function bt(t){if(!Number.isFinite(t)||t<0)throw new Error("Invalid total seconds");let r=Math.floor(t/86400),n=Math.floor(t%86400/3600),e=Math.floor(t%3600/60),o=t%60;return {days:r,hours:n,minutes:e,seconds:o}}function L(t){let[r,n]=t.split("/"),e=k(r),o=n?Number(n):NaN;if(e===null||!Number.isInteger(o)||o<0||o>32)return null;let i=o===0?0:4294967295<<32-o>>>0,s=e&i,p=s|~i>>>0;return [S(s),S(p)]}function St(t){let r=t.split(".").map(i=>Number(i));if(r.length!==4||r.some(i=>!Number.isInteger(i)||i<0||i>255))throw new Error("Invalid IPv4 address");let n=new ArrayBuffer(4),e=new DataView(n),o=0;for(;o<4;)e.setUint8(o,r[o]),o++;return e.getUint32(0,false)}function Dt(t){if(!I(t))return "";let r=new ArrayBuffer(4),n=new DataView(r);n.setUint32(0,t,false);let e=[],o=0;for(;o<4;)e.push(n.getUint8(o)),o++;return e.join(".")}function k(t){if(!m(t))return null;let r=g(t).split(".");if(r.length!==4)return null;let n=0;for(let e=0;e<4;e++){if(!/^\d{1,3}$/.test(r[e]))return null;let o=Number(r[e]);if(o<0||o>255)return null;n=n<<8|o;}return n>>>0}function*C(t,r,n={}){let{includeNetwork:e=true,includeBroadcast:o=true}=n,i,s,p=false,d=null;if(r===void 0&&t.includes("/")){let f=L(t);if(!f)throw new Error(`Invalid CIDR: "${t}"`);let[u,l]=f,[O,q]=t.split("/");d=Number(q),i=k(u),s=k(l),p=true;}else {let f=k(t);if(f===null)throw new Error(`Invalid IPv4: "${t}"`);if(i=f,r&&r.trim()!==""){let u=k(r);if(u===null)throw new Error(`Invalid IPv4: "${r}"`);s=u;}else {let u=i>>>24&255,l=i>>>16&255,O=i>>>8&255;s=(u<<24|l<<16|O<<8|255)>>>0;}}i>s&&([i,s]=[s,i]);let h=-1,x=-1;p&&d!==null&&d<=30&&(h=i,x=s);for(let f=i;f<=s;f=f+1>>>0){if(!e&&f===h){if(f===s)break;continue}if(!o&&f===x){if(f===s)break;continue}if(yield S(f),f===4294967295)break}}function Lt(t,r,n={}){let{limit:e=1e6}=n,o=[],i=0;for(let s of C(t,r,n)){if(i>=e)throw new Error(`Range is too large (> ${e}). Use the generator version instead.`);o.push(s),i++;}return o}function S(t){if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`Invalid IPv4 number: ${t}`);return [t>>>24&255,t>>>16&255,t>>>8&255,t&255].join(".")}function b(t){return Array.isArray(t)}function D(t){return b(t)&&t.length>0}function T(t){return typeof t=="boolean"}function Ht(t){if(t instanceof Date)return !Number.isNaN(t.getTime());if(m(t)||c(t)){let r=new Date(t);return !Number.isNaN(r.getTime())}return false}var K=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/;function Vt(t){return a(t)?K.test(t):false}function M(t){return t!=null}function Kt(t){return typeof t=="function"}var Y=/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;function vt(t){if(!m(t))return false;let r=t.trim();return Y.test(r)}function nr(t){return m(t)&&/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(t)}function c(t){return typeof t=="number"&&Number.isFinite(t)}function sr(t){return c(t)&&!Number.isInteger(t)}function mr(t){return c(t)&&t<0}function j(t){return c(t)&&t<=0}function I(t){return c(t)&&t>0}function W(t){return c(t)&&t>=0}function N(t){return typeof t=="object"&&t!==null&&Object.prototype.toString.call(t)==="[object Object]"&&!Array.isArray(t)}function z(t){return N(t)&&Object.keys(t).length>0}function Tr(t,{minLength:r=8,maxLength:n=256,requireUppercase:e=true,requireLowercase:o=true,requireDigit:i=true,requireSpecial:s=true}={}){return !(!m(t)||t.length<r||t.length>n||e&&!/[A-ZА-Я]/.test(t)||o&&!/[a-zа-я]/.test(t)||i&&!/\d/.test(t)||s&&!/[~!?@#$%^&*_\-+()\[\]{}><\\\/|"'.,:;=]/.test(t))}function yr(t){if(!a(t)&&!c(t))return false;let r=String(t).trim();return !(r.startsWith("-")||(r.match(/\+/g)||[]).length>1||r.includes("+")&&!r.startsWith("+")||!/^\+?[0-9-]+$/.test(r)||r.length<3||r.length>20||!/[0-9]$/.test(r)||r.includes("--"))}function m(t){return typeof t=="string"}function P(t){if(!a(t))return false;let r=t.trim().toLowerCase();return r==="true"||r==="false"}function a(t){return m(t)&&t.trim().length>0}function Er(t){if(!a(t))return false;let r=t.trim().toLowerCase();return r==="asc"||r==="desc"}function jr(t){return m(t)&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)}var X=/^(['"`])([\s\S]*)\1$/;function A(t,r){let n=t.trim(),e=J(n);if(e.ok)return e.value;let o=X.exec(n);return o?o[2]:r?n:null}function J(t){try{return {ok:!0,value:JSON.parse(t)}}catch{}return {ok:false}}function R(t,r=false){if(t===null||c(t)||T(t))return t;if(D(t)){let n=t,e=[];for(let o of n)a(o)?e.push(A(String(o),r)):e.push(o);return e}if(z(t)){let n=t,e={};for(let o of Object.keys(n)){let i=n[o];a(i)?e[o]=A(String(i),r):e[o]=i;}return e}return b(t)||N(t)?t:a(t)?A(String(t),r):null}function _r(t){try{return N(t)||b(t)?JSON.stringify(t):""}catch{}return ""}function Vr(t,r){let n=Math.trunc(r);if(n===0)return {...t};if(n>0)return {sign:t.sign,digitsInteger:t.digitsInteger,scale:t.scale+n};let e=10n**BigInt(-n);return {sign:t.sign,digitsInteger:t.digitsInteger*e,scale:t.scale+n}}function E(t,r){let n=/^([0-9]+)(?:\.([0-9]*))?e([+\-]?[0-9]+)$/i.exec((()=>{let[i,s]=r.split(/e/i),[p,d=""]=i.split("."),h=p.replace(/^0+/,"")+d,x=parseInt(s,10)-d.length;return `${h||"0"}e${x}`})());if(!n)throw new Error("Failed to parse exponential notation.");let e=n[1],o=parseInt(n[3],10);if(W(o))return e=e+"0".repeat(o),{sign:t,integerPart:e||"0",fractionalPart:""};{let i=-o;if(i>=e.length){let s="0".repeat(i-e.length);return {sign:t,integerPart:"0",fractionalPart:s+e}}else {let s=e.length-i;return {sign:t,integerPart:e.slice(0,s),fractionalPart:e.slice(s)}}}}function U(t){return Number(Z(t))}function Z(t){let r=t.sign<0?"-":"",n=t.digitsInteger.toString();if(t.scale===0)return r+n;let e=t.scale-n.length;if(e>=0)return r+"0."+"0".repeat(e)+n;let o=n.length-t.scale,i=n.slice(0,o),s=n.slice(o);return r+i+"."+s}function w(t,r=1,n=false){try{return U(r>1?H(B(t),r,"half-up"):B(t))}catch(e){if(n)throw e}return 0}function _(t){if(typeof t=="bigint"){let r=t<0n?-1:1,n=(t<0n?-t:t).toString();return {sign:r,integerPart:n,fractionalPart:""}}if(typeof t=="number"){if(!Number.isFinite(t))throw new Error("Input number is not finite.");let r=t<0?-1:1,e=Math.abs(t).toExponential(30);return E(r,e)}if(typeof t=="string"){let r=t.trim().replace(",",".");if(!r)throw new Error("Input string is empty.");let n=1;if((r.startsWith("+")||r.startsWith("-"))&&(n=r.startsWith("-")?-1:1,r=r.slice(1)),/^[0-9]*\.?[0-9]*(e[+\-]?[0-9]+)?$/i.test(r)){if(/e/i.test(r))return E(n,r);let[e="0",o=""]=r.split(".");return {sign:n,integerPart:e,fractionalPart:o}}throw new Error("Invalid numeric string.")}throw new Error("Unsupported input type.")}function B(t){let{sign:r,integerPart:n,fractionalPart:e}=_(t),o=n.replace(/^0+/,"")||"0",i=e.replace(/0+$/,""),s=o+i||"0";return {sign:r,digitsInteger:BigInt(s),scale:i.length}}function H(t,r,n="half-up"){let e=Math.max(0,Math.trunc(r));if(t.scale<=e)return {...t};let o=t.scale-e,i=10n**BigInt(o),s=t.digitsInteger/i,p=t.digitsInteger%i;if(n==="trunc"||p===0n)return {sign:t.sign,digitsInteger:s,scale:e};let d=i/2n,x=p>=d?s+1n:s;return {sign:t.sign,digitsInteger:x,scale:e}}function G(t){if(!m(t))return "";let r=g(t);return a(r)?r.toLowerCase():""}function an(t){if(!m(t))return "";let r=G(t);return a(r)?r[0].toUpperCase()+r.slice(1):""}function gn(t){return m(t)&&g(t)===""||t===void 0?null:t}function wn(t,r="+7"){if(!m(t))return null;let n=g(t).replace(/[\s\-().]/g,"");return /^00\d{8,15}$/.test(n)?n="+"+n.slice(2):/^\d{10}$/.test(n)?n=r+n:/^\d{9,15}$/.test(n)&&!n.startsWith("0")&&(n="+"+n),/^\+\d{10,15}$/.test(n)?n:null}function g(t){return String(m(t)?t.trim().normalize("NFKC").replace(/[\u200B-\u200D\uFEFF]/g,""):"")}function yn(t){return m(t)&&g(t)===""||t===null?void 0:t}function En(t){let r="",n={},e=[];for(r in t[0])r!=="id"&&(n[r]=[]);t.forEach(o=>{let i="";for(i in o)if(b(n[i])){let s=`"${o[i]}"`;(T(o[i])||P(o[i]))&&(s=Number(F(o[i]))),M(o[i])||(s="NULL"),n[i].push(`WHEN "${o.id}" THEN ${s}`);}});for(r in t[0])D(n[r])&&e.push(`${r} = CASE id ${n[r].join(" ")} END`);return e.join(",")}var v=1024,V=v*1024,y=V*1024,Q=y*1024,tt=Q*1024;function jn(t,r=""){let n=w(t);if(!c(n))throw new Error(`toGB: value "${t}" is not numeric`);let e=String(r).trim().toLowerCase().replace(/\s+/g,""),o=e?e[0]:"g",i;switch(o){case "b":i=n/y;break;case "k":i=n/V;break;case "m":i=n/y;break;case "g":i=n;break;case "t":i=n*(Q/y);break;case "p":i=n*(tt/y);break;default:i=n;break}if(!c(i))throw new Error(`toGB: result is not finite (value="${t}", unit="${r}")`);return Object.is(i,-0)?0:i}function $(t){return String(t).trim().toLowerCase().replace(/\s+/g,"").replace(/(?:\/?s|hash(?:es)?)$/i,"")}var rt={h:1e-9,k:1e-6,m:.001,g:1,t:1e3,p:1e6,e:1e9};function zn(t,r=""){let n=w(t);if(!c(n))return 0;let e=$(r),o=e?e[0]:"g",i=rt[o]??1,s=n*i;if(!c(s))throw new Error(`toGH: result is not finite (value="${n}", unit="${e}")`);return Object.is(s,-0)?0:s}var nt={h:1,k:1e3,m:1e6,g:1e9,t:1e12,p:1e15,e:1e18};function Hn(t,r=""){let n=w(t);if(!c(n))return 0;let e=$(r),o=e?e[0]:"h",i=nt[o]??1,s=n*i;if(!c(s))throw new Error(`toH: result is not finite (value="${n}", unit="${e}")`);return Object.is(s,-0)?0:s}var et=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function Vn(t=""){if(!a(t))return "";let r=t.trim(),n=et.test(r)?r:`http://${r}`;try{return new URL(n).hostname}catch{let o=(r.split("@").pop()||r).split(/[/?#]/,1)[0],i=o.match(/^\[([^\]]+)\]/);return i?i[1]:o.split(":",1)[0]||""}}
|
|
2
|
+
export{Vr as changeFixedDecimalScale,L as cidrToRange,E as convertExponentialToParts,Vn as extractHost,U as fixedDecimalToNum,Z as fixedDecimalToStr,lt as floorDateToMinutes,En as formatArrToSqlWhenCaseStr,gt as formatDateToString,it as formatStrToFuncArgsArr,F as formatToBool,G as formatToLowerCase,an as formatToNormalCase,gn as formatToNull,w as formatToNum,wn as formatToPhone,g as formatToTrim,yn as formatToUndefined,St as ipAddrToNum,b as isArr,D as isArrFilled,T as isBool,Ht as isDate,Vt as isEmail,M as isExists,Kt as isFunc,vt as isIpAddr,nr as isMacAddr,c as isNum,sr as isNumFloat,mr as isNumN,j as isNumNZ,I as isNumP,W as isNumPZ,N as isObj,z as isObjFilled,Tr as isPassword,yr as isPhone,m as isStr,Er as isStrAscDesc,P as isStrBool,a as isStrFilled,jr as isVar,R as jsonDecode,_r as jsonEncode,_ as normalizeToDecimalComponents,Dt as numToIpAddr,k as parseIPv4,A as parseStringLike,B as parseToFixedDecimal,ht as partsToSeconds,C as rangeIPv4,Lt as rangeIPv4ToArr,H as roundFixedDecimal,bt as secondsToParts,ft as splitArrToPortions,jn as toGB,zn as toGH,Hn as toH,S as toIPv4,J as tryParseJSON,at as wait};//# sourceMappingURL=index.mjs.map
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|