@rzl-zone/utils-js 0.0.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.
- package/LICENSE.md +21 -0
- package/README.md +215 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4309 -0
- package/dist/index.js +1 -0
- package/dist/next/index.cjs +1 -0
- package/dist/next/index.d.ts +184 -0
- package/dist/next/index.js +1 -0
- package/dist/next/server/index.cjs +1 -0
- package/dist/next/server/index.d.ts +42 -0
- package/dist/next/server/index.js +1 -0
- package/dist/rzl-utils.global.js +1 -0
- package/dist/types/index.d.ts +2057 -0
- package/package.json +148 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{id,enUS}from'date-fns/locale';import{parse,format}from'date-fns';var Pe=(e,r,t=false)=>{if(!(l(e)&&l(r)))throw new TypeError("props 'arr1' and 'arr2' must be `array` type!");if(!d(t))throw new TypeError("props 'ignoreOrder' must be `boolean` type!");if(!P(e.length,r.length))return false;let n=i=>l(i)?i.map(a=>l(a)?n(a):a).sort((a,u)=>{let p=q(a),y=q(u);return p<y?-1:p>y?1:0}):i,o=t?n(e):e,f=t?n(r):r;return P(o.length,f.length)?o.every((i,s)=>q(i)===q(f[s])):false};var Me=(e,r)=>P(e,r);var $=e=>e instanceof URL;var Be=(e,r)=>{if(!$(e)||!$(r))throw new TypeError("Both arguments to 'areURLsEqualPath' must be instances of URL.");return e.protocol+"//"+e.host+e.pathname==r.protocol+"//"+r.host+r.pathname};var We=(e,r)=>{if(!$(e)||!$(r))throw new TypeError("Both arguments to 'areURLsIdentical' must be instances of URL.");return e.protocol+"//"+e.host+e.pathname+e.search==r.protocol+"//"+r.host+r.pathname+r.search};var l=e=>Array.isArray(e);var j=e=>l(e)?e.length===0:true;var He=(e,r)=>{if(!l(e)||!l(r)||j(e)||j(r))return false;let t=new Set(e);return r.some(n=>t.has(n))};var g=e=>typeof e=="number"&&!Number.isNaN(e);var c=e=>typeof e=="string";var U=e=>typeof e=="symbol";var fe=(e,r)=>{if(!e||!O(e))return false;if(!(c(r)||g(r)||U(r)))throw new TypeError("props 'key' must be `string`,`number` or `symbol` type!");return Object.prototype.hasOwnProperty.call(e,r)?true:l(e)?e.some(t=>fe(t,r)):Object.values(e).some(t=>typeof t=="object"&&fe(t,r))};var x=(e,r)=>{if(!c(e))return true;m(r)||(r={});let{trim:t=true}=r;return t&&(e=e.trim()),e===""};var lr=e=>{if(x(e))return null;let r;try{r=decodeURIComponent(e);}catch{return null}let t=/https?:\/\/.*?(?=https?:\/\/|\s|$)/g,n=r.match(t);if(!n)return null;let o=n.map(f=>f.replace(/[.,;:!?)]*$/,"")).filter(f=>{try{let i=new URL(f);return i.protocol==="http:"||i.protocol==="https:"}catch{return false}});return o.length?o:null};var G=e=>typeof e=="bigint";var d=e=>typeof e=="boolean";function ce(e,r={removeInvalidValue:true}){if(!m(r))throw new TypeError("props 'options' must be `object` type!");let t=r&&"removeInvalidValue"in r?r.removeInvalidValue:true;if(!d(t))throw new TypeError("props 'removeInvalidValue' must be `boolean` type!");if(l(e)){let n=Array.from(e,o=>c(o)||g(o)?String(o):b(o)?null:void 0);return t?H(n):n}}function gr(e,r={removeInvalidValueNumber:true}){if(!m(r))throw new TypeError("props 'options' must be `object` type!");let t=r&&"removeInvalidValueNumber"in r?r.removeInvalidValueNumber:true;if(!d(t))throw new TypeError("props 'removeInvalidValueNumber' must be `boolean` type!");if(l(e)){let n=Array.from(e,o=>{let i=String(o).trim().match(/-?\d+(\.\d+)?/);return i?Number(i[0]):void 0});return t?H(n):n}}var H=e=>S(e)?void 0:l(e)?e.reduce((t,n)=>{if(!b(n)&&!w(n))if(l(n)){let o=H(n);o&&!j(o)&&t.push(o);}else t.push(n);return t},[]):[],hr=(e,r)=>{if(!l(e))throw new TypeError("'inputArray' must be an array");if(!m(r))throw new TypeError("'options' must be an object");let{forceToString:t=false,flatten:n=false}=r??{};if(!(t===false||t==="stringOrNumber"||t==="primitives"||t==="all"))throw new TypeError(`'forceToString' must be false | "stringOrNumber" | "primitives" | "all"`);if(!d(n))throw new TypeError("'flatten' must be boolean");let o=i=>{let s=[];return i.reduce((a,u)=>{let p=l(u)?o(u):B(u,t);return s.some(y=>P(y,p))||(s.push(p),a.push(p)),a},[])},f=i=>Array.isArray(i)?i.flatMap(f):i instanceof Set?[...i].flatMap(f):i instanceof Map?[...i.values()].flatMap(f):[i];return o(n?f(e):e)};var Tr=e=>S(e)?false:c(e)?!x(e):d(e)?e:g(e)?e!==0:l(e)||m(e)?!X(e):!!e;var ue=e=>S(e)?false:c(e)?!x(e):d(e)?e:g(e)?e!==0:l(e)?e.some(r=>ue(r)):m(e)?Object.values(e).some(r=>ue(r)):false;var Or=(e,r)=>{if(S(e))return false;let t=r&&"caseInsensitive"in r?r.caseInsensitive:false,n=r&&"trimString"in r?r.trimString:true;if(!d(t))throw new TypeError("props 'caseInsensitive' must be `boolean` type!");if(!d(n))throw new TypeError("props 'trimString' must be `boolean` type!");if(c(e)){let o=e;return n&&(o=o.trim()),t&&(o=o.toLowerCase()),["true","on","yes","1","indeterminate"].includes(o)}return g(e)?e===1:d(e)?e:false};var Ir=e=>S(e)?false:c(e)?!x(e):d(e)?e:g(e)?e!==0:l(e)?e.length>0:!!e;var vr=e=>{if(!c(e)&&!g(e))return 0;let r=String(e).trim().replace(/[^0-9]/g,"");return Number(r)||0};var Q=e=>{if(!N(e))return 0;let r=e.trim().replace(/\u00A0/g,"").replace(/\u202F/g,""),t=false;/^\(.*\)$/.test(r)&&(t=true,r=r.slice(1,-1).trim()),r=r.replace(/^[-\s]+/,a=>a.includes("-")?"-":"").replace(/[\s.,-]+$/,""),t=t||/^-/.test(r)||/^[^\d]*-/.test(r);let o=r.replace(/[^0-9.,'\s]/g,"").replace(/[\s']/g,""),f=o.match(/,\d{2}/g);if(f&&f.length>1)o=o.replace(/,/g,"");else{let a=(o.match(/\./g)||[]).length,u=(o.match(/,/g)||[]).length;if(a>1&&u===0)o=o.replace(/\./g,"");else if(u>1&&a===0)o=o.replace(/,/g,"");else{let p=o.lastIndexOf(","),y=o.lastIndexOf(".");if(p>y)o=o.replace(/\./g,"").replace(",",".");else if(y>p)o=o.replace(/,/g,"");else if(p>y){let T=o.slice(0,p).replace(/,/g,"").replace(/\./g,""),k=o.slice(p+1);o=T+"."+k;}else if(y>p){let T=o.slice(0,y).replace(/\./g,"").replace(/,/g,""),k=o.slice(y+1);o=T+"."+k;}else p!==-1?o=o.replace(/,/g,""):y!==-1&&(o=o.replace(/\./g,""));}}let s=parseFloat(o)||0;return t?-s:s};var Fr=e=>{let r={undefined:void 0,null:null,true:true,false:false,yes:true,no:false};if(c(e)){let t=e.trim().toLowerCase();if(Object.prototype.hasOwnProperty.call(r,t))return r[t];let n=t.replace(/,/g,"");return !isNaN(Number(n))&&n!==""?Number(n):t}return e};var ie=(e,r={})=>{if(!m(r))throw new TypeError("props 'options' must be `object` or empty as `undefined` type!");if(b(e))return r.removeNulls?void 0:null;if(w(e))return r.removeUndefined,void 0;if(l(e)){let t=e.map(n=>ie(n,r)).filter(n=>!w(n));return r.removeEmptyArrays&&j(t)?void 0:t}if(m(e)){let t={},n=e;for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o)){let f=ie(n[o],r);w(f)||(t[o]=f);}return r.removeEmptyObjects&&Object.keys(t).length===0?void 0:t}if(c(e)){let t=e.trim();if(r.convertNumbers&&!isNaN(Number(t)))return Number(t);if(r.convertBooleans){if(t==="true")return true;if(t==="false")return false}if(r.convertDates){if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(t))return new Date(t);if(r.customDateFormats?.length)for(let n of r.customDateFormats){let o=Ne(t,n);if(o)return o}}return r.strictMode?void 0:t}return r.strictMode?void 0:e},Ne=(e,r)=>{if(!c(e)||!c(r))throw new TypeError("props 'dateString' and 'format' must be `string` type!");let t=e.split(/[-/]/).map(Number);if(t.length!==3||t.some(isNaN))return null;let n,o,f;if(r==="DD/MM/YYYY")[n,o,f]=t;else if(r==="MM/DD/YYYY")[o,n,f]=t;else return null;o-=1;let i=new Date(f,o,n);return i.getFullYear()!==f||i.getMonth()!==o||i.getDate()!==n?null:i};function Br(e,r={}){if(b(e))return null;if(c(e)){if(!m(r))throw new TypeError("props 'options' must be `object` or empty as `undefined` type!");try{let t=r.removeUndefined?e.replace(/,\s*"[^"]*"\s*:\s*undefined(?=\s*[},])/g,"").replace(/"[^"]*"\s*:\s*undefined\s*(,)?/g,"").replace(/,(\s*[}\]])/g,"$1"):e.replace(/:\s*undefined(?=\s*[,}])/g,":null"),n=JSON.parse(t);return ie(n,r)}catch(t){r.loggingOnFail&&console.error("JSON parsing failed from `safeJsonParse`:",t),r.onError&&r.onError(t);return}}}var Se=e=>{try{if(D(structuredClone))return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))},ke=(e,r)=>(O(e)&&!b(e)&&r in e&&delete e[r],e),se=(e,r)=>{if(!e||typeof e!="object")return e;let[t,...n]=r;if(Array.isArray(e))for(let o of e)O(o)&&!b(o)&&se(o,r);else j(n)?delete e[t]:!w(e[t])&&O(e[t])&&se(e[t],n);return e},Wr=(e,r,t=true)=>{if(!O(e)||b(e))return{};if(!l(r)||!r.every(o=>O(o)&&"key"in o))throw new TypeError("Expected keysToDelete to be an array of{key,deep?}objects");let n=t?Se(e):e;for(let{key:o,deep:f}of r){let i=o.split(".");n=f?se(n,i):ke(n,i[0]);}return n};var q=(e,r=true,t=false,n=false)=>{if(!d(r)||!d(t))throw new TypeError("Expected 'sortKeys' and 'ignoreOrder' to be boolean.");let o=new WeakSet,f=s=>b(s)||typeof s!="object"&&!D(s),i=s=>{if(!(D(s)||U(s))){if(G(s))return s.toString();if(w(s)||le(s)||s===1/0||s===-1/0)return null;if(typeof s=="object"&&!b(s)){if(o.has(s))return "[Circular]";if(o.add(s),v(s))return s.toISOString();if(s instanceof Map)return{map:Array.from(s.entries()).map(i)};if(s instanceof Set)return{set:Array.from(s.values()).map(i)};if(l(s)){let u=s.map(i);if(t){let p=u.filter(f).sort(),y=u.filter(T=>!f(T));return [...p,...y]}return u}let a=Object.keys(s);return r&&a.sort(),a.reduce((u,p)=>{let y=i(s[p]);return w(y)||(u[p]=y),u},{})}return s}};try{return JSON.stringify(i(e),null,n?2:0)}catch(s){return console.warn("Error in safeStableStringify:",s),"{}"}};var B=(e,r)=>{if(typeof e=="number"&&Number.isNaN(e))return r==="primitives"||r==="all"?"NaN":NaN;if(c(e)||g(e))return r==="stringOrNumber"||r==="primitives"||r==="all"?String(e):e;if(d(e)||G(e)||S(e))return r==="primitives"||r==="all"?String(e):e;if(U(e)||D(e))return r==="all"?e.toString():e;if(l(e))return e.map(t=>B(t,r));if(typeof e=="object"&&!b(e)){if(v(e))return r==="all"?e.toISOString():e;if(Y(e)||ee(e)||e instanceof Promise)return r==="all"?e.toString():e;if(e instanceof Set)return r==="all"?[...e].map(n=>B(n,r)):e;if(e instanceof Map)return r==="all"?[...e.entries()].map(([n,o])=>[B(n,r),B(o,r)]):e;let t={};for(let n of Object.keys(e))t[n]=B(e[n],r);return t}return e};var Hr=(e,r=false,t=false)=>{function n(o,f,i,s){if(!S(o)){if(!d(f)||!d(i))throw new TypeError("props 'removeEmptyObjects' and 'removeEmptyArrays' must be `boolean` type!");if(g(o)||c(o)&&!isNaN(Number(o))){let a=Number(o);return pe(a)?a:void 0}if(l(o)){let a=o.map(u=>n(u,f,i,false)).filter(u=>!w(u));return i&&j(a)?void 0:a}if(m(o)){let a={};for(let[u,p]of Object.entries(o)){let y=n(p,f,i,false);w(y)||(a[u]=y);}return f&&Object.keys(a).length===0?s?{}:void 0:a}}}return n(e,r,t,true)};var et=(e,r=false,t=false)=>{function n(o,f,i,s){if(!S(o)){if(!d(f)||!d(i))throw new TypeError("props 'removeEmptyObjects' and 'removeEmptyArrays' must be `boolean` type!");if(g(o)||c(o))return String(o);if(l(o)){let a=o.map(u=>n(u,f,i,false)).filter(u=>!w(u));return i&&j(a)?void 0:a}if(m(o)){let a={};for(let[u,p]of Object.entries(o)){let y=n(p,f,i,false);w(y)?l(p)&&!i&&(a[u]=[]):a[u]=y;}return f&&Object.keys(a).length===0?s?{}:void 0:a}}}return n(e,r,t,true)};var it=e=>c(e)||g(e)?Q(e.toString())!==0?true:e.toString().trim()==="0":false;var v=e=>e instanceof Date&&!isNaN(e.getTime());var Y=e=>e instanceof RegExp;var Z=(e,r)=>{if(typeof e=="number"&&typeof r=="number"&&Number.isNaN(e)&&Number.isNaN(r)||e===r)return true;if(typeof e!=typeof r)return false;if(v(e)&&v(r))return e.getTime()===r.getTime();if(Y(e)&&Y(r)||U(e)&&U(r))return e.toString()===r.toString();if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return false;let t=Array.from(r),n=new Set;for(let o of e){let f=false;for(let i=0;i<t.length;i++)if(!n.has(i)&&Z(o,t[i])){n.add(i),f=true;break}if(!f)return false}return true}if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return false;let t=Array.from(r),n=new Set;for(let[o,f]of e){let i=false;for(let s=0;s<t.length;s++){if(n.has(s))continue;let[a,u]=t[s];if(Z(o,a)&&Z(f,u)){n.add(s),i=true;break}}if(!i)return false}return true}if(l(e)&&l(r))return e.length!==r.length?false:e.every((t,n)=>Z(t,r[n]));if(O(e)&&O(r)&&e&&r){if(l(e)!==l(r))return false;let t=Object.keys(e),n=Object.keys(r);return t.length!==n.length?false:t.every(o=>Z(e[o],r[o]))}return false};var me=e=>{if(c(e))return x(e);if(g(e))return false;if(!e)return true;if(l(e))return j(e)||e.every(me);if(O(e)){let r=Object.keys(e),t=Object.getOwnPropertySymbols(e);return [...r,...t].length===0||[...r,...t].every(n=>me(e[n]))}return false};var X=e=>S(e)||e===false||typeof e=="number"&&Number.isNaN(e)?true:c(e)?x(e):l(e)?e.length===0:m(e)?Object.keys(e).length===0&&Object.getOwnPropertySymbols(e).length===0:false;var ee=e=>e instanceof Error;var D=e=>typeof e=="function";var z=e=>Array.isArray(e)&&e.length>0;var m=e=>typeof e=="object"&&!S(e)&&!l(e);var N=(e,r)=>{if(!c(e))return false;m(r)||(r={});let{trim:t=true}=r;return(t?e.trim():e).length>0};var b=e=>e===null;var w=e=>typeof e>"u";var Dt=e=>{if(!c(e)||x(e))return false;let r;try{r=decodeURIComponent(e);}catch{return false}return !r.startsWith("http://")&&!r.startsWith("https://")?false:new RegExp(/^https?:\/\/(?:localhost(?::\d+)?(?:[\/?#][^\s]*)?|(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(?::\d+)?(?:[\/?#][^\s]*)?)$/).test(r)};var Pt=(e,r,t)=>{if(!c(e)||x(e)||!l(r))return false;if(b(t)||!m(t))throw new TypeError("props 'options' must be `object` type!");let{exactMatch:n=false,flags:o="i"}=t;if(!d(n))throw new TypeError("props 'exactMatch' must be `boolean` type!");if(!c(o))throw new TypeError("props 'flags' must be `string` type!");let f=s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=r.filter(s=>c(s)&&!x(s)).map(f);return i.length===0?false:i.every(s=>{let a=n?`(?<!\\S)${s}(?!\\S)`:s;return new RegExp(a,o.includes("u")?o:o+"u").test(e)})};var Mt=(e,r,t)=>{if(!c(e)||x(e)||!l(r))return false;if(b(t)||!m(t))throw new TypeError("props 'options' must be `object` type!");let{exactMatch:n=false,flags:o="i"}=t||{};if(!d(n))throw new TypeError("props 'exactMath' must be `boolean` type!");if(!c(o))throw new TypeError("props 'flags' must be `string` type!");let f=a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=r.filter(a=>c(a)&&!x(a)).map(f);if(i.length===0)return false;let s=n?`(?<!\\S)(${i.join("|")})(?!\\S)`:`(${i.join("|")})`;return new RegExp(s,o.includes("u")?o:o+"u").test(e)};var O=e=>typeof e=="object"&&!S(e);var de=e=>Object.prototype.toString.call(e)==="[object Arguments]";function Vt(e){return e instanceof ArrayBuffer}function qt(e){return e!=null&&typeof e!="function"&&re(e?.length)}function _t(e){return O(e)&&re(e.length)}var ye=e=>Buffer.isBuffer(e);function Xt(e){return !!e&&typeof e=="object"&&e.nodeType===1&&!ge(e)}function rn(e){if(e==null)return true;let r=typeof e;return r==="boolean"||r==="number"||r==="symbol"?true:r==="function"?Object.keys(e).length===0:typeof e=="string"||Array.isArray(e)||de(e)||be(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ye(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:false}function V(e,r,t,n=new WeakMap){if(e===r||e!==e&&r!==r)return true;if(typeof e!="object"||e===null||typeof r!="object"||r===null)return false;if(n.get(e)===r)return true;n.set(e,r);let o=(s,a,u,p,y)=>{if(t){let T=t(s,a,u,p,y,n);if(T!==void 0)return T}return V(s,a,t,n)};if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(e instanceof RegExp&&r instanceof RegExp)return e.source===r.source&&e.flags===r.flags;if(e instanceof Error&&r instanceof Error)return e.name===r.name&&e.message===r.message;if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){let s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);if(s.length!==a.length)return false;for(let u=0;u<s.length;u++)if(s[u]!==a[u])return false;return true}if(e instanceof ArrayBuffer&&r instanceof ArrayBuffer){if(e.byteLength!==r.byteLength)return false;let s=new Uint8Array(e),a=new Uint8Array(r);for(let u=0;u<s.length;u++)if(s[u]!==a[u])return false;return true}if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return false;for(let[s,a]of e)if(!r.has(s)||!V(a,r.get(s),t,n))return false;return true}if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return false;for(let s of e){let a=false;for(let u of r)if(V(s,u,t,n)){a=true;break}if(!a)return false}return true}if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return false;for(let s=0;s<e.length;s++)if(!o(e[s],r[s],s,e,r))return false;return true}if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(r))return false;let f=Reflect.ownKeys(e),i=Reflect.ownKeys(r);if(f.length!==i.length)return false;for(let s of f){let a=e[s],u=r[s];if(!o(a,u,s,e,r))return false}return true}function P(e,r){return V(e,r,void 0,new WeakMap)}function fn(e,r,t){return V(e,r,t,new WeakMap)}function pe(e){return typeof e=="number"&&Number.isFinite(e)}function M(e){return typeof e=="number"&&Number.isInteger(e)}function re(e){return typeof e=="number"&&e>-1&&Number.isInteger(e)&&e<=Number.MAX_SAFE_INTEGER}function we(e,r){return e===r||e===0&&r===0||Number.isNaN(e)&&Number.isNaN(r)}function te(e,r,t){if(e===r)return true;if(r===null||typeof r!="object")return we(e,r);if(e===null||typeof e!="object")return false;let n=Reflect.ownKeys(r).filter(o=>!(Array.isArray(r)&&o==="length"));for(let o of n){if(!(o in e))return false;let f=e[o],i=r[o],s=t?.(f,i,o,e,r);if(s!==void 0){if(!s)return false;continue}if(O(f)&&O(i)){if(!he(f,i,t))return false}else if(!we(f,i))return false}return true}function gn(e,r){return te(e,r)}function he(e,r,t){return te(e,r,t)}function le(e){return typeof e=="number"?Number.isNaN(e):Object.prototype.toString.call(e)==="[object Number]"&&Number.isNaN(e.valueOf())}var Ae=Function.prototype.toString,Oe=/\{\s*\[native code\]\s*\}/;function En(e){if(typeof e!="function")return false;try{let r=Ae.call(e);return Oe.test(r)}catch{return false}}function S(e){return e==null}function Sn(e){let r=typeof e;return e!=null&&(r=="object"||r=="function")}function ge(e){if(e===null||typeof e!="object")return false;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}function On(e){return typeof e=="number"&&Number.isSafeInteger(e)}function jn(e){return Object.prototype.toString.call(e)==="[object Set]"||e instanceof Set}function be(e){return e!=null&&typeof e=="object"&&Re.has(Object.prototype.toString.call(e))}var Re=new Set(["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]","[object BigInt64Array]","[object BigUint64Array]"]);function Cn(e){return typeof e=="object"&&e!==null&&e instanceof WeakMap}var Un=(e,r)=>{if(!c(e)){let t=typeof e;throw new TypeError(D(r)?r(t):r?.trim()||`Expected value to be 'string',but got '${t}'`)}};var _=()=>typeof window>"u"||typeof document>"u";var Bn=(e="on_processing")=>{if(_())return;if(!c(e))throw new TypeError("Expected 'className' to be a 'string' type");let{documentElement:r}=document;r&&!r.classList.contains(e)&&r.classList.add(e);},Vn=(e="on_processing")=>{if(_())return;if(!c(e))throw new TypeError("Expected 'className' to be a 'string' type");let{documentElement:r}=document;r&&r.classList.contains(e)&&r.classList.remove(e);},Kn=()=>{if(_())return;let e=document.activeElement;e instanceof HTMLElement?e.blur():console.warn("removeElementFocus:No active element to blur or is not supported on null element.");},Wn=e=>{if(_())return;m(e)||(e={});let{behavior:r="smooth",timeout:t=1}=e;setTimeout(()=>{window.scrollTo({top:0,left:0,behavior:r});},t<1?1:t);};var Zn=(e,r={})=>{if(!c(e)&&!g(e))throw new TypeError("props 'value' must be `string` or `number` type!");if(!m(r))throw new TypeError("props 'options' must be `object` type!");let{decimal:t=false,totalDecimal:n=2,endDecimal:o=true,indianFormat:f=false,suffixCurrency:i="",suffixDecimal:s="",roundedDecimal:a="round",negativeFormat:u="dash"}=r,{separatorDecimals:p=",",separator:y="."}=r;if(!c(y)||!c(p)||!c(i)||!c(s))throw new TypeError("props 'separator','separatorDecimals','suffixCurrency' and 'suffixDecimal' must be `string` type!");if(!d(t)||!d(o)||!d(f))throw new TypeError("props 'decimal','endDecimal' and 'indianFormat' must be `boolean` type!");if(!g(n))throw new TypeError("props 'totalDecimal' must be `number` type!");if(!(a===false||a==="round"||a==="ceil"||a==="floor"))throw new TypeError("props 'roundedDecimal' must be `false` or one of:'round' | 'ceil' | 'floor'");if(!(u==="abs"||u==="brackets"||u==="dash"||m(u)))throw new TypeError("props 'negativeFormat' must be on one of:'abs' | 'brackets' | 'dash' or `object`");let T=c(e)?Q(e):e;if(isNaN(T))throw new TypeError("'value' could not be parsed into a valid number");let k=Math.abs(T),E=Math.pow(10,n);if(a){let h=k*E;switch(a){case "round":k=Math.round(h)/E;break;case "ceil":k=Math.ceil(h)/E;break;case "floor":k=Math.floor(h)/E;break}}let R="",I="";if(a){let h=k*E;switch(a){case "round":k=Math.round(h)/E;break;case "ceil":k=Math.ceil(h)/E;break;case "floor":k=Math.floor(h)/E;break}}if(a)[R,I]=k.toFixed(n).split("."),I=I??"".padEnd(n,"0");else{let h=String(k).split(".");R=h[0],I=(h[1]||"").slice(0,n).padEnd(n,"0");}let A,F=(h,C)=>{let K=h.slice(-3),ae=h.slice(0,-3);return ae?ae.replace(/\B(?=(\d{2})+(?!\d))/g,C)+C+K:K};if(f?(y=",",p=".",A=(i.trim().length?i:"")+F(R,y)):A=(i.trim().length?i:"")+R.replace(/\B(?=(\d{3})+(?!\d))/g,y),t&&!w(I)&&n>0){let h=p+I;o&&(h+=s),A+=h;}if(T<0){if(u==="dash")A="-"+A;else if(u==="brackets")A="("+A+")";else if(u!=="abs"){if(m(u))if("custom"in u){let h=u.custom;if(!D(h))throw new TypeError("props 'negativeFormat.custom' must be a function:'(formatted:string)=>string'");let C=h(A);if(!c(C))throw new TypeError("props 'negativeFormat.custom' must return a string");A=C;}else{let h=u.style||"dash",C=d(u.space)?u.space:false;if(!d(C))throw new TypeError("props 'negativeFormat.space' must be boolean");if(!(h==="abs"||h==="brackets"||h==="dash"))throw new TypeError("props 'negativeFormat.style' must be one of:'dash' | 'brackets' | 'abs'");switch(h){case "dash":A="-"+(C?" ":"")+A;break;case "brackets":A=C?`(${A})`:`(${A})`;break;}}}}return A};var Gn=(e,r=",")=>{if(!c(e)&&!g(e))throw new TypeError("props 'value' must be 'string' or 'number' type!");if(!c(r))throw new TypeError("props 'separator' must be 'string' or empty as 'undefined' type!");r=c(r)?r:",";let t=r==="."?",":".",n=e.toString().trim(),o=n.lastIndexOf("."),f=n.lastIndexOf(","),i="";o>f?i=".":f>o&&(i=",");let s=n,a="";if(i){let p=n.split(i);s=p.slice(0,-1).join(i),a=p.slice(-1)[0];}s=s.replace(/[^\d]/g,"");let u=s.replace(/\B(?=(\d{3})+(?!\d))/g,r);return a?`${u}${t}${a}`:u};function Qn(e,r={}){if(S(e))return "";if(!c(e)&&!g(e))throw new TypeError("props 'value' must be `string`,`number`,`null` or `undefined` type!");if(!m(r))throw new TypeError("props 'options' must be `object` or unset type!");let{separator:t=" ",takeNumberOnly:n=false,checkValidOnly:o=false,plusNumberCountry:f="",openingNumberCountry:i="",closingNumberCountry:s=""}=r;if(!d(n)||!d(o))throw new TypeError("props 'takeNumberOnly' and 'checkValidOnly' must be `boolean` or unset as `undefined` type!");if(!c(t)||!c(f)||!c(i)||!c(s))throw new TypeError("props 'separator','plusNumberCountry','openingNumberCountry' and 'closingNumberCountry' must be `string` or unset type!");if(c(e)||(e=String(e)),n)return e.replace(/\D/g,"");if(o)return /^(\+)?[0-9\s().-]+$/.test(e)&&e.replace(/\D/g,"").length<24;e=e.replace(/\D/g,"");let a=f.trim().replace(/\s+/g,"").replace(/[^\d+]/g,"");/^\+/.test(a)&&(a="+"+a.replace(/^\++/,""));let u="",p="",y={7:"Russia,Kazakhstan",27:"South Africa",31:"Netherlands",32:"Belgium",33:"France",34:"Spain",36:"Hungary",39:"Italy,San Marino,Vatican",44:"United Kingdom",46:"Sweden",47:"Norway",48:"Poland",49:"Germany",52:"Mexico",54:"Argentina",55:"Brazil",56:"Chile",61:"Australia",62:"Indonesia",64:"New Zealand",81:"Japan",82:"South Korea",86:"China",90:"Turkey",91:"India",92:"Pakistan",351:"Portugal",352:"Luxembourg",971:"UAE"},T=a.replace(/^\+/,"").replace(/[^\d]/g,"");y[T]&&e.startsWith("0")?(u=e.slice(1,4),p=e.slice(4)):(u=e.slice(0,4),p=e.slice(4));let k=a.trim(),E=i.trim(),R=s.trim(),I="";k?E&&R?I=`${E}${k}${R}${u}`:E&&!R?I=`${E}${k}${u}`:!E&&R?I=`${k}${R}${u}`:I=`${k}${u}`:I=`${u}`;let A={0:t,4:t,8:t,12:t,16:t,20:t,24:t};for(let F=0;F<p.length;F++){let h=F+u.length;I+=(A[h]||"")+p[F];}return I}var oo=(e,r="YYYY-MM-DD hh:mm:ss")=>{if(!c(r)||!e||!(v(e)||c(e)))return null;try{let t=new Date(e);if(isNaN(t.getTime()))return null;let n=i=>i.toString().padStart(2,"0"),o={YYYY:t.getFullYear().toString(),MM:n(t.getMonth()+1),DD:n(t.getDate()),hh:n(t.getHours()),mm:n(t.getMinutes()),ss:n(t.getSeconds())},f=Object.entries(o).reduce((i,[s,a])=>i.split(s).join(a),r);return f.includes("NaN")?null:f}catch{return null}},io=(e,r)=>{if(!e||!(v(e)||c(e)))return null;let t=new Date(e);if(isNaN(t.getTime()))return null;m(r)||(r={});let{locale:n="en-US",...o}=r;return new Intl.DateTimeFormat(n?.toString()?.trim()?.length?n:"en-US",o).format(t)},so=(e,r)=>{if(!e||!(v(e)||c(e)))return null;m(r)||(r={});let{format:t="dd MMM yyyy - HH:mm:ss",inputFormat:n,locale:o,inputLocale:f,...i}=r,s;if(c(e)&&n&&f){let u=c(f)?f==="id"?id:enUS:f;try{s=parse(e,n,new Date,{locale:u});}catch{return null}}else s=new Date(e);if(isNaN(s.getTime()))return null;let a=c(o)?o==="id"?id:enUS:o;return format(s,t,{...i,locale:a})},ao=e=>{try{if(!e||c(e)&&x(e))e=new Date;else if(!(v(e)||c(e)))return "0";let r=new Date(e);if(isNaN(r.getTime()))return "0";let t=f=>f.toString().padStart(2,"0"),n=r.getTimezoneOffset(),o=n<0?"+":"-";return n=Math.abs(n),`${o}${t(Math.floor(n/60))}${t(n%60)}`}catch{return "0"}};var uo=(e,r="random")=>{if(!c(e))return "";if(r!=="random"&&r!=="fixed")throw new TypeError("Expected 'mode' to be a 'string' and the valid value is 'random' and 'fixed' only!");if(!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e))return "";let[n,o]=e.split("@"),f=o.split(".");if(f.length<2)return "";let[i,...s]=f,a=s.join("."),u=r==="fixed"?(()=>{let E=0;for(let R=0;R<e.length;R++)E=(E<<5)-E+e.charCodeAt(R),E|=0;return Math.abs(E)})():void 0,p=(E,R,I)=>{if(E.length<=R)return "*".repeat(E.length);let A=E.split(""),F=Math.max(R,Math.ceil(E.length*I)),h=new Set,C=0;for(;h.size<F;){let K=w(u)?Math.floor(Math.random()*E.length):(u+E.length+C*31)%E.length;h.add(K),C++;}for(let K of h)A[K]="*";return A.join("")},y=p(n,n.length<4?1:2,.6),T=p(i,i.length<4?1:2,.5),k=a.length<=2?a:p(a,1,.4);return `${y}@${T}.${k}`};function mo(e,r,t=" ",n=false){if(w(e)||b(e)||r<=0)return e;if(!(c(e)&&g(r)&&c(t)&&d(n)))throw new TypeError("Expected 'subject' and 'separator' to be a 'string' type,'limiter' to be a 'number' type,'reCountAfterSpace' to be a 'boolean' type");if(e=Te(e),!n){let a="",u=0;for(let p=0;p<e.length;p++){let y=e[p];u===r&&(a+=t,u=0),a+=y,u++;}return a}let o=e.split(" "),f=[],i=[],s=0;for(let a=0;a<o.length;a++){let u=o[a],p="",y=0;for(let T=0;T<u.length;T++)p+=u[T],y++,y===r&&T<u.length-1&&(p+=t,y=0);i.push(p),s++,(s===r||a===o.length-1)&&(f.push(i.join(t)),i=[],s=0);}return f.join(" ")}var bo=(e,r=10,t="...",n=true)=>{if(!N(e)||r<1)return "";if(!(g(r)&&c(t)&&d(n)))throw new TypeError("Expected 'ending' to be a 'string' type,'length' to be a 'number' type,'trim' to be a 'boolean' type");x(t)?t="...":t=t.trim();let o=n?e.trim():e;if(o.length<=r)return o;let i=o.slice(0,r);return(n?i:i.trimEnd())+t};var xo=e=>{if(!z(e))return;let r=Math.floor(Math.random()*(e.length||0));return e[r]};var J=(e,r)=>{if(!M(e)||!M(r))throw new Error("Error function of `getRandomIntInRange` both parameter `min` and `max` must be integers.");if(e>r)throw new Error("Error function of `getRandomIntInRange` parameter `min` must be less than or equal to `max`.");return e=Math.max(1,e),r=Math.min(Number.MAX_SAFE_INTEGER,r),Math.floor(Math.random()*(r-e+1))+e};var Ao=e=>{m(e)||(e={});let{minLength:r=1,maxLength:t=16,avoidZero:n=false}=e;if(!M(r)||!M(t)||r<1||t>16||r>t)throw new Error("Invalid parameters:minLength must be \u2265 1,maxLength must be \u2264 16,and minLength \u2264 maxLength.");let o=r===t?r:J(r,t),f=10**(o-1),i=10**o-1,s=J(f,i);return n&&s===0&&(s=f),s};var Io=e=>{m(e)||(e={});let{minLength:r=40,maxLength:t=40,type:n="string",avoidWhiteSpace:o=true}=e;if(!d(o))throw new Error("Invalid parameter:`avoidWhiteSpace` must be 'boolean'.");if(!M(r)||!M(t)||r<1||t>5e3||r>t)throw new Error("Invalid parameters:`minLength` must be \u2265 1,`maxLength` must be \u2264 5000,and `minLength` \u2264 `maxLength`.");if(n!=="string"&&n!=="number")throw new Error("Invalid parameter:`type` must be either 'string' or 'number'.");let f=J(r,t),i=T=>o?T.replace(/\s|\n|\t/g,""):T,u=n==="number"?e.replaceGenInt??"0123456789":e.replaceGenStr??"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",p=i(u)+(e.addChar||"");if(!p.length)throw new Error("Character set is empty. Ensure `replaceGenInt` or `replaceGenStr` has valid characters.");let y="";for(let T=0;T<f;T++)y+=p.charAt(Math.floor(Math.random()*p.length));return y};var Co=()=>{};var W=e=>{if(!l(e))throw new TypeError("Expected 'values' to be a 'array' type");let r=[];return e.forEach((t,n)=>{for(let o=n+1;o<e.length;o++)if(P(t,e[o])){r.some(f=>P(f,t))||r.push(t);break}}),r};var Mo=(e,r)=>{if(!e||typeof e!="object")return{};if(!l(r))throw new TypeError("Expected 'keysToOmit' to be a 'array' type");let t=W(r);if(t.length>0)throw new Error(`Function "omitKeys" Error:Duplicate keys detected - ${t}`);return Object.fromEntries(Object.entries(e).filter(([n])=>!r.includes(n)))};var zo=(e,r)=>{if(!m(e))return{};if(!l(r))throw new TypeError("Expected 'keysToOmit' to be a 'array' type");let t=W(r);if(z(t))throw new Error(`Function "omitKeysDeep" Error:Duplicate keys detected - ${t}`);let n=(i,s)=>{if(!i||typeof i!="object")return i;let[a,...u]=s;if(j(u))if(l(i)){let p=parseInt(a);!isNaN(p)&&p in i&&i.splice(p,1);}else delete i[a];else{let p=i[a];(l(p)||typeof p=="object"&&!b(p))&&(i[a]=n(p,u));}return i},o=i=>l(i)?i.map(o).filter(s=>!(typeof s=="object"&&!b(s)&&Object.keys(s).length===0)):i&&typeof i=="object"?Object.fromEntries(Object.entries(i).map(([a,u])=>[a,o(u)]).filter(([,a])=>!w(a)&&!(typeof a=="object"&&!b(a)&&Object.keys(a).length===0))):i,f=JSON.parse(JSON.stringify(e));for(let i of r){let s=i.split(".");n(f,s);}return o(f)};var Ko=(e,r)=>{if(!l(r))throw new TypeError("Expected 'arrayExcept' to be a 'array' type");let t=W(r);if(z(t))throw new Error(`Function omitProps Error,cause Duplicate of arrayExcept:${String(t)}`);if(e){let n=Object.entries(e).filter(([o])=>!r.includes(o));return Object.fromEntries(n)}};var De=new Set(["txt","md","rtf","tex","doc","docx","odt","ott","pdf","djvu","epub","mobi","azw","azw3","xls","xlsx","ods","csv","tsv","ppt","pptx","odp","pps","md","bib","tex","log","jpg","jpeg","png","gif","bmp","tif","tiff","webp","svg","ico","heif","heic","raw","cr2","nef","orf","sr2","dng","dds","psd","exr","xcf","ai","eps","cdr","psd","indd","mp3","wav","ogg","flac","aac","m4a","wma","alac","aiff","amr","mid","midi","opus","au","caf","ape","opus","mp4","mkv","avi","mov","flv","wmv","webm","mpeg","mpg","3gp","3g2","m4v","ts","mts","asf","rm","rmvb","vob","f4v","ogv","m2ts","mod","dav","zip","rar","7z","tar","gz","bz2","xz","tgz","tbz2","txz","lz","lzma","z","cab","arj","ace","iso","dmg","rpm","deb","pkg","apk","jar","iso","img","vhd","vmdk","qcow2","dmg","sql","db","dbf","mdb","accdb","json","xml","yaml","yml","toml","ini","plist","yaml","pkl","msgpack","h5","hdf5","parquet","avro","orc","ndjson","db","pdb","sqlite","sqlite3","dbx","sdf","js","jsx","ts","tsx","c","cpp","h","hpp","java","py","rb","go","rs","php","pl","sh","bat","cmd","ps1","lua","swift","kt","scala","cs","vb","dart","m","r","jl","fs","vbproj","sln","pri","Makefile","html","htm","xhtml","css","scss","sass","less","xml","json","yaml","yml","xlf","xlf","po","pot","jsp","asp","aspx","php","jspf","cgi","cfm","pl","env","conf","config","xml","ini","cfg","toml","yaml","dockerfile","gitignore","gitconfig","gitattributes","npmignore","lock","gradle","pom","yaml","prettierrc","eslintrc","babelrc","editorconfig","ttf","otf","woff","woff2","eot","dwg","dxf","shp","kml","kmz","gpx","stl","step","iges","3ds","3dm","fbx","obj","exe","msi","bin","run","com","cmd","apk","app","deb","rpm","elf","dll","so","dylib","sys","pem","crt","cer","key","der","csr","p12","pfx","jks","iso","cue","bin","nes","sfc","gba","nds","nes","sav","rom","pak","vpk","bik","epub","mobi","azw","azw3","fb2","lit","lrf","cbr","cbz","cbt","cba","opds","fasta","fa","fas","ffn","faa","fna","frn","fastq","fq","gb","gbk","sam","bam","vcf","gff","bed","log","bak","tmp","old","backup","swp","part","crdownload","torrent","ics","vcf","ics","ical","ics","ical","calendar","srt","sub","idx","cue","cdf","hdf","h5","nc","grib","fits","netcdf","sdf","vtk","xmind","drawio","jar","war","ear","crx","xpi","plugin","vsix","safariextz"]),Ce=new Set(["tar.gz","tar.bz2","tar.xz","tar.lz","tar.lzma","tar.Z","tar.zst","tar.xz"]),Yo=e=>{if(x(e))return;let r=e.split("/").pop();if(r==="")return "";if(r){for(let t of Ce){let n=`.${t}`;if(r.toLowerCase().endsWith(n))return r.slice(0,-n.length)}for(;;){let t=r.lastIndexOf(".");if(t===-1)break;let n=r.slice(t+1).toLowerCase();if(De.has(n))r=r.slice(0,t);else break}return r}};var Jo=(e=1e3,r)=>{if(!g(e)||!Number.isFinite(e)||e<=0)throw new TypeError("`milliSeconds` must be a number,non-zero,non-NaN,non-negative,and non finite number.");if(b(r)||r&&!(r instanceof AbortSignal))throw new TypeError("`signal` must be an instance of AbortSignal if provided.");return new Promise((t,n)=>{let o=setTimeout(()=>{f(),t();},e),f=()=>{clearTimeout(o),r&&r.removeEventListener("abort",i);},i=()=>{f(),n(new DOMException("Delay aborted","AbortError"));};r&&(r.aborted?i():r.addEventListener("abort",i,{once:true}));})};var Xo=(e,r={lowerCaseNextRest:true,trim:false})=>{if(!N(e))return "";m(r)||(r={});let t=r.lowerCaseNextRest!==false;return r.trim===true&&(e=e.trim()),e[0].toUpperCase()+(t?e.slice(1).toLowerCase():e.slice(1))},Qo=(e,r={collapseSpaces:false,trim:false})=>{if(!N(e))return "";let t=e;m(r)||(r={});let n=r.collapseSpaces===true;if(r.trim===true&&(t=t.trim()),n){let f=t.match(/^\s*/)?.[0]??"",i=t.match(/\s*$/)?.[0]??"";t=t.trim().replace(/\s+/g," "),t=`${f}${t}${i}`;}return t.toLowerCase().split(" ").map(f=>f.charAt(0).toUpperCase()+f.slice(1)).join(" ")},ei=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((r,t)=>t===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(""):"",ri=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(""):"",ti=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(r=>r.toLowerCase()).join("-"):"",ni=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(r=>r.toLowerCase()).join("_"):"",oi=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(r=>r.toLowerCase()).join("."):"",ii=e=>N(e)?e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(r=>r.toLowerCase()).join("-").replace(/^-+|-+$/g,""):"";var Te=(e,r={withTrim:true,trimOnly:false})=>{if(!N(e))return "";m(r)||(r={});let{trimOnly:t=false,withTrim:n=true}=r;return t?e.trim():(n&&(e=e.trim()),e.replace(/\s+/g," "))},fi=e=>N(e)?e.trim():"",ne=(e,r={trimOnly:false})=>{if(!N(e))return "";m(r)||(r={});let{trimOnly:t=false}=r;return t?e.trim():e.replace(/\s+/g,"")},ci=e=>c(e)?x(e)?"":e.replace(/<\/?[a-zA-Z][^<>]*\/?>/g," ").trim().replace(/\s+/g," ").trim():void 0;var pi=(e,r,t)=>{if(!g(e)||!c(t)||!c(r))throw new TypeError("Expected 'index' to be a 'number' type,'replaceTo' and 'originalString' to be a 'string' type");if(e<0||e>=r.length)throw new Error("Index parameter is out of range at function `replaceAt`");return r.slice(0,e)+t+r.slice(e+1)},mi=e=>{if(!N(e))return "";e=e.replace(/\s+/g," ").trim();let r=e.split(" ");return r.length>1?r[0][0]+r[1][0].toUpperCase():e.length>1?e.substring(0,2).toUpperCase():e[0].toUpperCase()};var gi=e=>{if(!l(e))throw new Error("Invalid argument:`props` must be an array from function `shouldForwardProp`.");return r=>!e.map(t=>t.toString()).includes(r.toString())};var hi=(e,r,t)=>{if(c(e)){if(x(e))throw new TypeError("`baseUrl` cannot be an empty string.");e=ne(e,{trimOnly:true});}else if(!$(e))throw new TypeError(`Invalid 'baseUrl'. Expected a non-empty string or a URL instance,received:${typeof e}`);if(!w(t)){if(!l(t))throw new TypeError("`removeParams` must be an array of strings.");if(!t.every(n=>c(n)))throw new TypeError("`removeParams` must only contain strings.")}try{if(!w(r)&&!D(r[Symbol.iterator]))throw new TypeError("`queryParams` must be iterable(like URLSearchParams.entries()or an array of [string,string])");let n=new URL(e);if(!w(r)){let o=Object.fromEntries(r);if(!X(o)){let f=new URLSearchParams(n.search);for(let[i,s]of Object.entries(o))f.set(i,s);t?.length&&ce(t)?.map(i=>{f.delete(i);}),n.search=f.toString();}}return t?.forEach(o=>n.searchParams.delete(o)),n}catch(n){throw new Error("Failed to construct a valid URL in `constructURL()`,Error:"+n)}};var Ti=(e,r=null,t={levels:1,removeDuplicates:true})=>{let n=[];!c(e)&&!l(e)&&n.push(`'url' must be a string or an array of strings. Received:${typeof e}`),!c(r)&&!l(r)&&!b(r)&&n.push(`'base' must be a string,array of strings,or null. Received:${typeof r}`),m(t)||n.push(`'options' must be a object. Received:${typeof t}`);let{levels:o=1,removeDuplicates:f=true}=t;if(g(o)||n.push(`'levels' must be a number. Received:${typeof o}`),d(f)||n.push(`'removeDuplicates' must be a boolean. Received:${typeof f}`),z(n))throw new TypeError(`Invalid parameter(s)in getPrefixPathname:- ${n.join(`- `)}`);function i(s){if(r){if(s=L(s),l(r)){for(let u of r)if(s.startsWith(L(u)))return L(u)}else if(s.startsWith(L(r)))return L(r);return null}return `/${s.split("/").filter(Boolean).slice(0,o).join("/")}`}if(l(e)){let s=e.map(i).filter(u=>!b(u)),a=f?[...new Set(s)]:s;return a.length===1?a[0]:a}return i(e)},Ni=(e,r="/")=>{if(!N(r))throw new TypeError(`Invalid parameter:'defaultValue' must be a string and string is non-empty string. Received:${typeof r}(${r})`);if(l(e)){if(!e.every(t=>c(t)))throw new TypeError(`Invalid parameter:'result' array must only contain strings. Received:${JSON.stringify(e)}`);for(let t of e){let n=L(t);if(n!=="/")return n}return L(r)}if(c(e)){let t=L(e);return t!=="/"?t:L(r)}if(!b(e))throw new TypeError(`Invalid parameter:'result' must be a string,array of strings,or null. Received:${JSON.stringify(e)}`);return L(r)},L=(e,r="/")=>{if(!N(r))throw new TypeError(`Invalid parameter:'defaultPath' must be a string and string is non-empty string. Received:${typeof r}(${r})`);if(!N(e))return r;try{if(e=ne(e,{trimOnly:!0}),e=e.replace(/\s+/g,""),e.startsWith("http://")||e.startsWith("https://")){let t=new URL(e);return `${t.pathname}${t.search}${t.hash}`.replace(/^\/+/,"/")}return "/"+e.replace(/^\/+/,"").replace(/\/{2,}/g,"/")}catch(t){let n=ee(t)?t:new Error("Unknown error from function `normalizePathname()`");throw new oe(`Failed to normalize pathname in function \`normalizePathname()\`:${n.message}`,n)}};var Ai=(e,r)=>{if(!N(e))return "";if(!w(r)){if(!m(r))throw new TypeError("Options must be an object.");if("prefixColon"in r&&!d(r.prefixColon))throw new TypeError("Option `prefixColon` must be a boolean.")}let t=e.replace(/\D+/g,"");return t?r?.prefixColon??false?`:${t}`:t:""};var oe=class e extends Error{constructor(t,n){super(t);this.originalError=n;this.name="NormalizePathnameError",Error.captureStackTrace&&Error.captureStackTrace(this,e);}};export{oe as NormalizePathnameError,Pe as areArraysEqual,Me as areObjectsEqual,Be as areURLsEqualPath,We as areURLsIdentical,He as arrayHasAnyMatch,Un as assertIsString,Xo as capitalizeFirst,Qo as capitalizeWords,uo as censorEmail,mo as chunkString,ie as cleanParsedData,hi as constructURL,Fr as convertType,hr as dedupeArray,Jo as delay,Bn as disableUserInteraction,fe as doesKeyExist,Vn as enableUserInteraction,vr as extractDigits,Yo as extractFileName,lr as extractURLs,H as filterNullArray,W as findDuplicates,Zn as formatCurrency,so as formatDateFns,io as formatDateIntl,oo as formatDateTime,Ai as formatEnvPort,Gn as formatNumber,Qn as formatPhoneNumber,Ni as getFirstPrefixPathname,ao as getGMTOffset,mi as getInitialsName,Ti as getPrefixPathname,xo as getRandomItem,de as isArguments,l as isArray,Vt as isArrayBuffer,qt as isArrayLike,_t as isArrayLikeObject,G as isBigInt,d as isBoolean,ye as isBuffer,it as isCurrencyLike,v as isDate,Z as isDeepEqual,Xt as isElement,rn as isEmpty,j as isEmptyArray,me as isEmptyDeep,x as isEmptyString,X as isEmptyValue,P as isEqual,fn as isEqualWith,ee as isError,pe as isFinite,D as isFunction,M as isInteger,re as isLength,gn as isMatch,he as isMatchWith,le as isNaN,En as isNative,S as isNil,z as isNonEmptyArray,N as isNonEmptyString,b as isNull,g as isNumber,m as isObject,Sn as isObjectLoose,O as isObjectOrArray,ge as isPlainObject,Y as isRegExp,On as isSafeInteger,_ as isServer,jn as isSet,c as isString,U as isSymbol,be as isTypedArray,$ as isURL,w as isUndefined,Dt as isValidURL,Cn as isWeakMap,Co as noop,L as normalizePathname,Te as normalizeSpaces,fi as normalizeString,Mo as omitKeys,zo as omitKeysDeep,Ko as omitProps,Q as parseCurrencyString,Ne as parseCustomDate,J as randomInt,Ao as randomIntByLength,Io as randomStr,Kn as removeElementFocus,Wr as removeObjectPaths,ne as removeSpaces,pi as replaceAt,Br as safeJsonParse,q as safeStableStringify,Wn as scrollToTop,gi as shouldForwardProp,ii as slugify,ci as stripHtmlTags,Pt as textContainsAll,Mt as textContainsAny,Tr as toBooleanContent,ue as toBooleanContentDeep,Or as toBooleanExplicit,Ir as toBooleanLoose,ei as toCamelCase,oi as toDotCase,ti as toKebabCase,gr as toNumberArrayUnRecursive,Hr as toNumberDeep,ri as toPascalCase,ni as toSnakeCase,ce as toStringArrayUnRecursive,et as toStringDeep,B as toStringDeepForce,bo as truncateString};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var w=r=>Array.isArray(r);var o=r=>typeof r=="string";var x=(r,e)=>{if(!o(r))return true;s(e)||(e={});let{trim:n=true}=e;return n&&(r=r.trim()),r===""};var d=r=>typeof r=="boolean";var T=r=>r instanceof Error;var $=r=>Array.isArray(r)&&r.length>0;var s=r=>typeof r=="object"&&!v(r)&&!w(r);var p=(r,e)=>{if(!o(r))return false;s(e)||(e={});let{trim:n=true}=e;return(n?r.trim():r).length>0};var g=r=>typeof r>"u";function v(r){return r==null}var c=(r,e={trimOnly:false})=>{if(!p(r))return "";s(e)||(e={});let{trimOnly:n=false}=e;return n?r.trim():r.replace(/\s+/g,"")};var E=(r,e="/")=>{if(!p(e))throw new TypeError(`Invalid parameter:'defaultPath' must be a string and string is non-empty string. Received:${typeof e}(${e})`);if(!p(r))return e;try{if(r=c(r,{trimOnly:!0}),r=r.replace(/\s+/g,""),r.startsWith("http://")||r.startsWith("https://")){let n=new URL(r);return `${n.pathname}${n.search}${n.hash}`.replace(/^\/+/,"/")}return "/"+r.replace(/^\/+/,"").replace(/\/{2,}/g,"/")}catch(n){let t=T(n)?n:new Error("Unknown error from function `normalizePathname()`");throw new h(`Failed to normalize pathname in function \`normalizePathname()\`:${t.message}`,t)}};var y=(r,e)=>{if(!p(r))return "";if(!g(e)){if(!s(e))throw new TypeError("Options must be an object.");if("prefixColon"in e&&!d(e.prefixColon))throw new TypeError("Option `prefixColon` must be a boolean.")}let n=r.replace(/\D+/g,"");return n?e?.prefixColon??false?`:${n}`:n:""};var h=class r extends Error{constructor(n,t){super(n);this.originalError=t;this.name="NormalizePathnameError",Error.captureStackTrace&&Error.captureStackTrace(this,r);}};function G(r,e){if(!o(r)||x(r))throw new TypeError(`\u{1F6A8}'generateRoute' Failed:- Invalid 'route' value.- Expected a non-empty string,but received ${typeof r}:${JSON.stringify(r)}`);if(!r.includes("["))return r;if(!s(e))throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":- Missing or invalid parameters object for route:"${r}",expected an object mapping parameters.`);if(!e)throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":- Missing parameters object for route:"${r}"`);let n=["?","&","#","=","/"," ","'",'"',"(",")","+",";","%","@",":"],t=[],i=Array.from(r.matchAll(/\[(\w+)\]/g)).map(a=>a[1]);for(let a of i){let l=e[a];if(g(l)){t.push(`- Missing parameter:"${a}".`);continue}let f=l.trim();if(!f){t.push(`- Parameter "${a}" cannot be empty.`);continue}f.includes("/")&&t.push(`- Parameter "${a}" contains slashes "/" which is not allowed.`);let u=n.filter(m=>m!=="/").filter(m=>f.includes(m));u.length>0&&t.push(`- Parameter "${a}" contains invalid characters(${u.length>1?u.join(","):u}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters:(${n.join(",")}).`);}if($(t))throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":${t.join(``)}`);return r.replace(/\[(\w+)\]/g,(a,l)=>e[l].trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")}var rr=(r="",e)=>{try{let f=function(m,P){return `${m.replace(/\/+$/,"")}/${P.replace(/^\/+/,"")}`};var n=f;if(!o(r))throw new TypeError(`Invalid type for 'pathname'. Expected 'string',received:${typeof r}`);s(e)||(e={});let{prefix:t="/api",withOrigin:i=!0}=e;if(!g(t)&&!o(t))throw new TypeError(`Invalid type for 'prefix'. Expected 'string',received:${typeof t}`);if(!d(i))throw new TypeError(`Invalid type for 'withOrigin'. Expected 'boolean',received:${typeof i}`);r=E(r),t=E(t);let a=t.endsWith("/")?t:t+"/";(r===t||r===t+"/"||r.startsWith(a))&&(r=r.slice(t.length),r=E(r));let l=b({suffix:t});return f(i?l:new URL(l).pathname,r).replace(/\/+$/,"")}catch(t){throw new Error("Failed to generate backend API URL in `createBeApiUrl()`,Error:"+t)}};var b=({suffix:r="/"}={})=>{if(!o(r))throw new TypeError(`Invalid type for 'suffix'. Expected string,received:${typeof r}`);try{let e=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(e){e=c(e);let i=new URL(e);!!!i.port&&process.env.NEXT_PUBLIC_PORT_BE&&(e=i.origin+y(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}));}else e="http://localhost"+y(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});r=c(r).length?c(r):"/";let n=new URL(e.replace(/\/+$/,"")).origin,t=r==="/"?"/":`${r.startsWith("/")?"":"/"}${r.replace(/\/+$/,"")}`;return `${n}${t}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`,failed to generate from `getBeApiUrl()`,Error:"+e)}};var or=()=>{try{let r=process.env.NEXT_PUBLIC_BASE_URL?.trim(),e=process.env.NEXT_PUBLIC_PORT_FE?.trim(),n=r||"http://localhost";n=c(n).replace(/\/+$/,"");let t=/:\/\/[^/]+:\d+/.test(n);!t&&e?n+=y(e,{prefixColon:!0}):!t&&!r&&(n+=":3000");let i=new URL(n);return `${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`}catch(r){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`,failed to generate from `getBaseUrl()`,Error:"+r)}};exports.createBeApiUrl=rr;exports.generateRoute=G;exports.getBaseUrl=or;exports.getBeApiUrl=b;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
|
|
2
|
+
/** Extracts dynamic route parameters from a given route string.
|
|
3
|
+
*
|
|
4
|
+
* This utility type recursively searches for dynamic segments within a route,
|
|
5
|
+
* extracting each parameter and constructing an object where each key represents
|
|
6
|
+
* a dynamic segment and its value is of type `string`.
|
|
7
|
+
*
|
|
8
|
+
* * ⚠️ ***Notes: This Type only support when using `NextJS`***
|
|
9
|
+
*
|
|
10
|
+
* @template T - The route string containing potential dynamic segments.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* type Params1 = ExtractRouteParams<"/user/[id]">;
|
|
15
|
+
* // Result: { id: string }
|
|
16
|
+
*
|
|
17
|
+
* type Params2 = ExtractRouteParams<"/post/[slug]/comment/[commentId]">;
|
|
18
|
+
* // Result: { slug: string; commentId: string }
|
|
19
|
+
*
|
|
20
|
+
* type Params3 = ExtractRouteParams<"/dashboard">;
|
|
21
|
+
* // Result: {} (no dynamic parameters)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
type ExtractRouteParams<T extends string>=T extends `${infer _Start}[${infer Param}]${infer Rest}` ?{[K in Param]:string;}& ExtractRouteParams<Rest>:Record<any,any>;
|
|
25
|
+
/** Determines whether a given route contains dynamic segments.
|
|
26
|
+
*
|
|
27
|
+
* This type checks if the route includes at least one `[param]` pattern.
|
|
28
|
+
* If it does, the result is `true`, otherwise `false`.
|
|
29
|
+
*
|
|
30
|
+
* * ⚠️ ***Notes: This Type only support when using `NextJS`***
|
|
31
|
+
*
|
|
32
|
+
* @template T - The route string to be evaluated.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* type HasParams1 = HasDynamicSegments<"/user/[id]">;
|
|
37
|
+
* // Result: true
|
|
38
|
+
*
|
|
39
|
+
* type HasParams2 = HasDynamicSegments<"/settings/profile">;
|
|
40
|
+
* // Result: false
|
|
41
|
+
*
|
|
42
|
+
* type HasParams3 = HasDynamicSegments<"/blog/[category]/[slug]">;
|
|
43
|
+
* // Result: true
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
type HasDynamicSegments<T extends string>=T extends `${string}[${string}]${string}` ? true:false;
|
|
47
|
+
/** ---------------------------------
|
|
48
|
+
* * ***Generates a URL by replacing dynamic route parameters with provided values.***
|
|
49
|
+
* ---------------------------------
|
|
50
|
+
*
|
|
51
|
+
* * ⚠️ ***Notes: This Function only support when using `NextJS`***
|
|
52
|
+
*
|
|
53
|
+
* @template T - The route string containing dynamic segments in the format `[param]`.
|
|
54
|
+
*
|
|
55
|
+
* @param {T} route - The route string containing dynamic segments.
|
|
56
|
+
* @param {ExtractRouteParams<T>} [params] - An object containing key-value pairs that match the dynamic segments in the route.
|
|
57
|
+
*
|
|
58
|
+
* @returns {string} The formatted URL with all dynamic segments replaced.
|
|
59
|
+
*
|
|
60
|
+
* @throws {Error} If the route contains dynamic segments but no parameters object is provided.
|
|
61
|
+
* @throws {Error} If a required parameter is missing from the `params` object.
|
|
62
|
+
* @throws {Error} If a parameter value is an empty string.
|
|
63
|
+
* @throws {Error} If any parameter contains invalid characters like `?`, `&`, `=`, `#`, `/`, spaces, `'`, `"`, `(`, `)`, `+`, `;`, `%`, `@`, or `:`, which can cause URL issues.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Basic usage
|
|
67
|
+
* generateRoute("/user/[id]", { id: "123" });
|
|
68
|
+
* // Returns: "/user/123"
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // No dynamic segments, returns as-is
|
|
72
|
+
* generateRoute("/dashboard");
|
|
73
|
+
* // Returns: "/dashboard"
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Throws an error due to missing parameters object
|
|
77
|
+
* generateRoute("/profile/[username]");
|
|
78
|
+
* // ❌ Error: 🚨 Missing parameters object for route: "/profile/[username]"
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Throws an error due to an empty parameter value
|
|
82
|
+
* generateRoute("/post/[category]/[slug]", { category: "tech", slug: "" });
|
|
83
|
+
* // ❌ Error: 🚨 Parameter "slug" cannot be empty in route: "/post/[category]/[slug]"
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Throws an error due to parameter containing invalid characters
|
|
87
|
+
* generateRoute("/search/[query]", { query: "how to?learn" });
|
|
88
|
+
* // ❌ Error: 🚨 Parameter "query" contains invalid character "?" in route: "/search/[query]"
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* // Handles leading/trailing slashes correctly
|
|
92
|
+
* generateRoute("/blog/[category]/[slug]", { category: "/news/", slug: "/latest-update/" });
|
|
93
|
+
* // ❌ Error: 🚨 Parameter "category" and "slug" contains slashes "/" which is not allowed.
|
|
94
|
+
*/
|
|
95
|
+
declare function generateRoute<T extends string>(route:T,...params:HasDynamicSegments<T>extends true ? [ExtractRouteParams<T>]:[]):string;
|
|
96
|
+
/** ---------------------------------
|
|
97
|
+
* * ***Constructs a backend API URL by appending a given pathname to the base API URL.***
|
|
98
|
+
* ---------------------------------
|
|
99
|
+
* This function builds on top of `getBeApiUrl()`, which determines the base API URL from:
|
|
100
|
+
* - `NEXT_PUBLIC_BACKEND_API_URL` environment variable (or defaults to `"http://localhost:8000"`).
|
|
101
|
+
* - Automatically appends `NEXT_PUBLIC_PORT_BE` if the base URL does not already include a port.
|
|
102
|
+
*
|
|
103
|
+
* Features of this function:
|
|
104
|
+
* - Allows customizing the API path with an optional `prefix` (defaults to `"/api"`).
|
|
105
|
+
* - Can include or exclude the origin (protocol + host) via `withOrigin`.
|
|
106
|
+
* - Normalizes paths to avoid duplicate slashes.
|
|
107
|
+
*
|
|
108
|
+
* * ⚠️ ***Notes: This Function only support when using `NextJS`***
|
|
109
|
+
*
|
|
110
|
+
* @param {string} pathname - The API endpoint path (e.g., `/users` or `/v1/posts`).
|
|
111
|
+
* @param {Object} options - Configuration options.
|
|
112
|
+
* @param {string} [options.prefix="/api"] - The prefix for the API path (default is `"/api"`).
|
|
113
|
+
* @param {boolean} [options.withOrigin=true] - Whether to include the full base URL or return only the API path.
|
|
114
|
+
* @returns {string} The formatted API URL.
|
|
115
|
+
*
|
|
116
|
+
* @throws {TypeError} If `withOrigin` is not a boolean.
|
|
117
|
+
* @throws {TypeError} If `prefix` and `pathname` is not a string.
|
|
118
|
+
* @throws {Error} If constructing the API URL fails due to an invalid base URL.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* createBeApiUrl("/users")
|
|
122
|
+
* // -> "http://localhost:8000/api/users"
|
|
123
|
+
*
|
|
124
|
+
* createBeApiUrl("/users", { withOrigin: false })
|
|
125
|
+
* // -> "/api/users"
|
|
126
|
+
*/
|
|
127
|
+
declare const createBeApiUrl:(
|
|
128
|
+
/** * The pathname api url, e.g:`"http://localhost.com/your-target-prefix-entri-point-api-is-here/your-target-pathname-is-here"`.
|
|
129
|
+
*
|
|
130
|
+
* @default "" */
|
|
131
|
+
pathname?:string,options?:{
|
|
132
|
+
/** * The prefix pathname api url, e.g:`"http://localhost.com/your-target-prefix-entri-point-api-is-here"`.
|
|
133
|
+
*
|
|
134
|
+
* @default "/api" */
|
|
135
|
+
prefix?:string;
|
|
136
|
+
/** * Option to getting `prefix` and `pathname` of api url only `(removing origin base api url)`.
|
|
137
|
+
*
|
|
138
|
+
* @default true */
|
|
139
|
+
withOrigin?:boolean;})=>string;
|
|
140
|
+
/** ---------------------------------
|
|
141
|
+
* * ***Retrieves the base API URL of the backend.***
|
|
142
|
+
* ---------------------------------
|
|
143
|
+
*
|
|
144
|
+
* This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
|
|
145
|
+
* If the variable is not set, it defaults to `"http://localhost:8000"`.
|
|
146
|
+
* It also allows adding an optional suffix to the returned URL.
|
|
147
|
+
*
|
|
148
|
+
* * ⚠️ ***Notes: This Function only support when using `NextJS`***
|
|
149
|
+
*
|
|
150
|
+
* This function determines the backend API base URL from the `NEXT_PUBLIC_BACKEND_API_URL` environment variable.
|
|
151
|
+
* - If `NEXT_PUBLIC_BACKEND_API_URL` is not set, it defaults to `"http://localhost:8000"`.
|
|
152
|
+
* - If `NEXT_PUBLIC_BACKEND_API_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_BE` if available.
|
|
153
|
+
* - Supports appending optional suffix (like "/api").
|
|
154
|
+
*
|
|
155
|
+
*
|
|
156
|
+
* @param {Object} options - Configuration options.
|
|
157
|
+
* @param {string} [options.suffix="/"] - The suffix to append to the base API URL.
|
|
158
|
+
* @returns {string} The formatted backend API base URL.
|
|
159
|
+
* @throws {TypeError} If `suffix` is not a `string`.
|
|
160
|
+
* @throws {Error} If `NEXT_PUBLIC_BACKEND_API_URL` is invalid.
|
|
161
|
+
*/
|
|
162
|
+
declare const getBeApiUrl:({suffix,}?:{
|
|
163
|
+
/** * The Suffix origin base api url, e.g:`http://localhost.com/api`.
|
|
164
|
+
*
|
|
165
|
+
* @default "/" */
|
|
166
|
+
suffix?:string;})=>string;
|
|
167
|
+
/** ---------------------------------
|
|
168
|
+
* * ***Retrieves the base URL of the application.***
|
|
169
|
+
* ---------------------------------
|
|
170
|
+
*
|
|
171
|
+
* This function is designed to be used within Next.js applications.
|
|
172
|
+
* It determines the base URL from the `NEXT_PUBLIC_BASE_URL` environment variable.
|
|
173
|
+
*
|
|
174
|
+
* * ⚠️ ***Notes: This Function only support when using `NextJS`***
|
|
175
|
+
*
|
|
176
|
+
* - If `NEXT_PUBLIC_BASE_URL` is not set, it defaults to `"http://localhost:3000"`.
|
|
177
|
+
* - If `NEXT_PUBLIC_BASE_URL` does **not** contain a port, it appends one from `NEXT_PUBLIC_PORT_FE` if available.
|
|
178
|
+
* - Ensures the final URL is valid and normalized (no trailing slashes).
|
|
179
|
+
*
|
|
180
|
+
* @returns {string} The resolved base URL of the application.
|
|
181
|
+
* @throws {Error} If the constructed URL is invalid or malformed.
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
declare const getBaseUrl:()=>string;export{createBeApiUrl,generateRoute,getBaseUrl,getBeApiUrl};export type{ExtractRouteParams,HasDynamicSegments};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var w=r=>Array.isArray(r);var o=r=>typeof r=="string";var x=(r,e)=>{if(!o(r))return true;s(e)||(e={});let{trim:n=true}=e;return n&&(r=r.trim()),r===""};var d=r=>typeof r=="boolean";var T=r=>r instanceof Error;var $=r=>Array.isArray(r)&&r.length>0;var s=r=>typeof r=="object"&&!v(r)&&!w(r);var p=(r,e)=>{if(!o(r))return false;s(e)||(e={});let{trim:n=true}=e;return(n?r.trim():r).length>0};var g=r=>typeof r>"u";function v(r){return r==null}var c=(r,e={trimOnly:false})=>{if(!p(r))return "";s(e)||(e={});let{trimOnly:n=false}=e;return n?r.trim():r.replace(/\s+/g,"")};var E=(r,e="/")=>{if(!p(e))throw new TypeError(`Invalid parameter:'defaultPath' must be a string and string is non-empty string. Received:${typeof e}(${e})`);if(!p(r))return e;try{if(r=c(r,{trimOnly:!0}),r=r.replace(/\s+/g,""),r.startsWith("http://")||r.startsWith("https://")){let n=new URL(r);return `${n.pathname}${n.search}${n.hash}`.replace(/^\/+/,"/")}return "/"+r.replace(/^\/+/,"").replace(/\/{2,}/g,"/")}catch(n){let t=T(n)?n:new Error("Unknown error from function `normalizePathname()`");throw new h(`Failed to normalize pathname in function \`normalizePathname()\`:${t.message}`,t)}};var y=(r,e)=>{if(!p(r))return "";if(!g(e)){if(!s(e))throw new TypeError("Options must be an object.");if("prefixColon"in e&&!d(e.prefixColon))throw new TypeError("Option `prefixColon` must be a boolean.")}let n=r.replace(/\D+/g,"");return n?e?.prefixColon??false?`:${n}`:n:""};var h=class r extends Error{constructor(n,t){super(n);this.originalError=t;this.name="NormalizePathnameError",Error.captureStackTrace&&Error.captureStackTrace(this,r);}};function G(r,e){if(!o(r)||x(r))throw new TypeError(`\u{1F6A8}'generateRoute' Failed:- Invalid 'route' value.- Expected a non-empty string,but received ${typeof r}:${JSON.stringify(r)}`);if(!r.includes("["))return r;if(!s(e))throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":- Missing or invalid parameters object for route:"${r}",expected an object mapping parameters.`);if(!e)throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":- Missing parameters object for route:"${r}"`);let n=["?","&","#","=","/"," ","'",'"',"(",")","+",";","%","@",":"],t=[],i=Array.from(r.matchAll(/\[(\w+)\]/g)).map(a=>a[1]);for(let a of i){let l=e[a];if(g(l)){t.push(`- Missing parameter:"${a}".`);continue}let f=l.trim();if(!f){t.push(`- Parameter "${a}" cannot be empty.`);continue}f.includes("/")&&t.push(`- Parameter "${a}" contains slashes "/" which is not allowed.`);let u=n.filter(m=>m!=="/").filter(m=>f.includes(m));u.length>0&&t.push(`- Parameter "${a}" contains invalid characters(${u.length>1?u.join(","):u}). These characters are not allowed because they could cause issues in URL structure. The following characters are forbidden in route parameters:(${n.join(",")}).`);}if($(t))throw new Error(`\u{1F6A8}'generateRoute' Failed cause in route "${r}":${t.join(``)}`);return r.replace(/\[(\w+)\]/g,(a,l)=>e[l].trim().replace(/^\/+|\/+$/g,"")).replace(/\/+/g,"/")}var rr=(r="",e)=>{try{let f=function(m,P){return `${m.replace(/\/+$/,"")}/${P.replace(/^\/+/,"")}`};var n=f;if(!o(r))throw new TypeError(`Invalid type for 'pathname'. Expected 'string',received:${typeof r}`);s(e)||(e={});let{prefix:t="/api",withOrigin:i=!0}=e;if(!g(t)&&!o(t))throw new TypeError(`Invalid type for 'prefix'. Expected 'string',received:${typeof t}`);if(!d(i))throw new TypeError(`Invalid type for 'withOrigin'. Expected 'boolean',received:${typeof i}`);r=E(r),t=E(t);let a=t.endsWith("/")?t:t+"/";(r===t||r===t+"/"||r.startsWith(a))&&(r=r.slice(t.length),r=E(r));let l=b({suffix:t});return f(i?l:new URL(l).pathname,r).replace(/\/+$/,"")}catch(t){throw new Error("Failed to generate backend API URL in `createBeApiUrl()`,Error:"+t)}};var b=({suffix:r="/"}={})=>{if(!o(r))throw new TypeError(`Invalid type for 'suffix'. Expected string,received:${typeof r}`);try{let e=process.env.NEXT_PUBLIC_BACKEND_API_URL?.trim();if(e){e=c(e);let i=new URL(e);!!!i.port&&process.env.NEXT_PUBLIC_PORT_BE&&(e=i.origin+y(process.env.NEXT_PUBLIC_PORT_BE,{prefixColon:!0}));}else e="http://localhost"+y(process.env.NEXT_PUBLIC_PORT_BE||"8000",{prefixColon:!0});r=c(r).length?c(r):"/";let n=new URL(e.replace(/\/+$/,"")).origin,t=r==="/"?"/":`${r.startsWith("/")?"":"/"}${r.replace(/\/+$/,"")}`;return `${n}${t}`}catch(e){throw new Error("Invalid `NEXT_PUBLIC_BACKEND_API_URL`,failed to generate from `getBeApiUrl()`,Error:"+e)}};var or=()=>{try{let r=process.env.NEXT_PUBLIC_BASE_URL?.trim(),e=process.env.NEXT_PUBLIC_PORT_FE?.trim(),n=r||"http://localhost";n=c(n).replace(/\/+$/,"");let t=/:\/\/[^/]+:\d+/.test(n);!t&&e?n+=y(e,{prefixColon:!0}):!t&&!r&&(n+=":3000");let i=new URL(n);return `${i.protocol}//${i.hostname}${i.port?`:${i.port}`:""}`}catch(r){throw new Error("Invalid `NEXT_PUBLIC_BASE_URL`,failed to generate from `getBaseUrl()`,Error:"+r)}};export{rr as createBeApiUrl,G as generateRoute,or as getBaseUrl,b as getBeApiUrl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';require('server-only');var server=require('next/server');var n=e=>typeof e=="boolean";var i=e=>typeof e=="function";var w=(e,o=true)=>{if(!i(server.NextRequest))throw new Error("`getClientIpOrUrl` is designed to be used in a `Next.js` environment.");if(!(e instanceof server.NextRequest))throw new TypeError("Argument `request` must be an instance of NextRequest.");if(!n(o))throw new TypeError("Expected `includeFullUrl` to be a boolean.");let t=(e.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(t[0]==="::ffff:127.0.0.1"||t[0]==="::1")&&(t[0]="127.0.0.1");let r=t.length>1?t[t.length-1].trim():t[0];if(!o)return r;let p=e.headers.get("x-forwarded-proto")||"http",a=e.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV=="production"?p:"http"}://${r}:${a}`};exports.getClientIpOrUrl=w;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import{NextRequest}from 'next/server';
|
|
2
|
+
/** ---------------------------------
|
|
3
|
+
* * ***Retrieves the real client IP address and constructs the full URL using headers like***
|
|
4
|
+
* ***`x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-port`.***
|
|
5
|
+
* ---------------------------------
|
|
6
|
+
*
|
|
7
|
+
* * ⚠️ **Notes:**
|
|
8
|
+
* - Only supported in **Next.js** environments (specifically in `server-only` contexts).
|
|
9
|
+
* - Should be used in **middleware** or **server actions** that have access to `NextRequest`.
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @param {NextRequest} request - The incoming Next.js request object.
|
|
13
|
+
* @param {boolean} [includeFullUrl=true] - Whether to return the full URL (`protocol://ip:port`) or just the IP address.
|
|
14
|
+
*
|
|
15
|
+
* @returns {string} The extracted client IP address or the full constructed URL.
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} If the function is used outside a Next.js server environment.
|
|
18
|
+
* @throws {TypeError} If the arguments do not match the expected types.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Basic usage in Next.js middleware
|
|
22
|
+
* import { NextRequest } from "next/server";
|
|
23
|
+
* import { getClientIpOrUrl } from "@rzl-zone/utils-js/next/server";
|
|
24
|
+
*
|
|
25
|
+
* export function middleware(request: NextRequest) {
|
|
26
|
+
* const clientIp = getClientIpOrUrl(request, false);
|
|
27
|
+
* console.log("Client IP:", clientIp);
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Get full URL
|
|
32
|
+
* const url = getClientIpOrUrl(request);
|
|
33
|
+
* console.log("Client full URL:", url);
|
|
34
|
+
*/
|
|
35
|
+
declare const getClientIpOrUrl:(
|
|
36
|
+
/** * The incoming Next.js request object. */
|
|
37
|
+
request:NextRequest,
|
|
38
|
+
/** * Whether to return the full URL (protocol, IP, and port) or just the IP address.
|
|
39
|
+
*
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
includeFullUrl?:boolean)=>string;export{getClientIpOrUrl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import'server-only';import{NextRequest}from'next/server';var n=e=>typeof e=="boolean";var i=e=>typeof e=="function";var w=(e,o=true)=>{if(!i(NextRequest))throw new Error("`getClientIpOrUrl` is designed to be used in a `Next.js` environment.");if(!(e instanceof NextRequest))throw new TypeError("Argument `request` must be an instance of NextRequest.");if(!n(o))throw new TypeError("Expected `includeFullUrl` to be a boolean.");let t=(e.headers.get("x-forwarded-for")??"127.0.0.1").trim().split(",");(t[0]==="::ffff:127.0.0.1"||t[0]==="::1")&&(t[0]="127.0.0.1");let r=t.length>1?t[t.length-1].trim():t[0];if(!o)return r;let p=e.headers.get("x-forwarded-proto")||"http",a=e.headers.get("x-forwarded-port")||"3000";return `${process.env.NODE_ENV=="production"?p:"http"}://${r}:${a}`};export{w as getClientIpOrUrl};
|