@rzl-zone/utils-js 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +94 -45
  3. package/dist/assertions/index.cjs +41 -1
  4. package/dist/assertions/index.d.ts +11 -2
  5. package/dist/assertions/index.js +14 -1
  6. package/dist/chunk-2CQX5CBG.js +262 -1
  7. package/dist/chunk-2IOOEY45.cjs +30 -1
  8. package/dist/chunk-2WA36TC5.cjs +189 -0
  9. package/dist/chunk-3IBQ5MOM.js +16 -1
  10. package/dist/chunk-3VA554KW.js +34 -1
  11. package/dist/chunk-5757UBXJ.cjs +157 -1
  12. package/dist/chunk-5IGC6PBH.js +33 -1
  13. package/dist/chunk-5KJFVIQT.cjs +65 -1
  14. package/dist/chunk-6JFCSH7J.js +35 -1
  15. package/dist/chunk-6JFZL7YE.cjs +24 -1
  16. package/dist/chunk-7ODAAXX5.cjs +397 -1
  17. package/dist/chunk-BAV5T2E3.cjs +15 -1
  18. package/dist/chunk-CAH33WOQ.cjs +36 -1
  19. package/dist/chunk-CDCERIZ2.js +177 -0
  20. package/dist/chunk-CKTLUNWX.js +22 -1
  21. package/dist/chunk-CMW2TBOQ.js +567 -1
  22. package/dist/chunk-D3ENH7H6.cjs +101 -1
  23. package/dist/chunk-DEZZUYE2.js +152 -1
  24. package/dist/chunk-DVMHRLKP.cjs +16 -1
  25. package/dist/chunk-DWF2R5GD.cjs +225 -1
  26. package/dist/chunk-E55EQK2U.cjs +18 -1
  27. package/dist/chunk-E74U6CYP.cjs +18 -1
  28. package/dist/chunk-EL6A35UR.cjs +64 -1
  29. package/dist/chunk-F6IPNNSJ.cjs +554 -1
  30. package/dist/chunk-FJZGG54N.cjs +267 -1
  31. package/dist/chunk-FWCKOJZM.js +542 -1
  32. package/dist/chunk-FWHNWL2P.cjs +419 -1
  33. package/dist/chunk-GGEADHZO.js +90 -1
  34. package/dist/chunk-GQR4R5WY.js +31 -1
  35. package/dist/chunk-H66AC7GK.cjs +93 -1
  36. package/dist/chunk-HQWOFR56.cjs +33 -1
  37. package/dist/chunk-HYRQMTRH.cjs +24 -1
  38. package/dist/chunk-IRFL4MAX.js +63 -1
  39. package/dist/chunk-IVL7CKVH.cjs +37 -1
  40. package/dist/chunk-IZPBKKPO.js +16 -1
  41. package/dist/chunk-JBQMXC5I.cjs +106 -1
  42. package/dist/chunk-JEQEF5WD.js +95 -1
  43. package/dist/chunk-JMJQCN74.js +370 -1
  44. package/dist/chunk-KHO2SBNA.cjs +16 -1
  45. package/dist/chunk-KVAL5PAG.cjs +26 -1
  46. package/dist/chunk-L5RDAVVH.js +14 -1
  47. package/dist/chunk-LS6U7FAY.cjs +110 -1
  48. package/dist/chunk-NBZWMBO6.js +101 -1
  49. package/dist/chunk-NRF6LWBC.cjs +56 -1
  50. package/dist/chunk-OI5XKNZO.js +53 -1
  51. package/dist/chunk-ONZFBJVW.js +14 -1
  52. package/dist/chunk-OYTYSY7G.js +106 -1
  53. package/dist/chunk-PET42Z7W.js +119 -1
  54. package/dist/chunk-PZQ6I4JJ.cjs +605 -1
  55. package/dist/chunk-QBKAEVYG.js +113 -1
  56. package/dist/chunk-QNKGP5DY.js +14 -1
  57. package/dist/chunk-RIPKY4RU.js +417 -1
  58. package/dist/chunk-RZW35UN5.cjs +116 -1
  59. package/dist/chunk-SBFNXGTJ.js +220 -1
  60. package/dist/chunk-SBKGWRS5.js +22 -1
  61. package/dist/chunk-SIM77PU4.js +59 -1
  62. package/dist/chunk-T2T7K3KR.js +28 -1
  63. package/dist/chunk-T7PU2V7X.cjs +123 -1
  64. package/dist/chunk-UDA26MCU.cjs +16 -1
  65. package/dist/chunk-V45XJKHW.cjs +18 -1
  66. package/dist/chunk-VJDDGRIK.cjs +16 -1
  67. package/dist/chunk-W2WNBUDE.js +16 -1
  68. package/dist/chunk-WVSPXFTY.js +14 -1
  69. package/dist/chunk-XABCB3Y7.cjs +582 -1
  70. package/dist/chunk-XEDXFSGI.js +24 -1
  71. package/dist/chunk-YKPSRP5G.js +571 -1
  72. package/dist/chunk-YWHHVDT4.js +13 -1
  73. package/dist/chunk-ZETAZZLD.cjs +38 -1
  74. package/dist/conversions/index.cjs +104 -1
  75. package/dist/conversions/index.d.ts +10 -1
  76. package/dist/conversions/index.js +25 -1
  77. package/dist/events/index.cjs +32 -1
  78. package/dist/events/index.d.ts +10 -1
  79. package/dist/events/index.js +13 -1
  80. package/dist/formatters/index.cjs +62 -1
  81. package/dist/formatters/index.d.ts +10 -1
  82. package/dist/formatters/index.js +19 -1
  83. package/dist/generators/index.cjs +38 -1
  84. package/dist/generators/index.d.ts +10 -1
  85. package/dist/generators/index.js +15 -1
  86. package/dist/index.d.ts +39 -12
  87. package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +13 -4
  88. package/dist/next/index.cjs +218 -1
  89. package/dist/next/index.d.ts +10 -1
  90. package/dist/next/index.js +213 -1
  91. package/dist/next/server/index.cjs +43 -1
  92. package/dist/next/server/index.d.ts +10 -1
  93. package/dist/next/server/index.js +41 -1
  94. package/dist/operations/index.cjs +33 -1
  95. package/dist/operations/index.d.ts +10 -1
  96. package/dist/operations/index.js +18 -1
  97. package/dist/parsers/index.cjs +18 -1
  98. package/dist/parsers/index.d.ts +10 -1
  99. package/dist/parsers/index.js +11 -1
  100. package/dist/predicates/index.cjs +299 -1
  101. package/dist/predicates/index.d.ts +13 -4
  102. package/dist/predicates/index.js +24 -1
  103. package/dist/promises/index.cjs +25 -1
  104. package/dist/promises/index.d.ts +10 -1
  105. package/dist/promises/index.js +14 -1
  106. package/dist/rzl-utils.global.js +25 -1
  107. package/dist/strings/index.cjs +82 -1
  108. package/dist/strings/index.d.ts +10 -1
  109. package/dist/strings/index.js +15 -1
  110. package/dist/tailwind/index.cjs +43 -1
  111. package/dist/tailwind/index.d.ts +10 -1
  112. package/dist/tailwind/index.js +12 -1
  113. package/dist/urls/index.cjs +51 -1
  114. package/dist/urls/index.d.ts +10 -1
  115. package/dist/urls/index.js +24 -1
  116. package/package.json +60 -179
  117. package/dist/chunk-JYQTCICM.js +0 -1
  118. package/dist/chunk-YLA3DURS.cjs +0 -1
