@zuzjs/core 0.3.15 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var E=require('axios'),J=require('fs/promises'),K=require('hashids'),T=require('js-cookie'),Q=require('md5'),d=require('moment'),nanoid=require('nanoid'),F=require('ip-regex');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var E__default=/*#__PURE__*/_interopDefault(E);var J__default=/*#__PURE__*/_interopDefault(J);var K__default=/*#__PURE__*/_interopDefault(K);var T__default=/*#__PURE__*/_interopDefault(T);var Q__default=/*#__PURE__*/_interopDefault(Q);var d__default=/*#__PURE__*/_interopDefault(d);var F__default=/*#__PURE__*/_interopDefault(F);/* ZuzJS Core */
2
- var M=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];var L=/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/,U=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/,B=/^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;var G=(r=>(r.Asc="ASC",r.Desc="DESC",r))(G||{});var P=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return F__default.default.v4({exact:true}).test(this._)}isIPv6(){return F__default.default.v6({exact:true}).test(this._)}isTypeof(t){return typeof this._==typeof t}isFunction(){return typeof this._=="function"}isArray(){return Array.isArray(this._)}isNull(){return this._===null}isString(){return typeof this._=="string"}isNumber(){return /^[+-]?\d+(\.\d+)?$/.test(this._)}isObject(){return typeof this._=="object"&&!Array.isArray(this._)&&this._!==null}isEmpty(){return Array.isArray(this._)?this._.length===0:typeof this._=="object"&&this._!==null?Object.keys(this._).length===0:this._===""||String(this._).length===0}isEmail(){return typeof this._=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(decodeURIComponent(this._))}isUrl(){return typeof this._=="string"&&/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/.test(this._)}toLowerCase(){return this._=typeof this._=="string"?this._.toLowerCase():String(this._).toLowerCase(),this}equals(t){let r=this._,n=t,o=(s,u)=>{if(s===u)return true;if(s===null||typeof s!="object"||u===null||typeof u!="object")return false;if(Array.isArray(s)&&Array.isArray(u)){if(s.length!==u.length)return false;for(let a=0;a<s.length;a++)if(!o(s[a],u[a]))return false;return true}if(this.isObjectValue(s)&&this.isObjectValue(u)){let a=Object.keys(s),c=Object.keys(u);if(a.length!==c.length)return false;for(let h of a)if(!c.includes(h)||!o(s[h],u[h]))return false;return true}return false},i=s=>typeof s=="object"&&s!==null&&!Array.isArray(s);return this.isObjectValue=i,Array.isArray(r)&&Array.isArray(n)||i(r)&&i(n)?o(r,n):r===n}isObjectValue(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}ucfirst(){return this._=typeof this._=="string"?this._.charAt(0).toUpperCase()+this._.slice(1):this._,this}formatString(t,...r){typeof this._!="string"&&(this._="");let n=[t,...r];return this._=this._.replace(/%(\d+)/g,(o,i)=>n[Number(i)]?.toString()||`%${i}`),this}camelCase(){return this._=typeof this._=="string"?this._.split(/[^a-zA-Z0-9]+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join(""):this._,this}sort(t="asc"){if(!this.isObject())return console.warn("sortKeys can only be applied to objects. Current value is not an object."),this;let r=this._,n=Object.keys(r).sort((i,s)=>t==="desc"?s.localeCompare(i):i.localeCompare(s)),o={};for(let i of n)o[i]=r[i];return this._=o,this}value(){return this._}valueOf(){return this._}toString(){return String(this._)}[Symbol.toPrimitive](t){return t==="number"?Number(this._):t==="boolean"?!!this._:String(this._)}},V=e=>new P(e),S=V;var N=class{_events;constructor(){this._events=[];}on(t,r,n){let o=this._events.find(u=>u.event===t),i=Symbol("listener_id"),s={fun:r,context:n,id:i};return o?o.listeners.push(s):this._events.push({event:t,listeners:[s]}),()=>{let u=this._events.find(a=>a.event===t);u&&(u.listeners=u.listeners.filter(a=>a.id!==i),u.listeners.length===0&&(this._events=this._events.filter(a=>a.event!==t)));}}off(t,r){let n=this._events.find(o=>o.event===t);n&&(n.listeners=n.listeners.filter(o=>o.fun!==r),n.listeners.length===0&&(this._events=this._events.filter(o=>o.event!==t)));}emit(t,...r){let n=this._events.find(o=>o.event===t);n&&[...n.listeners].forEach(({fun:o,context:i})=>{try{o.apply(i,r);}catch(s){console.error(`Error during event '${String(t)}' emission:`,s);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},Y=N;var Z="zuzjs-core",ee=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,te=(e,t=6,r=null)=>new K__default.default(r||Z,t).encode(e),$e=(e,t=null)=>{try{let r=new K__default.default(t||Z,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},De=e=>Q__default.default(e),He=e=>te(ee(11111111111,999999999999)),qe=e=>nanoid.nanoid(e),I=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,We=e=>decodeURIComponent(e.replace(/\+/g,"%20")),ze=e=>encodeURIComponent(e),Me=(e,t)=>`${e}${t!==1?"s":""}`,re=e=>L.test(e),ne=e=>U.test(e),se=e=>B.test(e),Le=e=>M.includes(e.toLowerCase()),Ue=e=>re(e)||ne(e)||se(e),Be=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(s=>s+s).join(""));let r=parseInt(e,16),n=r>>16&255,o=r>>8&255,i=r&255;return `rgba(${n}, ${o}, ${i}, ${t})`},oe=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),Fe=e=>{if(!e.trim())return "";let t=e.split(/\s+/).filter(Boolean);return oe(t).join(" ")},Ie=()=>E__default.default.CancelToken.source(),Ke=e=>E__default.default.defaults.withCredentials=e,ie=e=>{let r=typeof navigator<"u"?navigator.onLine:true;return {error:e?.code??"ERR_NETWORK",message:r?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}},A=(e=60,t=false,r={},n)=>typeof e=="object"&&e!==null?{timeout:e.timeout??60,ignoreKind:e.ignoreKind??false,headers:e.headers??{},onProgress:e.onProgress,withCredentials:e.withCredentials,returnRawResponse:e.returnRawResponse,appendCookiesToBody:e.appendCookiesToBody??true,appendTimestamp:e.appendTimestamp??true}:{timeout:e,ignoreKind:t,headers:r,onProgress:n,appendCookiesToBody:true,appendTimestamp:true},O=(e,t)=>{let r=T__default.default.get(),n=e,o="application/json";if(e instanceof FormData){if(o="multipart/form-data",t.appendCookiesToBody)for(let[i,s]of Object.entries(r))e.append(i,s);}else if(typeof e=="object"&&!Array.isArray(e)&&e!==null)n={...e,...t.appendCookiesToBody?r:{},...t.appendTimestamp?{__stmp:Date.now()/1e3}:{}};else if(!S(e).isString())throw new Error("Unsupported data type for withPost/withPut/withPatch");return {finalData:n,contentType:o}},ae=(e,t)=>{if(t.returnRawResponse)return e;if(e.data&&(t.ignoreKind||"kind"in e.data))return e.data;throw e.data},v=async(e,t)=>{try{let r=await E__default.default(e);return ae(r,t)}catch(r){throw r?.response?.data?r.response.data:r?.code==="ERR_NETWORK"?ie(r):r}};async function Ze(e,t,r=60,n=false,o={},i){let s=A(r,n,o,i),{finalData:u,contentType:a}=O(t,s);return v({method:"post",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}async function Ge(e,t=60,r=false,n={}){let o=A(t,r,n);return v({method:"get",url:e,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:o.headers},o)}async function Ve(e,t,r=60,n=false,o={},i){let s=A(r,n,o,i),{finalData:u,contentType:a}=O(t,s);return v({method:"put",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}async function Ye(e,t,r=60,n=false,o={},i){let s=A(r,n,o,i),{finalData:u,contentType:a}=O(t,s);return v({method:"patch",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}var Je=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},Qe=(e,t)=>{let r=t||"YYYY-MM-DD HH:mm:ss";if(!e)return d__default.default().format(r);if(e instanceof Date)return d__default.default(e).format(r);if(typeof e=="string"&&isNaN(Number(e)))return d__default.default(e).format(r);let n=Number(e);return n>9999999999?d__default.default(n).format(r):d__default.default.unix(n).format(r)},Xe=e=>{if(e instanceof Date)return d__default.default(e).fromNow();if(typeof e=="string"&&isNaN(Number(e)))return d__default.default(e).fromNow();let t=Number(e);return t>9999999999?d__default.default(t).fromNow():d__default.default.unix(t).fromNow()},et=e=>e[Math.floor(Math.random()*e.length)],tt=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:o=false,currency:i})=>{if(r==="currency"&&!i)throw new TypeError("Currency code is required with currency style.");if(i){let{code:s,style:u,symbol:a}=i,c=new Intl.NumberFormat(t,{style:"currency",currency:s,currencyDisplay:u,minimumFractionDigits:o||+e%1>0?n:0,maximumFractionDigits:o||+e%1>0?n:0}).format(+e);return a?c.replace(new RegExp(`\\${s}`,"g"),a):c}return new Intl.NumberFormat(t,{style:r,minimumFractionDigits:o?n:+e%1>0?2:0,maximumFractionDigits:o?n:+e%1>0?2:0}).format(+e)},rt=e=>{let t=["Bytes","KB","MB","GB","TB"],r=typeof e=="string"?parseFloat(e):e;if(r==0)return "0 Byte";let n=Math.floor(Math.log(r)/Math.log(1024)),o=typeof n=="string"?parseInt(n):n;return (r/Math.pow(1024,o)).toFixed(2)+" "+t[o]},nt=e=>navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(e):new Promise((t,r)=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",document.body.appendChild(n),n.focus(),n.select();try{document.execCommand("copy"),t("Copied to clipboard");}catch(o){r(o);}document.body.removeChild(n);}),st=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,o=/[^\x00-\x80]/,i=/^0x[0-9a-f]+$/i,s=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,u=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=e.direction=="DESC"?-1:1,c=-a,h=e.caseSensitive?l=>`${l}`.replace(n,""):l=>l.toString().toLowerCase().replace(n,""),j=l=>l.replace(s,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),$=(l,C)=>(!l.match(t)||C===1)&&parseFloat(l)||l.replace(r," ").replace(n,"")||0;return function(l,C){let f=h(l),g=h(C);if(!f&&!g)return 0;if(!f&&g)return c;if(f&&!g)return a;let R=j(f),D=j(g),_=f.match(i),k=g.match(i),y=_&&k?parseInt(_[0],16):R.length!==1&&Date.parse(f),b=_&&k?parseInt(k[0],16):y&&g.match(u)&&Date.parse(g)||null;if(b){if(y===b)return 0;if(typeof y=="number"&&typeof b=="number"&&y<b)return c;if(typeof y=="number"&&y>b)return a}let H=R.length,q=D.length;for(let x=0,W=Math.max(H,q);x<W;x+=1){let p=$(R[x]||"",H),m=$(D[x]||"",q);if(isNaN(p)!==isNaN(m))return isNaN(p)?a:c;if(o.test(p+m)&&p.localeCompare){let z=p.localeCompare(m);if(z>0)return a;if(z<0)return c;if(x===W-1)return 0}if(p<m)return c;if(p>m)return a;if(`${p}`<`${m}`)return c;if(`${p}`>`${m}`)return a}return 0}},ot=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?I(r):r:I(r)).join(""),it=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),at=(e,t,r)=>Math.min(Math.max(e,t),r),ut=(e,t="-")=>e==null?(console.log(e,"is undefined"),""):e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\p{L}\p{N}]+/gu,t).replace(new RegExp(`\\${t}{2,}`,"g"),t).replace(new RegExp(`^\\${t}|\\${t}$`,"g"),""),ct=e=>new Promise(t=>setTimeout(t,e)),lt=(e,t)=>setTimeout(e,t||1e3),pt=e=>Object.keys(e).filter(t=>isNaN(Number(t))),dt=async e=>{try{return await J__default.default.access(e),!0}catch{return false}},gt=e=>{let t=(e??"").trim();if(t.length===0)return new Uint8Array(0);let r="=".repeat((4-t.length%4)%4),n=(t+r).replace(/-/g,"+").replace(/_/g,"/"),o=window.atob(n),i=new Uint8Array(o.length);for(let s=0;s<o.length;++s)i[s]=o.charCodeAt(s);return i},mt=e=>{let t=e??"",r=[],n=0;return t.length>=8?n++:r.push("Use at least 8 characters"),/[a-z]/.test(t)?n++:r.push("Add lowercase letters"),/[A-Z]/.test(t)?n++:r.push("Add uppercase letters"),/\d/.test(t)?n++:r.push("Include numbers"),/[^A-Za-z0-9]/.test(t)?n++:r.push("Add special characters (e.g. !, @, #)"),{score:n,result:n<=2?"Weak":n==3?"Moderate":n==4?"Strong":"Excellent",suggestion:r}},ue=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ht=(e,t)=>{if(t.length===0)return e.trim();let r=t.map(o=>o.trim()).filter(Boolean).map(ue);if(r.length===0)return e.trim();let n=new RegExp(`\\b(${r.join("|")})\\b`,"gi");return e.replace(n,"").replace(/\s+/g," ").trim()},ft=(e,t=false)=>{let r=T__default.default.get(e);return r?t?JSON.parse(r):r:null},yt=e=>T__default.default.remove(e),bt=({key:e,value:t,json:r=false,path:n="/",expires:o,domain:i,secure:s,sameSite:u})=>{try{T__default.default.set(e,r||typeof t=="object"?JSON.stringify(t):t,{expires:o,path:n,domain:i,secure:s,sameSite:u});}catch(a){console.log("--- Error setting cookie",a);}};exports.MD5=De;exports.PubSub=Y;exports.SORT=G;exports._=S;exports.__SALT=Z;exports.arrayRand=et;exports.camelCase=ot;exports.camelCaseToDash=it;exports.checkPasswordStrength=mt;exports.clamp=at;exports.copyToClipboard=nt;exports.enumToKeys=pt;exports.escapeRegex=ue;exports.exists=dt;exports.formatNumber=tt;exports.formatSize=rt;exports.fromHash=$e;exports.getCancelToken=Ie;exports.getCookie=ft;exports.hexToRgba=Be;exports.isColor=Ue;exports.isColorName=Le;exports.isHexColor=re;exports.isHslColor=se;exports.isRgbaColor=ne;exports.natsort=st;exports.numberInRange=ee;exports.pluralize=Me;exports.removeCookie=yt;exports.removeDuplicateWords=Fe;exports.removeDuplicates=oe;exports.removeWords=ht;exports.setCookie=bt;exports.sleep=ct;exports.slugify=ut;exports.time=Qe;exports.timeSince=Xe;exports.toHash=te;exports.ucfirst=I;exports.urlBase64ToUint8Array=gt;exports.urldecode=We;exports.urlencode=ze;exports.uuid=He;exports.uuid2=qe;exports.withCredentials=Ke;exports.withDelay=lt;exports.withGet=Ge;exports.withPatch=Ye;exports.withPost=Ze;exports.withPut=Ve;exports.withTime=Je;
1
+ 'use strict';var O=require('axios'),Q=require('fs/promises'),Z=require('hashids'),A=require('js-cookie'),X=require('md5'),m=require('moment'),nanoid=require('nanoid'),B=require('ip-regex');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var O__default=/*#__PURE__*/_interopDefault(O);var Q__default=/*#__PURE__*/_interopDefault(Q);var Z__default=/*#__PURE__*/_interopDefault(Z);var A__default=/*#__PURE__*/_interopDefault(A);var X__default=/*#__PURE__*/_interopDefault(X);var m__default=/*#__PURE__*/_interopDefault(m);var B__default=/*#__PURE__*/_interopDefault(B);/* ZuzJS Core */
2
+ var I=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];var z=/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/,L=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/,U=/^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;var V=(r=>(r.Asc="ASC",r.Desc="DESC",r))(V||{});var S=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return B__default.default.v4({exact:true}).test(this._)}isIPv6(){return B__default.default.v6({exact:true}).test(this._)}isTypeof(t){return typeof this._==typeof t}isFunction(){return typeof this._=="function"}isArray(){return Array.isArray(this._)}isNull(){return this._===null}isString(){return typeof this._=="string"}isNumber(){return /^[+-]?\d+(\.\d+)?$/.test(this._)}isObject(){return typeof this._=="object"&&!Array.isArray(this._)&&this._!==null}isEmpty(){return Array.isArray(this._)?this._.length===0:typeof this._=="object"&&this._!==null?Object.keys(this._).length===0:this._===""||String(this._).length===0}isEmail(){return typeof this._=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(decodeURIComponent(this._))}isUrl(){return typeof this._=="string"&&/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/.test(this._)}toLowerCase(){return this._=typeof this._=="string"?this._.toLowerCase():String(this._).toLowerCase(),this}equals(t){let r=this._,n=t,s=(o,c)=>{if(o===c)return true;if(o===null||typeof o!="object"||c===null||typeof c!="object")return false;if(Array.isArray(o)&&Array.isArray(c)){if(o.length!==c.length)return false;for(let a=0;a<o.length;a++)if(!s(o[a],c[a]))return false;return true}if(this.isObjectValue(o)&&this.isObjectValue(c)){let a=Object.keys(o),u=Object.keys(c);if(a.length!==u.length)return false;for(let l of a)if(!u.includes(l)||!s(o[l],c[l]))return false;return true}return false},i=o=>typeof o=="object"&&o!==null&&!Array.isArray(o);return this.isObjectValue=i,Array.isArray(r)&&Array.isArray(n)||i(r)&&i(n)?s(r,n):r===n}isObjectValue(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}ucfirst(){return this._=typeof this._=="string"?this._.charAt(0).toUpperCase()+this._.slice(1):this._,this}formatString(t,...r){typeof this._!="string"&&(this._="");let n=[t,...r];return this._=this._.replace(/%(\d+)/g,(s,i)=>n[Number(i)]?.toString()||`%${i}`),this}camelCase(){return this._=typeof this._=="string"?this._.split(/[^a-zA-Z0-9]+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join(""):this._,this}sort(t="asc"){if(!this.isObject())return console.warn("sortKeys can only be applied to objects. Current value is not an object."),this;let r=this._,n=Object.keys(r).sort((i,o)=>t==="desc"?o.localeCompare(i):i.localeCompare(o)),s={};for(let i of n)s[i]=r[i];return this._=s,this}value(){return this._}valueOf(){return this._}toString(){return String(this._)}[Symbol.toPrimitive](t){return t==="number"?Number(this._):t==="boolean"?!!this._:String(this._)}},Y=e=>new S(e),$=Y;var N=class{_events;constructor(){this._events=[];}on(t,r,n){let s=this._events.find(c=>c.event===t),i=Symbol("listener_id"),o={fun:r,context:n,id:i};return s?s.listeners.push(o):this._events.push({event:t,listeners:[o]}),()=>{let c=this._events.find(a=>a.event===t);c&&(c.listeners=c.listeners.filter(a=>a.id!==i),c.listeners.length===0&&(this._events=this._events.filter(a=>a.event!==t)));}}off(t,r){let n=this._events.find(s=>s.event===t);n&&(n.listeners=n.listeners.filter(s=>s.fun!==r),n.listeners.length===0&&(this._events=this._events.filter(s=>s.event!==t)));}emit(t,...r){let n=this._events.find(s=>s.event===t);n&&[...n.listeners].forEach(({fun:s,context:i})=>{try{s.apply(i,r);}catch(o){console.error(`Error during event '${String(t)}' emission:`,o);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},J=N;var G="zuzjs-core",te=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,re=(e,t=6,r=null)=>new Z__default.default(r||G,t).encode(e),He=(e,t=null)=>{try{let r=new Z__default.default(t||G,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},Me=e=>X__default.default(e),qe=e=>re(te(11111111111,999999999999)),We=e=>nanoid.nanoid(e),F=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,Ie=e=>decodeURIComponent(e.replace(/\+/g,"%20")),ze=e=>encodeURIComponent(e),Le=(e,t)=>`${e}${t!==1?"s":""}`,ne=e=>z.test(e),se=e=>L.test(e),oe=e=>U.test(e),Ue=e=>I.includes(e.toLowerCase()),Be=e=>ne(e)||se(e)||oe(e),Fe=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(o=>o+o).join(""));let r=parseInt(e,16),n=r>>16&255,s=r>>8&255,i=r&255;return `rgba(${n}, ${s}, ${i}, ${t})`},Ke=()=>{let e=typeof window<"u"?performance.now():Date.now();return `#${(Math.floor(e*2654435769)&16777215).toString(16).padStart(6,"0")}`};function ie(e,t="string"){e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(p=>p+p).join(""));let r=parseInt(e.substring(0,2),16)/255,n=parseInt(e.substring(2,4),16)/255,s=parseInt(e.substring(4,6),16)/255,i=Math.max(r,n,s),o=Math.min(r,n,s),c=0,a=0,u=(i+o)/2;if(i!==o){let p=i-o;switch(a=u>.5?p/(2-i-o):p/(i+o),i){case r:c=(n-s)/p+(n<s?6:0);break;case n:c=(s-r)/p+2;break;case s:c=(r-n)/p+4;break}c/=6;}let l={h:Math.round(c*360),s:Math.round(a*100),l:Math.round(u*100)};return t==="string"?`hsl(${l.h}, ${l.s}%, ${l.l}%)`:l}var K=e=>{let t=e.replace(/^#/,""),r=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),s=parseInt(t.substring(4,6),16);return (r*299+n*587+s*114)/1e3>=128?"#1a1a1a":"#ffffff"},Ze=e=>{let t=ie(e,"object"),r=K(e)==="#ffffff",n=(s=0,i=0,o=0,c=1)=>{let a=(t.h+s+360)%360,u=Math.min(100,Math.max(0,t.s+i)),l=Math.min(100,Math.max(0,t.l+o));return c===1?`hsl(${a}, ${u}%, ${l}%)`:`hsla(${a}, ${u}%, ${l}%, ${c})`};return {primary:e,onPrimary:K(e),background:r?n(0,-10,-40):n(0,-20,45),surface:r?n(0,-5,-35):n(0,-15,40),foreground:r?"#ffffff":"#1a1a1a",muted:r?n(0,-20,20,.7):n(0,-20,-30,.6),border:r?n(0,0,10,.2):n(0,0,-10,.1),hover:n(0,0,r?10:-10),active:n(0,0,r?-5:5),ghost:n(0,0,0,.12)}},ae=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),Ge=e=>{if(!e.trim())return "";let t=e.split(/\s+/).filter(Boolean);return ae(t).join(" ")},Ve=()=>O__default.default.CancelToken.source(),Ye=e=>O__default.default.defaults.withCredentials=e,ce=e=>{let r=typeof navigator<"u"?navigator.onLine:true;return {error:e?.code??"ERR_NETWORK",message:r?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}},v=(e=60,t=false,r={},n)=>typeof e=="object"&&e!==null?{timeout:e.timeout??60,ignoreKind:e.ignoreKind??false,headers:e.headers??{},onProgress:e.onProgress,withCredentials:e.withCredentials,returnRawResponse:e.returnRawResponse,appendCookiesToBody:e.appendCookiesToBody??true,appendTimestamp:e.appendTimestamp??true}:{timeout:e,ignoreKind:t,headers:r,onProgress:n,appendCookiesToBody:true,appendTimestamp:true},j=(e,t)=>{let r=A__default.default.get(),n=e,s="application/json";if(e instanceof FormData){if(s="multipart/form-data",t.appendCookiesToBody)for(let[i,o]of Object.entries(r))e.append(i,o);}else if(typeof e=="object"&&!Array.isArray(e)&&e!==null)n={...e,...t.appendCookiesToBody?r:{},...t.appendTimestamp?{__stmp:Date.now()/1e3}:{}};else if(!$(e).isString())throw new Error("Unsupported data type for withPost/withPut/withPatch");return {finalData:n,contentType:s}},ue=(e,t)=>{if(t.returnRawResponse)return e;if(e.data&&(t.ignoreKind||"kind"in e.data))return e.data;throw e.data},C=async(e,t)=>{try{let r=await O__default.default(e);return ue(r,t)}catch(r){throw r?.response?.data?r.response.data:r?.code==="ERR_NETWORK"?ce(r):r}};async function Je(e,t,r=60,n=false,s={},i){let o=v(r,n,s,i),{finalData:c,contentType:a}=j(t,o);return C({method:"post",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}async function Qe(e,t=60,r=false,n={}){let s=v(t,r,n);return C({method:"get",url:e,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:s.headers},s)}async function Xe(e,t,r=60,n=false,s={},i){let o=v(r,n,s,i),{finalData:c,contentType:a}=j(t,o);return C({method:"put",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}async function et(e,t,r=60,n=false,s={},i){let o=v(r,n,s,i),{finalData:c,contentType:a}=j(t,o);return C({method:"patch",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}var tt=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},rt=(e,t)=>{let r=t||"YYYY-MM-DD HH:mm:ss";if(!e)return m__default.default().format(r);if(e instanceof Date)return m__default.default(e).format(r);if(typeof e=="string"&&isNaN(Number(e)))return m__default.default(e).format(r);let n=Number(e);return n>9999999999?m__default.default(n).format(r):m__default.default.unix(n).format(r)},nt=e=>{if(e instanceof Date)return m__default.default(e).fromNow();if(typeof e=="string"&&isNaN(Number(e)))return m__default.default(e).fromNow();let t=Number(e);return t>9999999999?m__default.default(t).fromNow():m__default.default.unix(t).fromNow()},st=e=>e[Math.floor(Math.random()*e.length)],ot=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:s=false,currency:i})=>{if(r==="currency"&&!i)throw new TypeError("Currency code is required with currency style.");if(i){let{code:o,style:c,symbol:a}=i,u=new Intl.NumberFormat(t,{style:"currency",currency:o,currencyDisplay:c,minimumFractionDigits:s||+e%1>0?n:0,maximumFractionDigits:s||+e%1>0?n:0}).format(+e);return a?u.replace(new RegExp(`\\${o}`,"g"),a):u}return new Intl.NumberFormat(t,{style:r,minimumFractionDigits:s?n:+e%1>0?2:0,maximumFractionDigits:s?n:+e%1>0?2:0}).format(+e)},it=e=>{let t=["Bytes","KB","MB","GB","TB"],r=typeof e=="string"?parseFloat(e):e;if(r==0)return "0 Byte";let n=Math.floor(Math.log(r)/Math.log(1024)),s=typeof n=="string"?parseInt(n):n;return (r/Math.pow(1024,s)).toFixed(2)+" "+t[s]},at=e=>navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(e):new Promise((t,r)=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",document.body.appendChild(n),n.focus(),n.select();try{document.execCommand("copy"),t("Copied to clipboard");}catch(s){r(s);}document.body.removeChild(n);}),ct=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,s=/[^\x00-\x80]/,i=/^0x[0-9a-f]+$/i,o=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,c=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=e.direction=="DESC"?-1:1,u=-a,l=e.caseSensitive?d=>`${d}`.replace(n,""):d=>d.toString().toLowerCase().replace(n,""),p=d=>d.replace(o,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),E=(d,R)=>(!d.match(t)||R===1)&&parseFloat(d)||d.replace(r," ").replace(n,"")||0;return function(d,R){let y=l(d),f=l(R);if(!y&&!f)return 0;if(!y&&f)return u;if(y&&!f)return a;let _=p(y),D=p(f),k=y.match(i),P=f.match(i),b=k&&P?parseInt(k[0],16):_.length!==1&&Date.parse(y),x=k&&P?parseInt(P[0],16):b&&f.match(c)&&Date.parse(f)||null;if(x){if(b===x)return 0;if(typeof b=="number"&&typeof x=="number"&&b<x)return u;if(typeof b=="number"&&b>x)return a}let H=_.length,M=D.length;for(let w=0,q=Math.max(H,M);w<q;w+=1){let g=E(_[w]||"",H),h=E(D[w]||"",M);if(isNaN(g)!==isNaN(h))return isNaN(g)?a:u;if(s.test(g+h)&&g.localeCompare){let W=g.localeCompare(h);if(W>0)return a;if(W<0)return u;if(w===q-1)return 0}if(g<h)return u;if(g>h)return a;if(`${g}`<`${h}`)return u;if(`${g}`>`${h}`)return a}return 0}},ut=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?F(r):r:F(r)).join(""),lt=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),pt=(e,t,r)=>Math.min(Math.max(e,t),r),dt=(e,t="-")=>e==null?(console.log(e,"is undefined"),""):e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\p{L}\p{N}]+/gu,t).replace(new RegExp(`\\${t}{2,}`,"g"),t).replace(new RegExp(`^\\${t}|\\${t}$`,"g"),""),gt=e=>new Promise(t=>setTimeout(t,e)),mt=(e,t)=>setTimeout(e,t||1e3),ft=e=>Object.keys(e).filter(t=>isNaN(Number(t))),ht=async e=>{try{return await Q__default.default.access(e),!0}catch{return false}},yt=e=>{let t=(e??"").trim();if(t.length===0)return new Uint8Array(0);let r="=".repeat((4-t.length%4)%4),n=(t+r).replace(/-/g,"+").replace(/_/g,"/"),s=window.atob(n),i=new Uint8Array(s.length);for(let o=0;o<s.length;++o)i[o]=s.charCodeAt(o);return i},bt=e=>{let t=e??"",r=[],n=0;return t.length>=8?n++:r.push("Use at least 8 characters"),/[a-z]/.test(t)?n++:r.push("Add lowercase letters"),/[A-Z]/.test(t)?n++:r.push("Add uppercase letters"),/\d/.test(t)?n++:r.push("Include numbers"),/[^A-Za-z0-9]/.test(t)?n++:r.push("Add special characters (e.g. !, @, #)"),{score:n,result:n<=2?"Weak":n==3?"Moderate":n==4?"Strong":"Excellent",suggestion:r}},le=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),xt=(e,t)=>{if(t.length===0)return e.trim();let r=t.map(s=>s.trim()).filter(Boolean).map(le);if(r.length===0)return e.trim();let n=new RegExp(`\\b(${r.join("|")})\\b`,"gi");return e.replace(n,"").replace(/\s+/g," ").trim()},wt=(e,t=false)=>{let r=A__default.default.get(e);return r?t?JSON.parse(r):r:null},Tt=e=>A__default.default.remove(e),At=({key:e,value:t,json:r=false,path:n="/",expires:s,domain:i,secure:o,sameSite:c})=>{try{A__default.default.set(e,r||typeof t=="object"?JSON.stringify(t):t,{expires:s,path:n,domain:i,secure:o,sameSite:c});}catch(a){console.log("--- Error setting cookie",a);}};exports.MD5=Me;exports.PubSub=J;exports.SORT=V;exports._=$;exports.__SALT=G;exports.arrayRand=st;exports.camelCase=ut;exports.camelCaseToDash=lt;exports.checkPasswordStrength=bt;exports.clamp=pt;exports.copyToClipboard=at;exports.enumToKeys=ft;exports.escapeRegex=le;exports.exists=ht;exports.formatNumber=ot;exports.formatSize=it;exports.fromHash=He;exports.generateColorHex=Ke;exports.generatePalette=Ze;exports.getCancelToken=Ve;exports.getContrastColor=K;exports.getCookie=wt;exports.hexToHsl=ie;exports.hexToRgba=Fe;exports.isColor=Be;exports.isColorName=Ue;exports.isHexColor=ne;exports.isHslColor=oe;exports.isRgbaColor=se;exports.natsort=ct;exports.numberInRange=te;exports.pluralize=Le;exports.removeCookie=Tt;exports.removeDuplicateWords=Ge;exports.removeDuplicates=ae;exports.removeWords=xt;exports.setCookie=At;exports.sleep=gt;exports.slugify=dt;exports.time=rt;exports.timeSince=nt;exports.toHash=re;exports.ucfirst=F;exports.urlBase64ToUint8Array=yt;exports.urldecode=Ie;exports.urlencode=ze;exports.uuid=qe;exports.uuid2=We;exports.withCredentials=Ye;exports.withDelay=mt;exports.withGet=Qe;exports.withPatch=et;exports.withPost=Je;exports.withPut=Xe;exports.withTime=tt;
package/dist/index.d.cts CHANGED
@@ -135,6 +135,45 @@ declare const isHslColor: (color: string) => boolean;
135
135
  declare const isColorName: (color: string) => boolean;
136
136
  declare const isColor: (color: string) => boolean;
137
137
  declare const hexToRgba: (hex: string, alpha?: number) => string;
138
+ /**
139
+ * Generates a unique, incremental hex color based on the current timestamp.
140
+ * Using a golden ratio multiplier helps spread the colors across the
141
+ * spectrum so sequential colors aren't just "slightly darker/lighter".
142
+ */
143
+ declare const generateColorHex: () => string;
144
+ /**
145
+ * Converts Hex to HSL with flexible output formats.
146
+ * @param hex - The color string (e.g., "#ff0000" or "ff0000")
147
+ * @param format - 'object' (default) or 'string' for CSS hsl()
148
+ */
149
+ type HSLObject = {
150
+ h: number;
151
+ s: number;
152
+ l: number;
153
+ };
154
+ declare function hexToHsl(hex: string, format: 'object'): HSLObject;
155
+ declare function hexToHsl(hex: string, format: 'string'): string;
156
+ /**
157
+ * Returns either #FFFFFF or a dark neutral #1A1A1A
158
+ * based on the background color's brightness.
159
+ */
160
+ declare const getContrastColor: (hex: string) => string;
161
+ /**
162
+ * Generates a functional UI palette based on a single seed color.
163
+ * Uses HSL manipulation to ensure visual harmony.
164
+ */
165
+ declare const generatePalette: (seedHex: string) => {
166
+ primary: string;
167
+ onPrimary: string;
168
+ background: string;
169
+ surface: string;
170
+ foreground: string;
171
+ muted: string;
172
+ border: string;
173
+ hover: string;
174
+ active: string;
175
+ ghost: string;
176
+ };
138
177
  declare const removeDuplicates: <T>(array: T[]) => T[];
139
178
  declare const removeDuplicateWords: (text: string) => string;
140
179
  declare const getCancelToken: () => CancelTokenSource;
@@ -193,4 +232,4 @@ declare const setCookie: ({ key, value, json, path, expires, domain, secure, sam
193
232
  sameSite?: "strict" | "Strict" | "lax" | "Lax" | "none" | "None" | undefined;
194
233
  }) => void;
195
234
 
196
- export { _ as "_", type EventListener, type FormatNumberParams, MD5, Events as PubSub, SORT, type WithHttpOptions, __SALT, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, escapeRegex, exists, formatNumber, formatSize, fromHash, getCancelToken, getCookie, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeCookie, removeDuplicateWords, removeDuplicates, removeWords, setCookie, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, uuid2, withCredentials, withDelay, withGet, withPatch, withPost, withPut, withTime };
235
+ export { _ as "_", type EventListener, type FormatNumberParams, type HSLObject, MD5, Events as PubSub, SORT, type WithHttpOptions, __SALT, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, escapeRegex, exists, formatNumber, formatSize, fromHash, generateColorHex, generatePalette, getCancelToken, getContrastColor, getCookie, hexToHsl, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeCookie, removeDuplicateWords, removeDuplicates, removeWords, setCookie, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, uuid2, withCredentials, withDelay, withGet, withPatch, withPost, withPut, withTime };
package/dist/index.d.ts CHANGED
@@ -135,6 +135,45 @@ declare const isHslColor: (color: string) => boolean;
135
135
  declare const isColorName: (color: string) => boolean;
136
136
  declare const isColor: (color: string) => boolean;
137
137
  declare const hexToRgba: (hex: string, alpha?: number) => string;
138
+ /**
139
+ * Generates a unique, incremental hex color based on the current timestamp.
140
+ * Using a golden ratio multiplier helps spread the colors across the
141
+ * spectrum so sequential colors aren't just "slightly darker/lighter".
142
+ */
143
+ declare const generateColorHex: () => string;
144
+ /**
145
+ * Converts Hex to HSL with flexible output formats.
146
+ * @param hex - The color string (e.g., "#ff0000" or "ff0000")
147
+ * @param format - 'object' (default) or 'string' for CSS hsl()
148
+ */
149
+ type HSLObject = {
150
+ h: number;
151
+ s: number;
152
+ l: number;
153
+ };
154
+ declare function hexToHsl(hex: string, format: 'object'): HSLObject;
155
+ declare function hexToHsl(hex: string, format: 'string'): string;
156
+ /**
157
+ * Returns either #FFFFFF or a dark neutral #1A1A1A
158
+ * based on the background color's brightness.
159
+ */
160
+ declare const getContrastColor: (hex: string) => string;
161
+ /**
162
+ * Generates a functional UI palette based on a single seed color.
163
+ * Uses HSL manipulation to ensure visual harmony.
164
+ */
165
+ declare const generatePalette: (seedHex: string) => {
166
+ primary: string;
167
+ onPrimary: string;
168
+ background: string;
169
+ surface: string;
170
+ foreground: string;
171
+ muted: string;
172
+ border: string;
173
+ hover: string;
174
+ active: string;
175
+ ghost: string;
176
+ };
138
177
  declare const removeDuplicates: <T>(array: T[]) => T[];
139
178
  declare const removeDuplicateWords: (text: string) => string;
140
179
  declare const getCancelToken: () => CancelTokenSource;
@@ -193,4 +232,4 @@ declare const setCookie: ({ key, value, json, path, expires, domain, secure, sam
193
232
  sameSite?: "strict" | "Strict" | "lax" | "Lax" | "none" | "None" | undefined;
194
233
  }) => void;
195
234
 
196
- export { _ as "_", type EventListener, type FormatNumberParams, MD5, Events as PubSub, SORT, type WithHttpOptions, __SALT, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, escapeRegex, exists, formatNumber, formatSize, fromHash, getCancelToken, getCookie, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeCookie, removeDuplicateWords, removeDuplicates, removeWords, setCookie, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, uuid2, withCredentials, withDelay, withGet, withPatch, withPost, withPut, withTime };
235
+ export { _ as "_", type EventListener, type FormatNumberParams, type HSLObject, MD5, Events as PubSub, SORT, type WithHttpOptions, __SALT, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, escapeRegex, exists, formatNumber, formatSize, fromHash, generateColorHex, generatePalette, getCancelToken, getContrastColor, getCookie, hexToHsl, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeCookie, removeDuplicateWords, removeDuplicates, removeWords, setCookie, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, uuid2, withCredentials, withDelay, withGet, withPatch, withPost, withPut, withTime };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import O from'axios';import Q from'fs/promises';import Z from'hashids';import A from'js-cookie';import X from'md5';import d from'moment';import {nanoid}from'nanoid';import I from'ip-regex';var L=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];var U=/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/,B=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/,F=/^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;var V=(r=>(r.Asc="ASC",r.Desc="DESC",r))(V||{});var S=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return I.v4({exact:true}).test(this._)}isIPv6(){return I.v6({exact:true}).test(this._)}isTypeof(t){return typeof this._==typeof t}isFunction(){return typeof this._=="function"}isArray(){return Array.isArray(this._)}isNull(){return this._===null}isString(){return typeof this._=="string"}isNumber(){return /^[+-]?\d+(\.\d+)?$/.test(this._)}isObject(){return typeof this._=="object"&&!Array.isArray(this._)&&this._!==null}isEmpty(){return Array.isArray(this._)?this._.length===0:typeof this._=="object"&&this._!==null?Object.keys(this._).length===0:this._===""||String(this._).length===0}isEmail(){return typeof this._=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(decodeURIComponent(this._))}isUrl(){return typeof this._=="string"&&/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/.test(this._)}toLowerCase(){return this._=typeof this._=="string"?this._.toLowerCase():String(this._).toLowerCase(),this}equals(t){let r=this._,n=t,o=(s,u)=>{if(s===u)return true;if(s===null||typeof s!="object"||u===null||typeof u!="object")return false;if(Array.isArray(s)&&Array.isArray(u)){if(s.length!==u.length)return false;for(let a=0;a<s.length;a++)if(!o(s[a],u[a]))return false;return true}if(this.isObjectValue(s)&&this.isObjectValue(u)){let a=Object.keys(s),c=Object.keys(u);if(a.length!==c.length)return false;for(let h of a)if(!c.includes(h)||!o(s[h],u[h]))return false;return true}return false},i=s=>typeof s=="object"&&s!==null&&!Array.isArray(s);return this.isObjectValue=i,Array.isArray(r)&&Array.isArray(n)||i(r)&&i(n)?o(r,n):r===n}isObjectValue(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}ucfirst(){return this._=typeof this._=="string"?this._.charAt(0).toUpperCase()+this._.slice(1):this._,this}formatString(t,...r){typeof this._!="string"&&(this._="");let n=[t,...r];return this._=this._.replace(/%(\d+)/g,(o,i)=>n[Number(i)]?.toString()||`%${i}`),this}camelCase(){return this._=typeof this._=="string"?this._.split(/[^a-zA-Z0-9]+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join(""):this._,this}sort(t="asc"){if(!this.isObject())return console.warn("sortKeys can only be applied to objects. Current value is not an object."),this;let r=this._,n=Object.keys(r).sort((i,s)=>t==="desc"?s.localeCompare(i):i.localeCompare(s)),o={};for(let i of n)o[i]=r[i];return this._=o,this}value(){return this._}valueOf(){return this._}toString(){return String(this._)}[Symbol.toPrimitive](t){return t==="number"?Number(this._):t==="boolean"?!!this._:String(this._)}},Y=e=>new S(e),N=Y;var E=class{_events;constructor(){this._events=[];}on(t,r,n){let o=this._events.find(u=>u.event===t),i=Symbol("listener_id"),s={fun:r,context:n,id:i};return o?o.listeners.push(s):this._events.push({event:t,listeners:[s]}),()=>{let u=this._events.find(a=>a.event===t);u&&(u.listeners=u.listeners.filter(a=>a.id!==i),u.listeners.length===0&&(this._events=this._events.filter(a=>a.event!==t)));}}off(t,r){let n=this._events.find(o=>o.event===t);n&&(n.listeners=n.listeners.filter(o=>o.fun!==r),n.listeners.length===0&&(this._events=this._events.filter(o=>o.event!==t)));}emit(t,...r){let n=this._events.find(o=>o.event===t);n&&[...n.listeners].forEach(({fun:o,context:i})=>{try{o.apply(i,r);}catch(s){console.error(`Error during event '${String(t)}' emission:`,s);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},J=E;var G="zuzjs-core",te=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,re=(e,t=6,r=null)=>new Z(r||G,t).encode(e),De=(e,t=null)=>{try{let r=new Z(t||G,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},He=e=>X(e),qe=e=>re(te(11111111111,999999999999)),We=e=>nanoid(e),K=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,ze=e=>decodeURIComponent(e.replace(/\+/g,"%20")),Me=e=>encodeURIComponent(e),Le=(e,t)=>`${e}${t!==1?"s":""}`,ne=e=>U.test(e),se=e=>B.test(e),oe=e=>F.test(e),Ue=e=>L.includes(e.toLowerCase()),Be=e=>ne(e)||se(e)||oe(e),Fe=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(s=>s+s).join(""));let r=parseInt(e,16),n=r>>16&255,o=r>>8&255,i=r&255;return `rgba(${n}, ${o}, ${i}, ${t})`},ie=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),Ie=e=>{if(!e.trim())return "";let t=e.split(/\s+/).filter(Boolean);return ie(t).join(" ")},Ke=()=>O.CancelToken.source(),Ze=e=>O.defaults.withCredentials=e,ae=e=>{let r=typeof navigator<"u"?navigator.onLine:true;return {error:e?.code??"ERR_NETWORK",message:r?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}},v=(e=60,t=false,r={},n)=>typeof e=="object"&&e!==null?{timeout:e.timeout??60,ignoreKind:e.ignoreKind??false,headers:e.headers??{},onProgress:e.onProgress,withCredentials:e.withCredentials,returnRawResponse:e.returnRawResponse,appendCookiesToBody:e.appendCookiesToBody??true,appendTimestamp:e.appendTimestamp??true}:{timeout:e,ignoreKind:t,headers:r,onProgress:n,appendCookiesToBody:true,appendTimestamp:true},j=(e,t)=>{let r=A.get(),n=e,o="application/json";if(e instanceof FormData){if(o="multipart/form-data",t.appendCookiesToBody)for(let[i,s]of Object.entries(r))e.append(i,s);}else if(typeof e=="object"&&!Array.isArray(e)&&e!==null)n={...e,...t.appendCookiesToBody?r:{},...t.appendTimestamp?{__stmp:Date.now()/1e3}:{}};else if(!N(e).isString())throw new Error("Unsupported data type for withPost/withPut/withPatch");return {finalData:n,contentType:o}},ue=(e,t)=>{if(t.returnRawResponse)return e;if(e.data&&(t.ignoreKind||"kind"in e.data))return e.data;throw e.data},C=async(e,t)=>{try{let r=await O(e);return ue(r,t)}catch(r){throw r?.response?.data?r.response.data:r?.code==="ERR_NETWORK"?ae(r):r}};async function Ge(e,t,r=60,n=false,o={},i){let s=v(r,n,o,i),{finalData:u,contentType:a}=j(t,s);return C({method:"post",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}async function Ve(e,t=60,r=false,n={}){let o=v(t,r,n);return C({method:"get",url:e,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:o.headers},o)}async function Ye(e,t,r=60,n=false,o={},i){let s=v(r,n,o,i),{finalData:u,contentType:a}=j(t,s);return C({method:"put",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}async function Je(e,t,r=60,n=false,o={},i){let s=v(r,n,o,i),{finalData:u,contentType:a}=j(t,s);return C({method:"patch",url:e,data:u,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:{"Content-Type":a,...s.headers??{}},onUploadProgress:s.onProgress},s)}var Qe=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},Xe=(e,t)=>{let r=t||"YYYY-MM-DD HH:mm:ss";if(!e)return d().format(r);if(e instanceof Date)return d(e).format(r);if(typeof e=="string"&&isNaN(Number(e)))return d(e).format(r);let n=Number(e);return n>9999999999?d(n).format(r):d.unix(n).format(r)},et=e=>{if(e instanceof Date)return d(e).fromNow();if(typeof e=="string"&&isNaN(Number(e)))return d(e).fromNow();let t=Number(e);return t>9999999999?d(t).fromNow():d.unix(t).fromNow()},tt=e=>e[Math.floor(Math.random()*e.length)],rt=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:o=false,currency:i})=>{if(r==="currency"&&!i)throw new TypeError("Currency code is required with currency style.");if(i){let{code:s,style:u,symbol:a}=i,c=new Intl.NumberFormat(t,{style:"currency",currency:s,currencyDisplay:u,minimumFractionDigits:o||+e%1>0?n:0,maximumFractionDigits:o||+e%1>0?n:0}).format(+e);return a?c.replace(new RegExp(`\\${s}`,"g"),a):c}return new Intl.NumberFormat(t,{style:r,minimumFractionDigits:o?n:+e%1>0?2:0,maximumFractionDigits:o?n:+e%1>0?2:0}).format(+e)},nt=e=>{let t=["Bytes","KB","MB","GB","TB"],r=typeof e=="string"?parseFloat(e):e;if(r==0)return "0 Byte";let n=Math.floor(Math.log(r)/Math.log(1024)),o=typeof n=="string"?parseInt(n):n;return (r/Math.pow(1024,o)).toFixed(2)+" "+t[o]},st=e=>navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(e):new Promise((t,r)=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",document.body.appendChild(n),n.focus(),n.select();try{document.execCommand("copy"),t("Copied to clipboard");}catch(o){r(o);}document.body.removeChild(n);}),ot=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,o=/[^\x00-\x80]/,i=/^0x[0-9a-f]+$/i,s=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,u=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=e.direction=="DESC"?-1:1,c=-a,h=e.caseSensitive?l=>`${l}`.replace(n,""):l=>l.toString().toLowerCase().replace(n,""),$=l=>l.replace(s,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),D=(l,R)=>(!l.match(t)||R===1)&&parseFloat(l)||l.replace(r," ").replace(n,"")||0;return function(l,R){let f=h(l),g=h(R);if(!f&&!g)return 0;if(!f&&g)return c;if(f&&!g)return a;let _=$(f),H=$(g),k=f.match(i),P=g.match(i),y=k&&P?parseInt(k[0],16):_.length!==1&&Date.parse(f),b=k&&P?parseInt(P[0],16):y&&g.match(u)&&Date.parse(g)||null;if(b){if(y===b)return 0;if(typeof y=="number"&&typeof b=="number"&&y<b)return c;if(typeof y=="number"&&y>b)return a}let q=_.length,W=H.length;for(let x=0,z=Math.max(q,W);x<z;x+=1){let p=D(_[x]||"",q),m=D(H[x]||"",W);if(isNaN(p)!==isNaN(m))return isNaN(p)?a:c;if(o.test(p+m)&&p.localeCompare){let M=p.localeCompare(m);if(M>0)return a;if(M<0)return c;if(x===z-1)return 0}if(p<m)return c;if(p>m)return a;if(`${p}`<`${m}`)return c;if(`${p}`>`${m}`)return a}return 0}},it=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?K(r):r:K(r)).join(""),at=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),ut=(e,t,r)=>Math.min(Math.max(e,t),r),ct=(e,t="-")=>e==null?(console.log(e,"is undefined"),""):e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\p{L}\p{N}]+/gu,t).replace(new RegExp(`\\${t}{2,}`,"g"),t).replace(new RegExp(`^\\${t}|\\${t}$`,"g"),""),lt=e=>new Promise(t=>setTimeout(t,e)),pt=(e,t)=>setTimeout(e,t||1e3),dt=e=>Object.keys(e).filter(t=>isNaN(Number(t))),gt=async e=>{try{return await Q.access(e),!0}catch{return false}},mt=e=>{let t=(e??"").trim();if(t.length===0)return new Uint8Array(0);let r="=".repeat((4-t.length%4)%4),n=(t+r).replace(/-/g,"+").replace(/_/g,"/"),o=window.atob(n),i=new Uint8Array(o.length);for(let s=0;s<o.length;++s)i[s]=o.charCodeAt(s);return i},ht=e=>{let t=e??"",r=[],n=0;return t.length>=8?n++:r.push("Use at least 8 characters"),/[a-z]/.test(t)?n++:r.push("Add lowercase letters"),/[A-Z]/.test(t)?n++:r.push("Add uppercase letters"),/\d/.test(t)?n++:r.push("Include numbers"),/[^A-Za-z0-9]/.test(t)?n++:r.push("Add special characters (e.g. !, @, #)"),{score:n,result:n<=2?"Weak":n==3?"Moderate":n==4?"Strong":"Excellent",suggestion:r}},ce=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ft=(e,t)=>{if(t.length===0)return e.trim();let r=t.map(o=>o.trim()).filter(Boolean).map(ce);if(r.length===0)return e.trim();let n=new RegExp(`\\b(${r.join("|")})\\b`,"gi");return e.replace(n,"").replace(/\s+/g," ").trim()},yt=(e,t=false)=>{let r=A.get(e);return r?t?JSON.parse(r):r:null},bt=e=>A.remove(e),xt=({key:e,value:t,json:r=false,path:n="/",expires:o,domain:i,secure:s,sameSite:u})=>{try{A.set(e,r||typeof t=="object"?JSON.stringify(t):t,{expires:o,path:n,domain:i,secure:s,sameSite:u});}catch(a){console.log("--- Error setting cookie",a);}};export{He as MD5,J as PubSub,V as SORT,N as _,G as __SALT,tt as arrayRand,it as camelCase,at as camelCaseToDash,ht as checkPasswordStrength,ut as clamp,st as copyToClipboard,dt as enumToKeys,ce as escapeRegex,gt as exists,rt as formatNumber,nt as formatSize,De as fromHash,Ke as getCancelToken,yt as getCookie,Fe as hexToRgba,Be as isColor,Ue as isColorName,ne as isHexColor,oe as isHslColor,se as isRgbaColor,ot as natsort,te as numberInRange,Le as pluralize,bt as removeCookie,Ie as removeDuplicateWords,ie as removeDuplicates,ft as removeWords,xt as setCookie,lt as sleep,ct as slugify,Xe as time,et as timeSince,re as toHash,K as ucfirst,mt as urlBase64ToUint8Array,ze as urldecode,Me as urlencode,qe as uuid,We as uuid2,Ze as withCredentials,pt as withDelay,Ve as withGet,Je as withPatch,Ge as withPost,Ye as withPut,Qe as withTime};
1
+ import j from'axios';import X from'fs/promises';import G from'hashids';import v from'js-cookie';import ee from'md5';import m from'moment';import {nanoid}from'nanoid';import F from'ip-regex';var z=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];var L=/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/,U=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/,B=/^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;var Y=(r=>(r.Asc="ASC",r.Desc="DESC",r))(Y||{});var $=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return F.v4({exact:true}).test(this._)}isIPv6(){return F.v6({exact:true}).test(this._)}isTypeof(t){return typeof this._==typeof t}isFunction(){return typeof this._=="function"}isArray(){return Array.isArray(this._)}isNull(){return this._===null}isString(){return typeof this._=="string"}isNumber(){return /^[+-]?\d+(\.\d+)?$/.test(this._)}isObject(){return typeof this._=="object"&&!Array.isArray(this._)&&this._!==null}isEmpty(){return Array.isArray(this._)?this._.length===0:typeof this._=="object"&&this._!==null?Object.keys(this._).length===0:this._===""||String(this._).length===0}isEmail(){return typeof this._=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(decodeURIComponent(this._))}isUrl(){return typeof this._=="string"&&/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/.test(this._)}toLowerCase(){return this._=typeof this._=="string"?this._.toLowerCase():String(this._).toLowerCase(),this}equals(t){let r=this._,n=t,s=(o,c)=>{if(o===c)return true;if(o===null||typeof o!="object"||c===null||typeof c!="object")return false;if(Array.isArray(o)&&Array.isArray(c)){if(o.length!==c.length)return false;for(let a=0;a<o.length;a++)if(!s(o[a],c[a]))return false;return true}if(this.isObjectValue(o)&&this.isObjectValue(c)){let a=Object.keys(o),u=Object.keys(c);if(a.length!==u.length)return false;for(let l of a)if(!u.includes(l)||!s(o[l],c[l]))return false;return true}return false},i=o=>typeof o=="object"&&o!==null&&!Array.isArray(o);return this.isObjectValue=i,Array.isArray(r)&&Array.isArray(n)||i(r)&&i(n)?s(r,n):r===n}isObjectValue(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}ucfirst(){return this._=typeof this._=="string"?this._.charAt(0).toUpperCase()+this._.slice(1):this._,this}formatString(t,...r){typeof this._!="string"&&(this._="");let n=[t,...r];return this._=this._.replace(/%(\d+)/g,(s,i)=>n[Number(i)]?.toString()||`%${i}`),this}camelCase(){return this._=typeof this._=="string"?this._.split(/[^a-zA-Z0-9]+/).map((t,r)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)).join(""):this._,this}sort(t="asc"){if(!this.isObject())return console.warn("sortKeys can only be applied to objects. Current value is not an object."),this;let r=this._,n=Object.keys(r).sort((i,o)=>t==="desc"?o.localeCompare(i):i.localeCompare(o)),s={};for(let i of n)s[i]=r[i];return this._=s,this}value(){return this._}valueOf(){return this._}toString(){return String(this._)}[Symbol.toPrimitive](t){return t==="number"?Number(this._):t==="boolean"?!!this._:String(this._)}},J=e=>new $(e),N=J;var O=class{_events;constructor(){this._events=[];}on(t,r,n){let s=this._events.find(c=>c.event===t),i=Symbol("listener_id"),o={fun:r,context:n,id:i};return s?s.listeners.push(o):this._events.push({event:t,listeners:[o]}),()=>{let c=this._events.find(a=>a.event===t);c&&(c.listeners=c.listeners.filter(a=>a.id!==i),c.listeners.length===0&&(this._events=this._events.filter(a=>a.event!==t)));}}off(t,r){let n=this._events.find(s=>s.event===t);n&&(n.listeners=n.listeners.filter(s=>s.fun!==r),n.listeners.length===0&&(this._events=this._events.filter(s=>s.event!==t)));}emit(t,...r){let n=this._events.find(s=>s.event===t);n&&[...n.listeners].forEach(({fun:s,context:i})=>{try{s.apply(i,r);}catch(o){console.error(`Error during event '${String(t)}' emission:`,o);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},Q=O;var V="zuzjs-core",re=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,ne=(e,t=6,r=null)=>new G(r||V,t).encode(e),Me=(e,t=null)=>{try{let r=new G(t||V,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},qe=e=>ee(e),We=e=>ne(re(11111111111,999999999999)),Ie=e=>nanoid(e),K=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,ze=e=>decodeURIComponent(e.replace(/\+/g,"%20")),Le=e=>encodeURIComponent(e),Ue=(e,t)=>`${e}${t!==1?"s":""}`,se=e=>L.test(e),oe=e=>U.test(e),ie=e=>B.test(e),Be=e=>z.includes(e.toLowerCase()),Fe=e=>se(e)||oe(e)||ie(e),Ke=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(o=>o+o).join(""));let r=parseInt(e,16),n=r>>16&255,s=r>>8&255,i=r&255;return `rgba(${n}, ${s}, ${i}, ${t})`},Ze=()=>{let e=typeof window<"u"?performance.now():Date.now();return `#${(Math.floor(e*2654435769)&16777215).toString(16).padStart(6,"0")}`};function ae(e,t="string"){e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(p=>p+p).join(""));let r=parseInt(e.substring(0,2),16)/255,n=parseInt(e.substring(2,4),16)/255,s=parseInt(e.substring(4,6),16)/255,i=Math.max(r,n,s),o=Math.min(r,n,s),c=0,a=0,u=(i+o)/2;if(i!==o){let p=i-o;switch(a=u>.5?p/(2-i-o):p/(i+o),i){case r:c=(n-s)/p+(n<s?6:0);break;case n:c=(s-r)/p+2;break;case s:c=(r-n)/p+4;break}c/=6;}let l={h:Math.round(c*360),s:Math.round(a*100),l:Math.round(u*100)};return t==="string"?`hsl(${l.h}, ${l.s}%, ${l.l}%)`:l}var Z=e=>{let t=e.replace(/^#/,""),r=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),s=parseInt(t.substring(4,6),16);return (r*299+n*587+s*114)/1e3>=128?"#1a1a1a":"#ffffff"},Ge=e=>{let t=ae(e,"object"),r=Z(e)==="#ffffff",n=(s=0,i=0,o=0,c=1)=>{let a=(t.h+s+360)%360,u=Math.min(100,Math.max(0,t.s+i)),l=Math.min(100,Math.max(0,t.l+o));return c===1?`hsl(${a}, ${u}%, ${l}%)`:`hsla(${a}, ${u}%, ${l}%, ${c})`};return {primary:e,onPrimary:Z(e),background:r?n(0,-10,-40):n(0,-20,45),surface:r?n(0,-5,-35):n(0,-15,40),foreground:r?"#ffffff":"#1a1a1a",muted:r?n(0,-20,20,.7):n(0,-20,-30,.6),border:r?n(0,0,10,.2):n(0,0,-10,.1),hover:n(0,0,r?10:-10),active:n(0,0,r?-5:5),ghost:n(0,0,0,.12)}},ce=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),Ve=e=>{if(!e.trim())return "";let t=e.split(/\s+/).filter(Boolean);return ce(t).join(" ")},Ye=()=>j.CancelToken.source(),Je=e=>j.defaults.withCredentials=e,ue=e=>{let r=typeof navigator<"u"?navigator.onLine:true;return {error:e?.code??"ERR_NETWORK",message:r?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}},C=(e=60,t=false,r={},n)=>typeof e=="object"&&e!==null?{timeout:e.timeout??60,ignoreKind:e.ignoreKind??false,headers:e.headers??{},onProgress:e.onProgress,withCredentials:e.withCredentials,returnRawResponse:e.returnRawResponse,appendCookiesToBody:e.appendCookiesToBody??true,appendTimestamp:e.appendTimestamp??true}:{timeout:e,ignoreKind:t,headers:r,onProgress:n,appendCookiesToBody:true,appendTimestamp:true},E=(e,t)=>{let r=v.get(),n=e,s="application/json";if(e instanceof FormData){if(s="multipart/form-data",t.appendCookiesToBody)for(let[i,o]of Object.entries(r))e.append(i,o);}else if(typeof e=="object"&&!Array.isArray(e)&&e!==null)n={...e,...t.appendCookiesToBody?r:{},...t.appendTimestamp?{__stmp:Date.now()/1e3}:{}};else if(!N(e).isString())throw new Error("Unsupported data type for withPost/withPut/withPatch");return {finalData:n,contentType:s}},le=(e,t)=>{if(t.returnRawResponse)return e;if(e.data&&(t.ignoreKind||"kind"in e.data))return e.data;throw e.data},R=async(e,t)=>{try{let r=await j(e);return le(r,t)}catch(r){throw r?.response?.data?r.response.data:r?.code==="ERR_NETWORK"?ue(r):r}};async function Qe(e,t,r=60,n=false,s={},i){let o=C(r,n,s,i),{finalData:c,contentType:a}=E(t,o);return R({method:"post",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}async function Xe(e,t=60,r=false,n={}){let s=C(t,r,n);return R({method:"get",url:e,timeout:s.timeout*1e3,withCredentials:s.withCredentials,headers:s.headers},s)}async function et(e,t,r=60,n=false,s={},i){let o=C(r,n,s,i),{finalData:c,contentType:a}=E(t,o);return R({method:"put",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}async function tt(e,t,r=60,n=false,s={},i){let o=C(r,n,s,i),{finalData:c,contentType:a}=E(t,o);return R({method:"patch",url:e,data:c,timeout:o.timeout*1e3,withCredentials:o.withCredentials,headers:{"Content-Type":a,...o.headers??{}},onUploadProgress:o.onProgress},o)}var rt=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},nt=(e,t)=>{let r=t||"YYYY-MM-DD HH:mm:ss";if(!e)return m().format(r);if(e instanceof Date)return m(e).format(r);if(typeof e=="string"&&isNaN(Number(e)))return m(e).format(r);let n=Number(e);return n>9999999999?m(n).format(r):m.unix(n).format(r)},st=e=>{if(e instanceof Date)return m(e).fromNow();if(typeof e=="string"&&isNaN(Number(e)))return m(e).fromNow();let t=Number(e);return t>9999999999?m(t).fromNow():m.unix(t).fromNow()},ot=e=>e[Math.floor(Math.random()*e.length)],it=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:s=false,currency:i})=>{if(r==="currency"&&!i)throw new TypeError("Currency code is required with currency style.");if(i){let{code:o,style:c,symbol:a}=i,u=new Intl.NumberFormat(t,{style:"currency",currency:o,currencyDisplay:c,minimumFractionDigits:s||+e%1>0?n:0,maximumFractionDigits:s||+e%1>0?n:0}).format(+e);return a?u.replace(new RegExp(`\\${o}`,"g"),a):u}return new Intl.NumberFormat(t,{style:r,minimumFractionDigits:s?n:+e%1>0?2:0,maximumFractionDigits:s?n:+e%1>0?2:0}).format(+e)},at=e=>{let t=["Bytes","KB","MB","GB","TB"],r=typeof e=="string"?parseFloat(e):e;if(r==0)return "0 Byte";let n=Math.floor(Math.log(r)/Math.log(1024)),s=typeof n=="string"?parseInt(n):n;return (r/Math.pow(1024,s)).toFixed(2)+" "+t[s]},ct=e=>navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(e):new Promise((t,r)=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",document.body.appendChild(n),n.focus(),n.select();try{document.execCommand("copy"),t("Copied to clipboard");}catch(s){r(s);}document.body.removeChild(n);}),ut=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,s=/[^\x00-\x80]/,i=/^0x[0-9a-f]+$/i,o=/(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g,c=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,a=e.direction=="DESC"?-1:1,u=-a,l=e.caseSensitive?d=>`${d}`.replace(n,""):d=>d.toString().toLowerCase().replace(n,""),p=d=>d.replace(o,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),D=(d,_)=>(!d.match(t)||_===1)&&parseFloat(d)||d.replace(r," ").replace(n,"")||0;return function(d,_){let y=l(d),f=l(_);if(!y&&!f)return 0;if(!y&&f)return u;if(y&&!f)return a;let k=p(y),H=p(f),P=y.match(i),S=f.match(i),b=P&&S?parseInt(P[0],16):k.length!==1&&Date.parse(y),x=P&&S?parseInt(S[0],16):b&&f.match(c)&&Date.parse(f)||null;if(x){if(b===x)return 0;if(typeof b=="number"&&typeof x=="number"&&b<x)return u;if(typeof b=="number"&&b>x)return a}let M=k.length,q=H.length;for(let w=0,W=Math.max(M,q);w<W;w+=1){let g=D(k[w]||"",M),h=D(H[w]||"",q);if(isNaN(g)!==isNaN(h))return isNaN(g)?a:u;if(s.test(g+h)&&g.localeCompare){let I=g.localeCompare(h);if(I>0)return a;if(I<0)return u;if(w===W-1)return 0}if(g<h)return u;if(g>h)return a;if(`${g}`<`${h}`)return u;if(`${g}`>`${h}`)return a}return 0}},lt=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?K(r):r:K(r)).join(""),pt=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),dt=(e,t,r)=>Math.min(Math.max(e,t),r),gt=(e,t="-")=>e==null?(console.log(e,"is undefined"),""):e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\p{L}\p{N}]+/gu,t).replace(new RegExp(`\\${t}{2,}`,"g"),t).replace(new RegExp(`^\\${t}|\\${t}$`,"g"),""),mt=e=>new Promise(t=>setTimeout(t,e)),ft=(e,t)=>setTimeout(e,t||1e3),ht=e=>Object.keys(e).filter(t=>isNaN(Number(t))),yt=async e=>{try{return await X.access(e),!0}catch{return false}},bt=e=>{let t=(e??"").trim();if(t.length===0)return new Uint8Array(0);let r="=".repeat((4-t.length%4)%4),n=(t+r).replace(/-/g,"+").replace(/_/g,"/"),s=window.atob(n),i=new Uint8Array(s.length);for(let o=0;o<s.length;++o)i[o]=s.charCodeAt(o);return i},xt=e=>{let t=e??"",r=[],n=0;return t.length>=8?n++:r.push("Use at least 8 characters"),/[a-z]/.test(t)?n++:r.push("Add lowercase letters"),/[A-Z]/.test(t)?n++:r.push("Add uppercase letters"),/\d/.test(t)?n++:r.push("Include numbers"),/[^A-Za-z0-9]/.test(t)?n++:r.push("Add special characters (e.g. !, @, #)"),{score:n,result:n<=2?"Weak":n==3?"Moderate":n==4?"Strong":"Excellent",suggestion:r}},pe=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),wt=(e,t)=>{if(t.length===0)return e.trim();let r=t.map(s=>s.trim()).filter(Boolean).map(pe);if(r.length===0)return e.trim();let n=new RegExp(`\\b(${r.join("|")})\\b`,"gi");return e.replace(n,"").replace(/\s+/g," ").trim()},Tt=(e,t=false)=>{let r=v.get(e);return r?t?JSON.parse(r):r:null},At=e=>v.remove(e),vt=({key:e,value:t,json:r=false,path:n="/",expires:s,domain:i,secure:o,sameSite:c})=>{try{v.set(e,r||typeof t=="object"?JSON.stringify(t):t,{expires:s,path:n,domain:i,secure:o,sameSite:c});}catch(a){console.log("--- Error setting cookie",a);}};export{qe as MD5,Q as PubSub,Y as SORT,N as _,V as __SALT,ot as arrayRand,lt as camelCase,pt as camelCaseToDash,xt as checkPasswordStrength,dt as clamp,ct as copyToClipboard,ht as enumToKeys,pe as escapeRegex,yt as exists,it as formatNumber,at as formatSize,Me as fromHash,Ze as generateColorHex,Ge as generatePalette,Ye as getCancelToken,Z as getContrastColor,Tt as getCookie,ae as hexToHsl,Ke as hexToRgba,Fe as isColor,Be as isColorName,se as isHexColor,ie as isHslColor,oe as isRgbaColor,ut as natsort,re as numberInRange,Ue as pluralize,At as removeCookie,Ve as removeDuplicateWords,ce as removeDuplicates,wt as removeWords,vt as setCookie,mt as sleep,gt as slugify,nt as time,st as timeSince,ne as toHash,K as ucfirst,bt as urlBase64ToUint8Array,ze as urldecode,Le as urlencode,We as uuid,Ie as uuid2,Je as withCredentials,ft as withDelay,Xe as withGet,tt as withPatch,Qe as withPost,et as withPut,rt as withTime};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/core",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "keywords": [
5
5
  "core",
6
6
  "zuz",