@@ -1 +1,571 @@
1
- import{normalizeSpaces as e}from"./chunk-T2T7K3KR.js";import{parseCurrencyString as t}from"./chunk-IRFL4MAX.js";import{isFinite as r}from"./chunk-3IBQ5MOM.js";import{isInteger as o}from"./chunk-WVSPXFTY.js";import{isEmptyString as n}from"./chunk-W2WNBUDE.js";import{assertIsString as a}from"./chunk-SBKGWRS5.js";import{safeStableStringify as i,isDate as s}from"./chunk-PET42Z7W.js";import{isString as u,getPreciseType as p,assertIsPlainObject as l,hasOwnProp as m,isBoolean as c,isPlainObject as d,isNaN as f,isUndefined as y,isFunction as h,assertIsBoolean as b,isNil as g,isNumber as $,isNonEmptyString as v}from"./chunk-CMW2TBOQ.js";import{isSupportedCountry as T,AsYouType as w}from"libphonenumber-js/max";import{id as N,enUS as C}from"date-fns/locale";import{parse as D,format as E}from"date-fns";var k=(e,n={})=>{if(!u(e)&&!r(e))throw new TypeError(`First parameter (\`value\`) must be of type \`string\` or \`primitive-number\`, but received: \`${p(e)}\`, with value: \`${i(e)}\`.`);l(n,{message:({currentType:e,validType:t})=>`Second parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const s=!!m(n,"decimal")&&n.decimal,g=m(n,"totalDecimal")?n.totalDecimal:2,$=!m(n,"endDecimal")||n.endDecimal,v=!!m(n,"indianFormat")&&n.indianFormat,T=m(n,"suffixCurrency")?n.suffixCurrency:"",w=m(n,"suffixDecimal")?n.suffixDecimal:"",N=m(n,"roundedDecimal")?n.roundedDecimal:"round",C=m(n,"negativeFormat")?n.negativeFormat:"dash";let D=m(n,"separatorDecimals")?n.separatorDecimals:",",E=m(n,"separator")?n.separator:".";if(!(u(E)&&u(D)&&u(T)&&u(w)))throw new TypeError(`Parameter \`separator\`, \`separatorDecimals\`, \`suffixCurrency\` and \`suffixDecimal\` property of the \`options\` (second parameter) must be of type \`string\`, but received: ['separator': \`${p(E)}\`, 'separatorDecimals': \`${p(D)}\`, 'suffixCurrency': \`${p(T)}\`, 'suffixDecimal': \`${p(w)}\`].`);if(!c(s)||!c($)||!c(v))throw new TypeError(`Parameter \`decimal\`, \`endDecimal\` and \`indianFormat\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: ['decimal': \`${p(s)}\`, 'endDecimal': \`${p($)}\`, 'indianFormat': \`${p(v)}\`].`);if(!o(g))throw new TypeError(`Parameter \`totalDecimal\` property of the \`options\` (second parameter) must be of type \`integer-number\`, but received: \`${p(g)}\`, with value: \`${i(length)}\`.`);if(!1!==N&&"round"!==N&&"ceil"!==N&&"floor"!==N)throw new TypeError(`Parameter \`roundedDecimal\` property of the \`options\` (second parameter) must be of type \`false\` or \`string\` must be one of "round" | "ceil" | "floor", but received: \`${p(N)}\`, with value: \`${i(N)}\`.`);if("abs"!==C&&"brackets"!==C&&"dash"!==C&&!d(C))throw new TypeError(`Parameter \`negativeFormat\` property of the \`options\` (second parameter) must be of type \`string\` must be one of "abs" | "brackets" | "dash" or \`plain-object\` type, but received: \`${p(C)}\`, with value: \`${i(C)}\`.`);const k=u(e)?t(e):e;if(f(k))throw new TypeError("First parameter (`value`) could not be parsed into a valid `number`.");let F="",S="",O=Math.abs(k);const M=Math.pow(10,g);if(N){const e=O*M;switch(N){case"round":O=Math.round(e)/M;break;case"ceil":O=Math.ceil(e)/M;break;case"floor":O=Math.floor(e)/M}}if(N)[F,S]=O.toFixed(g).split("."),S=S??"".padEnd(g,"0");else{const e=String(O).split(".");F=e[0],S=(e[1]||"").slice(0,g).padEnd(g,"0")}let P;if(v?(E=",",D=".",P=(T.trim().length?T:"")+((e,t)=>{const r=e.slice(-3),o=e.slice(0,-3);return o?o.replace(/\B(?=(\d{2})+(?!\d))/g,t)+t+r:r})(F,E)):P=(T.trim().length?T:"")+F.replace(/\B(?=(\d{3})+(?!\d))/g,E),s&&!y(S)&&g>0){let e=D+S;$&&(e+=w),P+=e}if(k<0)if("dash"===C)P="-"+P;else if("brackets"===C)P="("+P+")";else if("abs"===C);else if(d(C))if(m(C,"custom")){const e=C.custom;if(!h(e))throw new TypeError(`Parameter \`negativeFormat.custom\` property of the \`options\` (second parameter) must be of type function: \`(formatted: string) => string\`, but received: \`${p(e)}\`.`);const t=e(P);a(t,{message:({currentType:e,validType:t})=>`Parameter \`negativeFormat.custom\` property of the \`options\` (second parameter) expected return a \`${t}\` type value, but received: \`${e}\`.`}),P=t}else{const e=C.style||"dash",t=!y(C.space)&&C.space;if(b(t,{message:({currentType:e,validType:t})=>`Parameter \`negativeFormat.space\` property of the \`options\` (second parameter) must be of type \`${t} or undefined\`, but received: \`${e}\`.`}),"abs"!==e&&"brackets"!==e&&"dash"!==e)throw new TypeError(`Parameter \`negativeFormat.style\` property of the \`options\` (second parameter) must be of type \`string\` must be of type "abs" | "brackets" | "dash", but received: \`${p(e)}\`, with value: \`${i(e)}\`.`);switch(e){case"dash":P="-"+(t?" ":"")+P;break;case"brackets":P=t?`( ${P} )`:`(${P})`}}return P},F=(e,t=",")=>{if(!u(e)&&!r(e))throw new TypeError(`First parameter (\`value\`) must be of type \`string\` or \`primitive number\`, but received: \`${p(e)}\`.`);if(!u(t))throw new TypeError(`Second parameter (\`separator\`) must be of type \`string\` or empty as \`undefined\`, but received: \`${p(t)}\`.`);const o="."===(t=u(t)?t:",")?",":".",n=e.toString().trim(),a=n.lastIndexOf("."),i=n.lastIndexOf(",");let s="";a>i?s=".":i>a&&(s=",");let l=n,m="";if(s){const e=n.split(s);l=e.slice(0,-1).join(s),m=e.slice(-1)[0]}l=l.replace(/[^\d]/g,"");const c=l.replace(/\B(?=(\d{3})+(?!\d))/g,t);return m?`${c}${o}${m}`:c};function S(e,t={}){if(g(e))return"";if(!u(e)&&!$(e))throw new TypeError(`First parameter (\`value\`) must be of type \`string\`, \`number\`, \`null\` or \`undefined\`, but received: \`${p(e)}\`.`);l(t,{message:({currentType:e,validType:t})=>`Second parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const r=!!m(t,"takeNumberOnly")&&t.takeNumberOnly,o=!!m(t,"checkValidOnly")&&t.checkValidOnly,n=m(t,"defaultCountry")?t.defaultCountry:void 0,a=m(t,"separator")?t.separator:" ",s=!m(t,"prependPlusCountryCode")||t.prependPlusCountryCode,d=m(t,"outputFormat")?t.outputFormat:"INTERNATIONAL",f=m(t,"openingNumberCountry")?t.openingNumberCountry:"",h=m(t,"closingNumberCountry")?t.closingNumberCountry:"";if(!c(r)||!c(o)||!c(s))throw new TypeError(`Parameter \`takeNumberOnly\`, \`checkValidOnly\` and \`prependPlusCountryCode\` property of the \`options\` (second parameter) must be of type \`boolean\` or unset as \`undefined\` value, but received: ['takeNumberOnly': \`${p(r)}\`, 'checkValidOnly': \`${p(o)}\`, 'prependPlusCountryCode': \`${p(s)}\`].`);if(!y(n)&&!T(n))throw new TypeError(`Parameter \`defaultCountry\` property of the \`options\` (second parameter) must be of type \`string\` as \`CountryCode\` (ISO-3166-1 alpha-2) or unset as \`undefined\` value, but received: \`${p(n)}\`, with value: \`${i(n,{keepUndefined:!0})}\`.\n\nSee: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements, for all ISO 3166-1 alpha-2 code.`);if(!["INTERNATIONAL","NATIONAL","RFC3966","E.164"].includes(d))throw new TypeError(`Parameter \`outputFormat\` property of the \`options\` (second parameter) must be of type \`string\` as \`OutputFormat\` ("NATIONAL" | "INTERNATIONAL" | "E.164" | "RFC3966") or unset as \`undefined\` (default value to: \`INTERNATIONAL\`) value, but received: \`${p(d)}\`, with value: ${i(d,{keepUndefined:!0})}.`);if(!u(a)||!u(f)||!u(h))throw new TypeError(`Parameter \`separator\`, \`plusNumberCountry\`, \`openingNumberCountry\` and \`closingNumberCountry\` property of the \`options\` (second parameter) must be of type \`string\` or unset as \`undefined\` value, but received: ['separator': \`${p(a)}\`,'openingNumberCountry': \`${p(f)}\`, 'closingNumberCountry': \`${p(h)}\`].`);u(e)||(e=String(e));const b=((e,t)=>{let r;try{return r=new w(t),r.input(e),r}catch{return void r?.reset()}})(e,n),N=(C=b,!!C?.isValid()&&!!C.getNumber());var C;if(o)return N;if(!N)return"";if(r)return b.getNumber().formatNational().replace(/\D/g,"");const D=b.getNumber().format(d);if("INTERNATIONAL"===d){const[e,...t]=D.split(" "),r=s?e:e.replace(/^\++/,""),o=t.join(a);return v(f)&&v(h)?`${f}${r}${h} ${o}`:`${r} ${o}`}if("NATIONAL"===d){return`${D.split(" ").join(a)}`}return D}var O=(e,t,r,o)=>{if(e.length<=t)return"*".repeat(e.length);const n=e.split(""),a=Math.max(t,Math.ceil(e.length*r)),i=new Set;let s=0;for(;i.size<a;){const t=y(o)?Math.floor(Math.random()*e.length):(o+e.length+31*s)%e.length;i.add(t),s++}for(const e of i)n[e]="*";return n.join("")},M=(e,t={})=>{if(!v(e))return"";l(t,{message:({currentType:e,validType:t})=>`Second parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const r=m(t,"mode")?t.mode:"fixed";if("random"!==r&&"fixed"!==r)throw new TypeError(`Parameter \`mode\` property of the \`options\` (second parameter) must be one of "fixed" or "random", but received: \`${p(r)}\`, with value: \`${i(r)}\`.`);if(!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e))return"";const[o,n]=e.split("@"),a=n.split(".");if(a.length<2)return"";const[s,...u]=a,c=u.join("."),d=((e,t)=>"fixed"===e?(()=>{let e=0;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return Math.abs(e)})():void 0)(r,e),f=o.length<4?1:2,y=s.length<4?1:2;return`${O(o,f,.6,d)}@${O(s,y,.5,d)}.${c.length<=2?c:O(c,1,.4,d)}`};function P(t,r,n={}){if(g(t)||r<=0)return t;if(a(t,{message:({currentType:e,validType:t})=>`First parameter (\`subject\`) must be of type \`${t}\`, but received: \`${e}\`.`}),!o(r))throw new TypeError(`Second parameter (\`limiter\`) must be of type \`integer-number\`, but received: \`${p(r)}\`, with value: \`${i(r)}\`.`);l(n,{message:({currentType:e,validType:t})=>`Third parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const s=m(n,"separator")?n.separator:" ",u=!!m(n,"reCountAfterSpace")&&n.reCountAfterSpace;if(a(s,{message:({currentType:e,validType:t})=>`Parameter \`separator\` property of the \`options\` (third parameter) must be of type \`${t}\`, but received: \`${e}\`.`}),b(u,{message:({currentType:e,validType:t})=>`Parameter \`reCountAfterSpace\` property of the \`options\` (third parameter) must be of type \`${t}\`, but received: \`${e}\`.`}),t=e(t),!u){let e="",o=0;for(let n=0;n<t.length;n++){o===r&&(e+=s,o=0),e+=t[n],o++}return e}const c=t.split(" "),d=[];let f=[],y=0;for(let e=0;e<c.length;e++){const t=c[e];let o="",n=0;for(let e=0;e<t.length;e++)o+=t[e],n++,n===r&&e<t.length-1&&(o+=s,n=0);f.push(o),y++,y!==r&&e!==c.length-1||(d.push(f.join(s)),f=[],y=0)}return d.join(" ")}var A=(e,t={})=>{if(!v(e))return"";l(t,{message:({currentType:e,validType:t})=>`Seconds parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const r=!m(t,"trim")||t.trim,s=m(t,"length")?t.length:10;let u=m(t,"ending")?t.ending:"...";if(!o(s))throw new TypeError(`Parameter \`length\` property of the \`options\` (second parameter) must be of type \`integer-number\`, but received: \`${p(s)}\`, with value: \`${i(s)}\`.`);if(s<1)return"";a(u,{message:({currentType:e,validType:t})=>`Parameter \`ending\` property of the \`options\` (second parameter) must be of type \`${t}\`, but received: \`${e}\`.`}),b(r,{message:({currentType:e,validType:t})=>`Parameter \`trim\` property of the \`options\` (second parameter) must be of type \`${t}\`, but received: \`${e}\`.`}),u=n(u)?"...":u.trim();const c=r?e.trim():e;if(c.length<=s)return c;const d=c.slice(0,s);return(r?d:d.trimEnd())+u},I=(e,t={})=>{if(g(e)||!s(e)&&!v(e))return null;d(t)||(t={});const{inputFormat:r,locale:o="en",inputLocale:n="en",...a}=t,i=m(t,"format")&&v(t.format)?t.format:"dd MMM yyyy - HH:mm:ss";let u;try{if(v(e)&&r&&n){const t=v(n)?"id"===n?N:C:n;u=D(e,r,new Date,{locale:t})}else u=new Date(e);if(f(u.getTime()))return null;const t=v(o)?"id"===o?N:C:o;return E(u,i,{...a,locale:t})}catch{return null}},j=(e,t)=>{if(g(e)||!s(e)&&!v(e))return null;const r=new Date(e);if(f(r.getTime()))return null;d(t)||(t={});const{locale:o="en-US",...n}=t;try{return new Intl.DateTimeFormat(v(o)?o.trim():"en-US",n).format(r)}catch{return null}},x=(e,t)=>{if(g(t)&&(t="YYYY-MM-DD hh:mm:ss"),!u(t))return null;if(g(e)||!s(e)&&!v(e))return null;try{const r=new Date(e);if(f(r.getTime()))return null;const o=e=>e.toString().padStart(2,"0"),n={YYYY:r.getFullYear().toString(),MM:o(r.getMonth()+1),DD:o(r.getDate()),hh:o(r.getHours()),mm:o(r.getMinutes()),ss:o(r.getSeconds())},a=Object.entries(n).reduce((e,[t,r])=>e.split(t).join(r),t);return a.includes("NaN")?null:a}catch{return null}},L=e=>{try{if(g(e)||u(e)&&n(e))e=new Date;else if(!s(e)&&!v(e))return"0";const t=new Date(e);if(f(t.getTime()))return"0";const r=e=>e.toString().padStart(2,"0");let o=t.getTimezoneOffset();const a=o<0?"+":"-";return o=Math.abs(o),`${a}${r(Math.floor(o/60))}${r(o%60)}`}catch{return"0"}};export{M as censorEmail,P as chunkString,k as formatCurrency,I as formatDateFns,j as formatDateIntl,x as formatDateTime,F as formatNumber,S as formatPhoneNumber,L as getGMTOffset,A as truncateString};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ import { normalizeSpaces } from './chunk-T2T7K3KR.js';
11
+ import { parseCurrencyString } from './chunk-IRFL4MAX.js';
12
+ import { isFinite } from './chunk-3IBQ5MOM.js';
13
+ import { isInteger } from './chunk-WVSPXFTY.js';
14
+ import { isEmptyString } from './chunk-W2WNBUDE.js';
15
+ import { assertIsString } from './chunk-SBKGWRS5.js';
16
+ import { safeStableStringify, isDate } from './chunk-PET42Z7W.js';
17
+ import { isString, getPreciseType, assertIsPlainObject, hasOwnProp, isBoolean, isPlainObject, isNaN, isUndefined, isFunction, assertIsBoolean, isNil, isNumber, isNonEmptyString } from './chunk-CMW2TBOQ.js';
18
+ import { isSupportedCountry, AsYouType } from 'libphonenumber-js/max';
19
+ import { id, enUS } from 'date-fns/locale';
20
+ import { parse, format } from 'date-fns';
21
+
22
+ var formatIndianNumber = (numStr, separator) => {
23
+ const lastThree = numStr.slice(-3);
24
+ const rest = numStr.slice(0, -3);
25
+ if (!rest) return lastThree;
26
+ return rest.replace(/\B(?=(\d{2})+(?!\d))/g, separator) + separator + lastThree;
27
+ };
28
+ var formatCurrency = (value, options = {}) => {
29
+ if (!isString(value) && !isFinite(value)) {
30
+ throw new TypeError(
31
+ `First parameter (\`value\`) must be of type \`string\` or \`primitive-number\`, but received: \`${getPreciseType(
32
+ value
33
+ )}\`, with value: \`${safeStableStringify(value)}\`.`
34
+ );
35
+ }
36
+ assertIsPlainObject(options, {
37
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
38
+ });
39
+ const decimal = hasOwnProp(options, "decimal") ? options.decimal : false;
40
+ const totalDecimal = hasOwnProp(options, "totalDecimal") ? options.totalDecimal : 2;
41
+ const endDecimal = hasOwnProp(options, "endDecimal") ? options.endDecimal : true;
42
+ const indianFormat = hasOwnProp(options, "indianFormat") ? options.indianFormat : false;
43
+ const suffixCurrency = hasOwnProp(options, "suffixCurrency") ? options.suffixCurrency : "";
44
+ const suffixDecimal = hasOwnProp(options, "suffixDecimal") ? options.suffixDecimal : "";
45
+ const roundedDecimal = hasOwnProp(options, "roundedDecimal") ? options.roundedDecimal : "round";
46
+ const negativeFormat = hasOwnProp(options, "negativeFormat") ? options.negativeFormat : "dash";
47
+ let separatorDecimals = hasOwnProp(options, "separatorDecimals") ? options.separatorDecimals : ",";
48
+ let separator = hasOwnProp(options, "separator") ? options.separator : ".";
49
+ if (!isString(separator) || !isString(separatorDecimals) || !isString(suffixCurrency) || !isString(suffixDecimal)) {
50
+ throw new TypeError(
51
+ `Parameter \`separator\`, \`separatorDecimals\`, \`suffixCurrency\` and \`suffixDecimal\` property of the \`options\` (second parameter) must be of type \`string\`, but received: ['separator': \`${getPreciseType(
52
+ separator
53
+ )}\`, 'separatorDecimals': \`${getPreciseType(
54
+ separatorDecimals
55
+ )}\`, 'suffixCurrency': \`${getPreciseType(
56
+ suffixCurrency
57
+ )}\`, 'suffixDecimal': \`${getPreciseType(suffixDecimal)}\`].`
58
+ );
59
+ }
60
+ if (!isBoolean(decimal) || !isBoolean(endDecimal) || !isBoolean(indianFormat)) {
61
+ throw new TypeError(
62
+ `Parameter \`decimal\`, \`endDecimal\` and \`indianFormat\` property of the \`options\` (second parameter) must be of type \`boolean\`, but received: ['decimal': \`${getPreciseType(
63
+ decimal
64
+ )}\`, 'endDecimal': \`${getPreciseType(
65
+ endDecimal
66
+ )}\`, 'indianFormat': \`${getPreciseType(indianFormat)}\`].`
67
+ );
68
+ }
69
+ if (!isInteger(totalDecimal)) {
70
+ throw new TypeError(
71
+ `Parameter \`totalDecimal\` property of the \`options\` (second parameter) must be of type \`integer-number\`, but received: \`${getPreciseType(
72
+ totalDecimal
73
+ )}\`, with value: \`${safeStableStringify(length)}\`.`
74
+ );
75
+ }
76
+ if (!(roundedDecimal === false || roundedDecimal === "round" || roundedDecimal === "ceil" || roundedDecimal === "floor")) {
77
+ throw new TypeError(
78
+ `Parameter \`roundedDecimal\` property of the \`options\` (second parameter) must be of type \`false\` or \`string\` must be one of "round" | "ceil" | "floor", but received: \`${getPreciseType(
79
+ roundedDecimal
80
+ )}\`, with value: \`${safeStableStringify(roundedDecimal)}\`.`
81
+ );
82
+ }
83
+ if (!(negativeFormat === "abs" || negativeFormat === "brackets" || negativeFormat === "dash" || isPlainObject(negativeFormat))) {
84
+ throw new TypeError(
85
+ `Parameter \`negativeFormat\` property of the \`options\` (second parameter) must be of type \`string\` must be one of "abs" | "brackets" | "dash" or \`plain-object\` type, but received: \`${getPreciseType(
86
+ negativeFormat
87
+ )}\`, with value: \`${safeStableStringify(negativeFormat)}\`.`
88
+ );
89
+ }
90
+ const rawNum = isString(value) ? parseCurrencyString(value) : value;
91
+ if (isNaN(rawNum)) {
92
+ throw new TypeError(
93
+ `First parameter (\`value\`) could not be parsed into a valid \`number\`.`
94
+ );
95
+ }
96
+ let integerPart = "";
97
+ let decimalPartRaw = "";
98
+ let num = Math.abs(rawNum);
99
+ const factor = Math.pow(10, totalDecimal);
100
+ if (roundedDecimal) {
101
+ const scaled = num * factor;
102
+ switch (roundedDecimal) {
103
+ case "round":
104
+ num = Math.round(scaled) / factor;
105
+ break;
106
+ case "ceil":
107
+ num = Math.ceil(scaled) / factor;
108
+ break;
109
+ case "floor":
110
+ num = Math.floor(scaled) / factor;
111
+ break;
112
+ }
113
+ }
114
+ if (roundedDecimal) {
115
+ [integerPart, decimalPartRaw] = num.toFixed(totalDecimal).split(".");
116
+ decimalPartRaw = decimalPartRaw ?? "".padEnd(totalDecimal, "0");
117
+ } else {
118
+ const split = String(num).split(".");
119
+ integerPart = split[0];
120
+ decimalPartRaw = (split[1] || "").slice(0, totalDecimal).padEnd(totalDecimal, "0");
121
+ }
122
+ let formattedInteger;
123
+ if (indianFormat) {
124
+ separator = ",";
125
+ separatorDecimals = ".";
126
+ formattedInteger = (suffixCurrency.trim().length ? suffixCurrency : "") + formatIndianNumber(integerPart, separator);
127
+ } else {
128
+ formattedInteger = (suffixCurrency.trim().length ? suffixCurrency : "") + integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
129
+ }
130
+ if (decimal && !isUndefined(decimalPartRaw) && totalDecimal > 0) {
131
+ let formattedDecimal = separatorDecimals + decimalPartRaw;
132
+ if (endDecimal) formattedDecimal += suffixDecimal;
133
+ formattedInteger += formattedDecimal;
134
+ }
135
+ if (rawNum < 0) {
136
+ if (negativeFormat === "dash") {
137
+ formattedInteger = "-" + formattedInteger;
138
+ } else if (negativeFormat === "brackets") {
139
+ formattedInteger = "(" + formattedInteger + ")";
140
+ } else if (negativeFormat === "abs") ; else if (isPlainObject(negativeFormat)) {
141
+ if (hasOwnProp(negativeFormat, "custom")) {
142
+ const formatCustomNegative = negativeFormat.custom;
143
+ if (!isFunction(formatCustomNegative)) {
144
+ throw new TypeError(
145
+ `Parameter \`negativeFormat.custom\` property of the \`options\` (second parameter) must be of type function: \`(formatted: string) => string\`, but received: \`${getPreciseType(
146
+ formatCustomNegative
147
+ )}\`.`
148
+ );
149
+ }
150
+ const result = formatCustomNegative(formattedInteger);
151
+ assertIsString(result, {
152
+ message: ({ currentType, validType }) => `Parameter \`negativeFormat.custom\` property of the \`options\` (second parameter) expected return a \`${validType}\` type value, but received: \`${currentType}\`.`
153
+ });
154
+ formattedInteger = result;
155
+ } else {
156
+ const formatStyleNegative = negativeFormat.style || "dash";
157
+ const formatSpaceNegative = !isUndefined(negativeFormat.space) ? negativeFormat.space : false;
158
+ assertIsBoolean(formatSpaceNegative, {
159
+ message: ({ currentType, validType }) => `Parameter \`negativeFormat.space\` property of the \`options\` (second parameter) must be of type \`${validType} or undefined\`, but received: \`${currentType}\`.`
160
+ });
161
+ if (!(formatStyleNegative === "abs" || formatStyleNegative === "brackets" || formatStyleNegative === "dash")) {
162
+ throw new TypeError(
163
+ `Parameter \`negativeFormat.style\` property of the \`options\` (second parameter) must be of type \`string\` must be of type "abs" | "brackets" | "dash", but received: \`${getPreciseType(
164
+ formatStyleNegative
165
+ )}\`, with value: \`${safeStableStringify(formatStyleNegative)}\`.`
166
+ );
167
+ }
168
+ switch (formatStyleNegative) {
169
+ case "dash":
170
+ formattedInteger = "-" + (formatSpaceNegative ? " " : "") + formattedInteger;
171
+ break;
172
+ case "brackets":
173
+ formattedInteger = formatSpaceNegative ? `( ${formattedInteger} )` : `(${formattedInteger})`;
174
+ break;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ return formattedInteger;
180
+ };
181
+
182
+ var formatNumber = (value, separator = ",") => {
183
+ if (!isString(value) && !isFinite(value)) {
184
+ throw new TypeError(
185
+ `First parameter (\`value\`) must be of type \`string\` or \`primitive number\`, but received: \`${getPreciseType(
186
+ value
187
+ )}\`.`
188
+ );
189
+ }
190
+ if (!isString(separator)) {
191
+ throw new TypeError(
192
+ `Second parameter (\`separator\`) must be of type \`string\` or empty as \`undefined\`, but received: \`${getPreciseType(
193
+ separator
194
+ )}\`.`
195
+ );
196
+ }
197
+ separator = isString(separator) ? separator : ",";
198
+ const decimalSeparator = separator === "." ? "," : separator === "," ? "." : ".";
199
+ const stringValue = value.toString().trim();
200
+ const lastDot = stringValue.lastIndexOf(".");
201
+ const lastComma = stringValue.lastIndexOf(",");
202
+ let actualDecimal = "";
203
+ if (lastDot > lastComma) {
204
+ actualDecimal = ".";
205
+ } else if (lastComma > lastDot) {
206
+ actualDecimal = ",";
207
+ }
208
+ let integerPart = stringValue;
209
+ let decimalPart = "";
210
+ if (actualDecimal) {
211
+ const parts = stringValue.split(actualDecimal);
212
+ integerPart = parts.slice(0, -1).join(actualDecimal);
213
+ decimalPart = parts.slice(-1)[0];
214
+ }
215
+ integerPart = integerPart.replace(/[^\d]/g, "");
216
+ const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
217
+ return decimalPart ? `${formattedInteger}${decimalSeparator}${decimalPart}` : formattedInteger;
218
+ };
219
+ var parsingAsYouType = (value, defaultCountry) => {
220
+ let parsed;
221
+ try {
222
+ parsed = new AsYouType(defaultCountry);
223
+ parsed.input(value);
224
+ return parsed;
225
+ } catch {
226
+ parsed?.reset();
227
+ return void 0;
228
+ }
229
+ };
230
+ var isValidParseAsYouType = (parsedAsYouType) => {
231
+ const parsed = !!parsedAsYouType?.isValid() && !!parsedAsYouType.getNumber();
232
+ return parsed;
233
+ };
234
+
235
+ function formatPhoneNumber(value, options = {}) {
236
+ if (isNil(value)) return "";
237
+ if (!isString(value) && !isNumber(value)) {
238
+ throw new TypeError(
239
+ `First parameter (\`value\`) must be of type \`string\`, \`number\`, \`null\` or \`undefined\`, but received: \`${getPreciseType(
240
+ value
241
+ )}\`.`
242
+ );
243
+ }
244
+ assertIsPlainObject(options, {
245
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
246
+ });
247
+ const takeNumberOnly = hasOwnProp(options, "takeNumberOnly") ? options.takeNumberOnly : false;
248
+ const checkValidOnly = hasOwnProp(options, "checkValidOnly") ? options.checkValidOnly : false;
249
+ const defaultCountry = hasOwnProp(
250
+ options,
251
+ "defaultCountry"
252
+ ) ? options.defaultCountry : void 0;
253
+ const separator = hasOwnProp(options, "separator") ? options.separator : " ";
254
+ const prependPlusCountryCode = hasOwnProp(options, "prependPlusCountryCode") ? options.prependPlusCountryCode : true;
255
+ const outputFormat = hasOwnProp(options, "outputFormat") ? options.outputFormat : "INTERNATIONAL";
256
+ const openingNumberCountry = hasOwnProp(options, "openingNumberCountry") ? options.openingNumberCountry : "";
257
+ const closingNumberCountry = hasOwnProp(options, "closingNumberCountry") ? options.closingNumberCountry : "";
258
+ if (!isBoolean(takeNumberOnly) || !isBoolean(checkValidOnly) || !isBoolean(prependPlusCountryCode)) {
259
+ throw new TypeError(
260
+ `Parameter \`takeNumberOnly\`, \`checkValidOnly\` and \`prependPlusCountryCode\` property of the \`options\` (second parameter) must be of type \`boolean\` or unset as \`undefined\` value, but received: ['takeNumberOnly': \`${getPreciseType(
261
+ takeNumberOnly
262
+ )}\`, 'checkValidOnly': \`${getPreciseType(
263
+ checkValidOnly
264
+ )}\`, 'prependPlusCountryCode': \`${getPreciseType(prependPlusCountryCode)}\`].`
265
+ );
266
+ }
267
+ if (!isUndefined(defaultCountry) && !isSupportedCountry(defaultCountry)) {
268
+ throw new TypeError(
269
+ `Parameter \`defaultCountry\` property of the \`options\` (second parameter) must be of type \`string\` as \`CountryCode\` (ISO-3166-1 alpha-2) or unset as \`undefined\` value, but received: \`${getPreciseType(
270
+ defaultCountry
271
+ )}\`, with value: \`${safeStableStringify(defaultCountry, {
272
+ keepUndefined: true
273
+ })}\`.
274
+
275
+ See: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements, for all ISO 3166-1 alpha-2 code.`
276
+ );
277
+ }
278
+ if (!["INTERNATIONAL", "NATIONAL", "RFC3966", "E.164"].includes(outputFormat)) {
279
+ throw new TypeError(
280
+ `Parameter \`outputFormat\` property of the \`options\` (second parameter) must be of type \`string\` as \`OutputFormat\` ("NATIONAL" | "INTERNATIONAL" | "E.164" | "RFC3966") or unset as \`undefined\` (default value to: \`INTERNATIONAL\`) value, but received: \`${getPreciseType(
281
+ outputFormat
282
+ )}\`, with value: ${safeStableStringify(outputFormat, { keepUndefined: true })}.`
283
+ );
284
+ }
285
+ if (!isString(separator) || !isString(openingNumberCountry) || !isString(closingNumberCountry)) {
286
+ throw new TypeError(
287
+ `Parameter \`separator\`, \`plusNumberCountry\`, \`openingNumberCountry\` and \`closingNumberCountry\` property of the \`options\` (second parameter) must be of type \`string\` or unset as \`undefined\` value, but received: ['separator': \`${getPreciseType(
288
+ separator
289
+ )}\`,'openingNumberCountry': \`${getPreciseType(
290
+ openingNumberCountry
291
+ )}\`, 'closingNumberCountry': \`${getPreciseType(closingNumberCountry)}\`].`
292
+ );
293
+ }
294
+ if (!isString(value)) value = String(value);
295
+ const parsedPhoneNumber = parsingAsYouType(value, defaultCountry);
296
+ const validPhoneNumber = isValidParseAsYouType(parsedPhoneNumber);
297
+ if (checkValidOnly) return validPhoneNumber;
298
+ if (!validPhoneNumber) return "";
299
+ if (takeNumberOnly) {
300
+ return parsedPhoneNumber.getNumber().formatNational().replace(/\D/g, "");
301
+ }
302
+ const num = parsedPhoneNumber.getNumber();
303
+ const intlNumb = num.format(outputFormat);
304
+ if (outputFormat === "INTERNATIONAL") {
305
+ const [cc, ...rest] = intlNumb.split(" ");
306
+ const countryCode = prependPlusCountryCode ? cc : cc.replace(/^\++/, "");
307
+ const restWithSeparator = rest.join(separator);
308
+ if (isNonEmptyString(openingNumberCountry) && isNonEmptyString(closingNumberCountry)) {
309
+ return `${openingNumberCountry}${countryCode}${closingNumberCountry} ${restWithSeparator}`;
310
+ }
311
+ return `${countryCode} ${restWithSeparator}`;
312
+ }
313
+ if (outputFormat === "NATIONAL") {
314
+ const restWithSeparator = intlNumb.split(" ").join(separator);
315
+ return `${restWithSeparator}`;
316
+ }
317
+ return intlNumb;
318
+ }
319
+
320
+ var hashSeedGenerate = (mode, email) => {
321
+ const generateSeed = () => {
322
+ let hash = 0;
323
+ for (let i = 0; i < email.length; i++) {
324
+ hash = (hash << 5) - hash + email.charCodeAt(i);
325
+ hash |= 0;
326
+ }
327
+ return Math.abs(hash);
328
+ };
329
+ return mode === "fixed" ? generateSeed() : void 0;
330
+ };
331
+ var _censor = (str, minCensor, maxPercentage, hashSeed) => {
332
+ if (str.length <= minCensor) return "*".repeat(str.length);
333
+ const strArr = str.split("");
334
+ const totalCensor = Math.max(minCensor, Math.ceil(str.length * maxPercentage));
335
+ const indexes = /* @__PURE__ */ new Set();
336
+ let i = 0;
337
+ while (indexes.size < totalCensor) {
338
+ const idx = !isUndefined(hashSeed) ? (hashSeed + str.length + i * 31) % str.length : Math.floor(Math.random() * str.length);
339
+ indexes.add(idx);
340
+ i++;
341
+ }
342
+ for (const index of indexes) {
343
+ strArr[index] = "*";
344
+ }
345
+ return strArr.join("");
346
+ };
347
+
348
+ var censorEmail = (email, options = {}) => {
349
+ if (!isNonEmptyString(email)) return "";
350
+ assertIsPlainObject(options, {
351
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
352
+ });
353
+ const mode = hasOwnProp(options, "mode") ? options.mode : "fixed";
354
+ if (mode !== "random" && mode !== "fixed") {
355
+ throw new TypeError(
356
+ `Parameter \`mode\` property of the \`options\` (second parameter) must be one of "fixed" or "random", but received: \`${getPreciseType(
357
+ mode
358
+ )}\`, with value: \`${safeStableStringify(mode)}\`.`
359
+ );
360
+ }
361
+ const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
362
+ if (!emailRegex.test(email)) return "";
363
+ const [local, domain] = email.split("@");
364
+ const domainParts = domain.split(".");
365
+ if (domainParts.length < 2) return "";
366
+ const [domainName, ...tldParts] = domainParts;
367
+ const tld = tldParts.join(".");
368
+ const hashSeed = hashSeedGenerate(mode, email);
369
+ const localMinCensor = local.length < 4 ? 1 : 2;
370
+ const domainMinCensor = domainName.length < 4 ? 1 : 2;
371
+ const censoredLocal = _censor(local, localMinCensor, 0.6, hashSeed);
372
+ const censoredDomain = _censor(domainName, domainMinCensor, 0.5, hashSeed);
373
+ const censoredTLD = tld.length <= 2 ? tld : _censor(tld, 1, 0.4, hashSeed);
374
+ return `${censoredLocal}@${censoredDomain}.${censoredTLD}`;
375
+ };
376
+
377
+ function chunkString(subject, limiter, options = {}) {
378
+ if (isNil(subject) || limiter <= 0) return subject;
379
+ assertIsString(subject, {
380
+ message: ({ currentType, validType }) => `First parameter (\`subject\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
381
+ });
382
+ if (!isInteger(limiter)) {
383
+ throw new TypeError(
384
+ `Second parameter (\`limiter\`) must be of type \`integer-number\`, but received: \`${getPreciseType(
385
+ limiter
386
+ )}\`, with value: \`${safeStableStringify(limiter)}\`.`
387
+ );
388
+ }
389
+ assertIsPlainObject(options, {
390
+ message: ({ currentType, validType }) => `Third parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
391
+ });
392
+ const separator = hasOwnProp(options, "separator") ? options.separator : " ";
393
+ const reCountAfterSpace = hasOwnProp(options, "reCountAfterSpace") ? options.reCountAfterSpace : false;
394
+ assertIsString(separator, {
395
+ message: ({ currentType, validType }) => `Parameter \`separator\` property of the \`options\` (third parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
396
+ });
397
+ assertIsBoolean(reCountAfterSpace, {
398
+ message: ({ currentType, validType }) => `Parameter \`reCountAfterSpace\` property of the \`options\` (third parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
399
+ });
400
+ subject = normalizeSpaces(subject);
401
+ if (!reCountAfterSpace) {
402
+ let result = "";
403
+ let currentCount = 0;
404
+ for (let i = 0; i < subject.length; i++) {
405
+ const char = subject[i];
406
+ if (currentCount === limiter) {
407
+ result += separator;
408
+ currentCount = 0;
409
+ }
410
+ result += char;
411
+ currentCount++;
412
+ }
413
+ return result;
414
+ }
415
+ const words = subject.split(" ");
416
+ const finalSegments = [];
417
+ let currentGroup = [];
418
+ let wordsInCurrentGroupCount = 0;
419
+ for (let i = 0; i < words.length; i++) {
420
+ const word = words[i];
421
+ let processedWord = "";
422
+ let charCountInWord = 0;
423
+ for (let j = 0; j < word.length; j++) {
424
+ processedWord += word[j];
425
+ charCountInWord++;
426
+ if (charCountInWord === limiter && j < word.length - 1) {
427
+ processedWord += separator;
428
+ charCountInWord = 0;
429
+ }
430
+ }
431
+ currentGroup.push(processedWord);
432
+ wordsInCurrentGroupCount++;
433
+ if (wordsInCurrentGroupCount === limiter || i === words.length - 1) {
434
+ finalSegments.push(currentGroup.join(separator));
435
+ currentGroup = [];
436
+ wordsInCurrentGroupCount = 0;
437
+ }
438
+ }
439
+ return finalSegments.join(" ");
440
+ }
441
+
442
+ var truncateString = (text, options = {}) => {
443
+ if (!isNonEmptyString(text)) return "";
444
+ assertIsPlainObject(options, {
445
+ message: ({ currentType, validType }) => `Seconds parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
446
+ });
447
+ const trim = hasOwnProp(options, "trim") ? options.trim : true;
448
+ const length2 = hasOwnProp(options, "length") ? options.length : 10;
449
+ let ending = hasOwnProp(options, "ending") ? options.ending : "...";
450
+ if (!isInteger(length2)) {
451
+ throw new TypeError(
452
+ `Parameter \`length\` property of the \`options\` (second parameter) must be of type \`integer-number\`, but received: \`${getPreciseType(
453
+ length2
454
+ )}\`, with value: \`${safeStableStringify(length2)}\`.`
455
+ );
456
+ }
457
+ if (length2 < 1) return "";
458
+ assertIsString(ending, {
459
+ message: ({ currentType, validType }) => `Parameter \`ending\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
460
+ });
461
+ assertIsBoolean(trim, {
462
+ message: ({ currentType, validType }) => `Parameter \`trim\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
463
+ });
464
+ if (isEmptyString(ending)) {
465
+ ending = "...";
466
+ } else {
467
+ ending = ending.trim();
468
+ }
469
+ const original = trim ? text.trim() : text;
470
+ const originalTrimmedLength = original.length;
471
+ if (originalTrimmedLength <= length2) return original;
472
+ const sliced = original.slice(0, length2);
473
+ const cleanSliced = trim ? sliced : sliced.trimEnd();
474
+ return cleanSliced + ending;
475
+ };
476
+ var formatDateFns = (date, options = {}) => {
477
+ if (isNil(date) || !(isDate(date) || isNonEmptyString(date))) return null;
478
+ if (!isPlainObject(options)) {
479
+ options = {};
480
+ }
481
+ const { inputFormat, locale = "en", inputLocale = "en", ...restOptions } = options;
482
+ const format$1 = hasOwnProp(options, "format") && isNonEmptyString(options.format) ? options.format : "dd MMM yyyy - HH:mm:ss";
483
+ let parsedDate;
484
+ try {
485
+ if (isNonEmptyString(date) && inputFormat && inputLocale) {
486
+ const valueOfInputLocale = isNonEmptyString(inputLocale) ? inputLocale === "id" ? id : enUS : inputLocale;
487
+ parsedDate = parse(date, inputFormat, /* @__PURE__ */ new Date(), {
488
+ locale: valueOfInputLocale
489
+ });
490
+ } else {
491
+ parsedDate = new Date(date);
492
+ }
493
+ if (isNaN(parsedDate.getTime())) return null;
494
+ const valueOfLocale = isNonEmptyString(locale) ? locale === "id" ? id : enUS : locale;
495
+ return format(parsedDate, format$1, {
496
+ ...restOptions,
497
+ locale: valueOfLocale
498
+ });
499
+ } catch {
500
+ return null;
501
+ }
502
+ };
503
+
504
+ var formatDateIntl = (date, options) => {
505
+ if (isNil(date) || !(isDate(date) || isNonEmptyString(date))) return null;
506
+ const parsedDate = new Date(date);
507
+ if (isNaN(parsedDate.getTime())) return null;
508
+ if (!isPlainObject(options)) {
509
+ options = {};
510
+ }
511
+ const { locale = "en-US", ...restProps } = options;
512
+ try {
513
+ return new Intl.DateTimeFormat(
514
+ isNonEmptyString(locale) ? locale.trim() : "en-US",
515
+ restProps
516
+ ).format(parsedDate);
517
+ } catch {
518
+ return null;
519
+ }
520
+ };
521
+
522
+ var formatDateTime = (date, format) => {
523
+ if (isNil(format)) {
524
+ format = "YYYY-MM-DD hh:mm:ss";
525
+ }
526
+ if (!isString(format)) return null;
527
+ if (isNil(date) || !(isDate(date) || isNonEmptyString(date))) {
528
+ return null;
529
+ }
530
+ try {
531
+ const parsedDate = new Date(date);
532
+ if (isNaN(parsedDate.getTime())) return null;
533
+ const pad2 = (n) => n.toString().padStart(2, "0");
534
+ const map = {
535
+ YYYY: parsedDate.getFullYear().toString(),
536
+ MM: pad2(parsedDate.getMonth() + 1),
537
+ DD: pad2(parsedDate.getDate()),
538
+ hh: pad2(parsedDate.getHours()),
539
+ mm: pad2(parsedDate.getMinutes()),
540
+ ss: pad2(parsedDate.getSeconds())
541
+ };
542
+ const result = Object.entries(map).reduce(
543
+ (prev, [key, value]) => prev.split(key).join(value),
544
+ format
545
+ );
546
+ return !result.includes("NaN") ? result : null;
547
+ } catch {
548
+ return null;
549
+ }
550
+ };
551
+
552
+ var getGMTOffset = (date) => {
553
+ try {
554
+ if (isNil(date) || isString(date) && isEmptyString(date)) {
555
+ date = /* @__PURE__ */ new Date();
556
+ } else if (!(isDate(date) || isNonEmptyString(date))) {
557
+ return "0";
558
+ }
559
+ const parsedDate = new Date(date);
560
+ if (isNaN(parsedDate.getTime())) return "0";
561
+ const padZero = (num) => num.toString().padStart(2, "0");
562
+ let offset = parsedDate.getTimezoneOffset();
563
+ const sign = offset < 0 ? "+" : "-";
564
+ offset = Math.abs(offset);
565
+ return `${sign}${padZero(Math.floor(offset / 60))}${padZero(offset % 60)}`;
566
+ } catch {
567
+ return "0";
568
+ }
569
+ };
570
+
571
+ export { censorEmail, chunkString, formatCurrency, formatDateFns, formatDateIntl, formatDateTime, formatNumber, formatPhoneNumber, getGMTOffset, truncateString };
@@ -1 +1,13 @@
1
- var r=()=>{};export{r as noop};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ var noop = () => {
11
+ };
12
+
13
+ export { noop };
@@ -1 +1,38 @@
1
- "use strict";var e=require("./chunk-PZQ6I4JJ.cjs");exports.isEmptyArray=t=>!e.isArray(t)||0===t.length,exports.isEmptyObject=function(t,r={}){if(!e.isObject(t))return!0;e.assertIsPlainObject(r,{message:({currentType:e,validType:t})=>`Second parameter (\`options\`) must be of type \`${t}\`, but received: \`${e}\`.`});const s=!!e.hasOwnProp(r,"checkSymbols")&&r.checkSymbols;e.assertIsBoolean(s,{message:({currentType:e,validType:t})=>`Parameter \`checkSymbols\` property of the \`options\` (second parameter) must be of type \`${t}\`, but received: \`${e}\`.`});const c=0===Object.keys(t).length;return s?c&&0===Object.getOwnPropertySymbols(t).length:c};
1
+ /*!
2
+ * ====================================================
3
+ * Rzl Utils-JS.
4
+ * ----------------------------------------------------
5
+ * Version: 3.5.1.
6
+ * Author: Rizalvin Dwiky.
7
+ * Repository: https://github.com/rzl-zone/utils-js.
8
+ * ====================================================
9
+ */
10
+ 'use strict';
11
+
12
+ var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
13
+
14
+ var isEmptyArray = (value) => {
15
+ if (!chunkPZQ6I4JJ_cjs.isArray(value)) return true;
16
+ return value.length === 0;
17
+ };
18
+
19
+ function isEmptyObject(value, options = {}) {
20
+ if (!chunkPZQ6I4JJ_cjs.isObject(value)) {
21
+ return true;
22
+ }
23
+ chunkPZQ6I4JJ_cjs.assertIsPlainObject(options, {
24
+ message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
25
+ });
26
+ const checkSymbols = chunkPZQ6I4JJ_cjs.hasOwnProp(options, "checkSymbols") ? options.checkSymbols : false;
27
+ chunkPZQ6I4JJ_cjs.assertIsBoolean(checkSymbols, {
28
+ message: ({ currentType, validType }) => `Parameter \`checkSymbols\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.`
29
+ });
30
+ const hasNoKeys = Object.keys(value).length === 0;
31
+ if (checkSymbols) {
32
+ return hasNoKeys && Object.getOwnPropertySymbols(value).length === 0;
33
+ }
34
+ return hasNoKeys;
35
+ }
36
+
37
+ exports.isEmptyArray = isEmptyArray;
38
+ exports.isEmptyObject = isEmptyObject;