@zuzjs/core 0.3.0 → 0.3.2

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 ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var w=require('axios'),Z=require('fs/promises'),H=require('hashids'),G=require('js-cookie'),W=require('md5'),E=require('moment'),react=require('react'),U=require('ip-regex');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var w__default=/*#__PURE__*/_interopDefault(w);var Z__default=/*#__PURE__*/_interopDefault(Z);var H__default=/*#__PURE__*/_interopDefault(H);var G__default=/*#__PURE__*/_interopDefault(G);var W__default=/*#__PURE__*/_interopDefault(W);var E__default=/*#__PURE__*/_interopDefault(E);var U__default=/*#__PURE__*/_interopDefault(U);/* ZuzJS Core */
2
+ var O=["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}$/,M=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/,I=/^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 C=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return U__default.default.v4({exact:true}).test(this._)}isIPv6(){return U__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"&&/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(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=(i,c)=>{if(i===c)return true;if(i===null||typeof i!="object"||c===null||typeof c!="object")return false;if(Array.isArray(i)&&Array.isArray(c)){if(i.length!==c.length)return false;for(let a=0;a<i.length;a++)if(!s(i[a],c[a]))return false;return true}if(this.isObjectValue(i)&&this.isObjectValue(c)){let a=Object.keys(i),l=Object.keys(c);if(a.length!==l.length)return false;for(let p of a)if(!l.includes(p)||!s(i[p],c[p]))return false;return true}return false},o=i=>typeof i=="object"&&i!==null&&!Array.isArray(i);return this.isObjectValue=o,Array.isArray(r)&&Array.isArray(n)||o(r)&&o(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,o)=>n[Number(o)]?.toString()||`%${o}`),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((o,i)=>t==="desc"?i.localeCompare(o):o.localeCompare(i)),s={};for(let o of n)s[o]=r[o];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._)}},K=e=>new C(e),T=K;var S=class{_events;constructor(){this._events=[];}on(t,r,n){let s=this._events.find(c=>c.event===t),o=Symbol("listener_id"),i={fun:r,context:n,id:o};return s?s.listeners.push(i):this._events.push({event:t,listeners:[i]}),()=>{let c=this._events.find(a=>a.event===t);c&&(c.listeners=c.listeners.filter(a=>a.id!==o),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:o})=>{try{s.apply(o,r);}catch(i){console.error(`Error during event '${String(t)}' emission:`,i);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},V=S;var B="zuzjs-core",X=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,ee=(e,t=6,r=null)=>new H__default.default(r||B,t).encode(e),Ne=(e,t=null)=>{try{let r=new H__default.default(t||B,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},Pe=e=>W__default.default(e),De=e=>ee(X(11111111111,999999999999)),z=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,Fe=e=>decodeURIComponent(e.replace(/\+/g,"%20")),Oe=e=>encodeURIComponent(e),Le=(e,t)=>`${e}${t!==1?"s":""}`,te=e=>L.test(e),re=e=>M.test(e),ne=e=>I.test(e),Me=e=>O.includes(e.toLowerCase()),Ie=e=>te(e)||re(e)||ne(e),Ue=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(i=>i+i).join(""));let r=parseInt(e,16),n=r>>16&255,s=r>>8&255,o=r&255;return `rgba(${n}, ${s}, ${o}, ${t})`},qe=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),ze=()=>w__default.default.CancelToken.source(),He=e=>w__default.default.defaults.withCredentials=e,Be=async(e,t,r=60,n=false,s={},o)=>{let i=G__default.default.get(),c=t,a="application/json";if(t instanceof FormData){a="multipart/form-data";for(let[l,p]of Object.entries(i))t.append(l,p);}else if(typeof t=="object"&&!Array.isArray(t)&&t!==null)c={...t,...i,__stmp:Date.now()/1e3};else if(!T(t).isString())throw new Error("Unsupported data type for withPost");try{let l=await w__default.default({method:"post",url:e,data:c,timeout:r*1e3,headers:{"Content-Type":a,...s},onUploadProgress:o});if(l.data&&(n||"kind"in l.data))return l.data;throw l.data}catch(l){throw l?.response?.data?l.response.data:l.code==="ERR_NETWORK"?{error:l.code,message:navigator.onLine?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}:l}},Ye=async(e,t=60,r=false,n={})=>{try{let s=await w__default.default.get(e,{timeout:t*1e3,headers:n});if(s.data&&(r||"kind"in s.data))return s.data;throw s.data}catch(s){throw s?.response?.data?s.response.data:s.code==="ERR_NETWORK"?{error:s.code,message:navigator.onLine?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}:s}},Ke=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},Ve=(e,t)=>e?E__default.default.unix(+e/1e3).format(t||"YYYY-MM-DD HH:mm:ss"):E__default.default().format(t||"YYYY-MM-DD HH:mm:ss"),Ze=e=>E__default.default(e).fromNow(),Ge=e=>e[Math.floor(Math.random()*e.length)],We=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:s=false,currency:o})=>{if(r==="currency"&&!o)throw new TypeError("Currency code is required with currency style.");if(o){let{code:i,style:c,symbol:a}=o,l=new Intl.NumberFormat(t,{style:"currency",currency:i,currencyDisplay:c,minimumFractionDigits:s||+e%1>0?n:0,maximumFractionDigits:s||+e%1>0?n:0}).format(+e);return a?l.replace(new RegExp(`\\${i}`,"g"),a):l}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)},Je=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]},Qe=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);}),Xe=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,s=/[^\x00-\x80]/,o=/^0x[0-9a-f]+$/i,i=/(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,l=-a,p=e.caseSensitive?u=>`${u}`.replace(n,""):u=>u.toString().toLowerCase().replace(n,""),R=u=>u.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),$=(u,_)=>(!u.match(t)||_===1)&&parseFloat(u)||u.replace(r," ").replace(n,"")||0;return function(u,_){let h=p(u),g=p(_);if(!h&&!g)return 0;if(!h&&g)return l;if(h&&!g)return a;let A=R(h),j=R(g),k=h.match(o),v=g.match(o),y=k&&v?parseInt(k[0],16):A.length!==1&&Date.parse(h),f=k&&v?parseInt(v[0],16):y&&g.match(c)&&Date.parse(g)||null;if(f){if(y===f)return 0;if(typeof y=="number"&&typeof f=="number"&&y<f)return l;if(typeof y=="number"&&y>f)return a}let N=A.length,P=j.length;for(let b=0,D=Math.max(N,P);b<D;b+=1){let m=$(A[b]||"",N),d=$(j[b]||"",P);if(isNaN(m)!==isNaN(d))return isNaN(m)?a:l;if(s.test(m+d)&&m.localeCompare){let F=m.localeCompare(d);if(F>0)return a;if(F<0)return l;if(b===D-1)return 0}if(m<d)return l;if(m>d)return a;if(`${m}`<`${d}`)return l;if(`${m}`>`${d}`)return a}return 0}},et=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?z(r):r:z(r)).join(""),tt=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),rt=(e,t,r)=>Math.min(Math.max(e,t),r),nt=(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"),""),st=(e,t,r,{lerpFactor:n=.1,threshold:s=.1,multiplier:o=1}={})=>{if(!e.current)return;let i=parseFloat(getComputedStyle(e.current).getPropertyValue(t))||0,c=r*o,a=null,l=()=>{i+=(c-i)*n,e.current&&e.current.style.setProperty(t,`${i}px`),Math.abs(c-i)>s&&(a=requestAnimationFrame(l));};a&&cancelAnimationFrame(a),requestAnimationFrame(l);},ot=e=>new Promise(t=>setTimeout(t,e)),it=e=>Object.keys(e).filter(t=>isNaN(Number(t))),at=async e=>{try{return await Z__default.default.access(e),!0}catch{return false}},lt=e=>{let t="=".repeat((4-e.length%4)%4),r=(e+t).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(r),s=new Uint8Array(n.length);for(let o=0;o<n.length;++o)s[o]=n.charCodeAt(o);return s},se=(e,t,r)=>{let n=0;return react.Children.map(e,s=>{if(react.isValidElement(s)){let o=s,i=t(o)?react.cloneElement(o,r(n++,o)):o;return o.props.children?react.cloneElement(i,{children:se(o.props.children,t,r)}):i}return s})},ct=e=>{let t=[],r=0;return e.length>=8?r++:t.push("Use at least 8 characters"),/[a-z]/.test(e)?r++:t.push("Add lowercase letters"),/[A-Z]/.test(e)?r++:t.push("Add uppercase letters"),/\d/.test(e)?r++:t.push("Include numbers"),/[^A-Za-z0-9]/.test(e)?r++:t.push("Add special characters (e.g. !, @, #)"),{score:r,result:r<=2?"Weak":r==3?"Moderate":r==4?"Strong":"Excellent",suggestion:t}};exports.MD5=Pe;exports.PubSub=V;exports.SORT=Y;exports._=T;exports.__SALT=B;exports.addPropsToChildren=se;exports.animateCSSVar=st;exports.arrayRand=Ge;exports.camelCase=et;exports.camelCaseToDash=tt;exports.checkPasswordStrength=ct;exports.clamp=rt;exports.copyToClipboard=Qe;exports.enumToKeys=it;exports.exists=at;exports.formatNumber=We;exports.formatSize=Je;exports.fromHash=Ne;exports.getCancelToken=ze;exports.hexToRgba=Ue;exports.isColor=Ie;exports.isColorName=Me;exports.isHexColor=te;exports.isHslColor=ne;exports.isRgbaColor=re;exports.natsort=Xe;exports.numberInRange=X;exports.pluralize=Le;exports.removeDuplicates=qe;exports.sleep=ot;exports.slugify=nt;exports.time=Ve;exports.timeSince=Ze;exports.toHash=ee;exports.ucfirst=z;exports.urlBase64ToUint8Array=lt;exports.urldecode=Fe;exports.urlencode=Oe;exports.uuid=De;exports.withCredentials=He;exports.withGet=Ye;exports.withPost=Be;exports.withTime=Ke;
@@ -0,0 +1,165 @@
1
+ import { CancelTokenSource, AxiosRequestConfig, AxiosProgressEvent } from 'axios';
2
+ export { CancelTokenSource, AxiosProgressEvent as UploadProgressEvent } from 'axios';
3
+ import { ReactNode, ReactElement, RefObject } from 'react';
4
+
5
+ type dynamic = {
6
+ [x: string]: any;
7
+ };
8
+ interface FormatNumberParams {
9
+ number: number | string;
10
+ locale?: string;
11
+ style?: `decimal` | `currency` | `percent`;
12
+ decimal?: number;
13
+ forceDecimal?: boolean;
14
+ currency?: {
15
+ code: string;
16
+ style: `symbol` | `code` | `name`;
17
+ symbol?: string;
18
+ };
19
+ }
20
+ declare enum SORT {
21
+ Asc = "ASC",
22
+ Desc = "DESC"
23
+ }
24
+ type sortOptions = {
25
+ direction?: SORT;
26
+ caseSensitive?: boolean;
27
+ };
28
+ interface EventListener {
29
+ fun: (...args: any[]) => void;
30
+ context?: any;
31
+ id: symbol;
32
+ }
33
+
34
+ interface Event {
35
+ event: String | Symbol;
36
+ listeners: Array<EventListener>;
37
+ }
38
+ declare class Events {
39
+ _events: Event[];
40
+ constructor();
41
+ /**
42
+ * Registers an event listener.
43
+ * @param event The name of the event.
44
+ * @param fun The callback function.
45
+ * @param context Optional context (this) for the callback.
46
+ * @returns A function to unsubscribe this specific listener.
47
+ */
48
+ on(event: String | Symbol, fun: (...args: any[]) => void, context?: any): () => void;
49
+ /**
50
+ * Removes event listeners matching a specific event and function.
51
+ * Note: This removes *all* listeners for the event that use the exact same function reference.
52
+ * It's often more reliable to use the unsubscribe function returned by 'on'.
53
+ * @param event The name of the event.
54
+ * @param fun The callback function to remove.
55
+ */
56
+ off(event: String | Symbol, fun: (...args: any[]) => void): void;
57
+ /**
58
+ * Emits an event, calling all registered listeners.
59
+ * @param event The name of the event.
60
+ * @param args Arguments to pass to the listeners.
61
+ */
62
+ emit(event: String | Symbol, ...args: any[]): void;
63
+ /**
64
+ * Removes all listeners for a specific event.
65
+ * @param event The name of the event.
66
+ */
67
+ removeAllListeners(event: String | Symbol): void;
68
+ }
69
+
70
+ declare class withGlobals {
71
+ _: any;
72
+ constructor(value: any);
73
+ isIP(): boolean;
74
+ isIPv4(): boolean;
75
+ isIPv6(): boolean;
76
+ isTypeof(v: any): boolean;
77
+ isFunction(): boolean;
78
+ isArray(): boolean;
79
+ isNull(): boolean;
80
+ isString(): boolean;
81
+ isNumber(): boolean;
82
+ isObject(): boolean;
83
+ isEmpty(): boolean;
84
+ isEmail(): boolean;
85
+ isUrl(): boolean;
86
+ toLowerCase(): this;
87
+ /**
88
+ * Performs a deep equality check for arrays and objects, otherwise a strict equality check.
89
+ * @param v The value to compare against.
90
+ * @returns {boolean} True if the values are equal, false otherwise.
91
+ */
92
+ equals(v: any): boolean;
93
+ private isObjectValue;
94
+ ucfirst(): this;
95
+ formatString(v: string | number, ...vv: (string | number)[]): this;
96
+ camelCase(): this;
97
+ /**
98
+ * Sorts the keys of the internal object in ascending or descending order.
99
+ * If the internal value is not an object, it remains unchanged.
100
+ * @param order The sort order: 'asc' for ascending (default), 'desc' for descending.
101
+ * @returns {this} The current instance for chaining.
102
+ */
103
+ sort(order?: 'asc' | 'desc'): this;
104
+ value(): any;
105
+ valueOf(): any;
106
+ toString(): string;
107
+ [Symbol.toPrimitive](hint: string): string | number | boolean;
108
+ }
109
+ declare const _: <T>(value: T) => withGlobals;
110
+
111
+ declare const __SALT: string;
112
+
113
+ declare const numberInRange: (min: number, max: number) => number;
114
+ declare const toHash: (n: number, len?: number, SALT?: string | null) => string;
115
+ declare const fromHash: (str: string, SALT?: string | null) => number;
116
+ declare const MD5: (str: string) => string;
117
+ declare const uuid: (len: number) => string;
118
+ declare const ucfirst: (o: any) => string;
119
+ declare const urldecode: (str: string) => string;
120
+ declare const urlencode: (str: string) => string;
121
+ declare const pluralize: (word: string, count: number) => string;
122
+ declare const isHexColor: (color: string) => boolean;
123
+ declare const isRgbaColor: (color: string) => boolean;
124
+ declare const isHslColor: (color: string) => boolean;
125
+ declare const isColorName: (color: string) => boolean;
126
+ declare const isColor: (color: string) => boolean;
127
+ declare const hexToRgba: (hex: string, alpha?: number) => string;
128
+ declare const removeDuplicates: <T>(array: T[]) => T[];
129
+ declare const getCancelToken: () => CancelTokenSource;
130
+ declare const withCredentials: (include: boolean) => boolean;
131
+ declare const withPost: <T>(uri: string, data: any, // 'dynamic' usually maps to 'any' or 'Record<string, any>'
132
+ timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"], onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
133
+ declare const withGet: <T>(uri: string, timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"]) => Promise<T>;
134
+ declare const withTime: (fun: (...args: any[]) => any) => {
135
+ result: any;
136
+ executionTime: number;
137
+ };
138
+ declare const time: (stamp?: number, format?: string) => string;
139
+ declare const timeSince: (stamp: number) => string;
140
+ declare const arrayRand: (arr: any[]) => any;
141
+ declare const formatNumber: ({ number, locale, style, decimal, forceDecimal, currency }: FormatNumberParams) => string;
142
+ declare const formatSize: (bytes: number | string) => string;
143
+ declare const copyToClipboard: (text: string) => Promise<unknown>;
144
+ declare const natsort: (options?: sortOptions) => (a: string | number, b: string | number) => number;
145
+ declare const camelCase: (str: string, ucf?: boolean) => string;
146
+ declare const camelCaseToDash: (str: string) => string;
147
+ declare const clamp: (value: number, min: number, max: number) => number;
148
+ declare const slugify: (text: string, separator?: string) => string;
149
+ declare const animateCSSVar: (ref: RefObject<HTMLElement>, variable: string, to: number, { lerpFactor, threshold, multiplier, }?: {
150
+ lerpFactor?: number;
151
+ threshold?: number;
152
+ multiplier?: number;
153
+ }) => void;
154
+ declare const sleep: (ms: number) => Promise<any>;
155
+ declare const enumToKeys: <T extends Record<string, any>>(obj: T) => Array<keyof T>;
156
+ declare const exists: (path: string) => Promise<boolean>;
157
+ declare const urlBase64ToUint8Array: (base64String: string) => Uint8Array;
158
+ declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, getProps: (index: number, element: ReactElement<any>) => object) => ReactNode;
159
+ declare const checkPasswordStrength: (password: string) => {
160
+ score: number;
161
+ result: string;
162
+ suggestion: string[];
163
+ };
164
+
165
+ export { _ as "_", type EventListener, type FormatNumberParams, MD5, Events as PubSub, SORT, __SALT, addPropsToChildren, animateCSSVar, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, exists, formatNumber, formatSize, fromHash, getCancelToken, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeDuplicates, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, withCredentials, withGet, withPost, withTime };
@@ -0,0 +1,165 @@
1
+ import { CancelTokenSource, AxiosRequestConfig, AxiosProgressEvent } from 'axios';
2
+ export { CancelTokenSource, AxiosProgressEvent as UploadProgressEvent } from 'axios';
3
+ import { ReactNode, ReactElement, RefObject } from 'react';
4
+
5
+ type dynamic = {
6
+ [x: string]: any;
7
+ };
8
+ interface FormatNumberParams {
9
+ number: number | string;
10
+ locale?: string;
11
+ style?: `decimal` | `currency` | `percent`;
12
+ decimal?: number;
13
+ forceDecimal?: boolean;
14
+ currency?: {
15
+ code: string;
16
+ style: `symbol` | `code` | `name`;
17
+ symbol?: string;
18
+ };
19
+ }
20
+ declare enum SORT {
21
+ Asc = "ASC",
22
+ Desc = "DESC"
23
+ }
24
+ type sortOptions = {
25
+ direction?: SORT;
26
+ caseSensitive?: boolean;
27
+ };
28
+ interface EventListener {
29
+ fun: (...args: any[]) => void;
30
+ context?: any;
31
+ id: symbol;
32
+ }
33
+
34
+ interface Event {
35
+ event: String | Symbol;
36
+ listeners: Array<EventListener>;
37
+ }
38
+ declare class Events {
39
+ _events: Event[];
40
+ constructor();
41
+ /**
42
+ * Registers an event listener.
43
+ * @param event The name of the event.
44
+ * @param fun The callback function.
45
+ * @param context Optional context (this) for the callback.
46
+ * @returns A function to unsubscribe this specific listener.
47
+ */
48
+ on(event: String | Symbol, fun: (...args: any[]) => void, context?: any): () => void;
49
+ /**
50
+ * Removes event listeners matching a specific event and function.
51
+ * Note: This removes *all* listeners for the event that use the exact same function reference.
52
+ * It's often more reliable to use the unsubscribe function returned by 'on'.
53
+ * @param event The name of the event.
54
+ * @param fun The callback function to remove.
55
+ */
56
+ off(event: String | Symbol, fun: (...args: any[]) => void): void;
57
+ /**
58
+ * Emits an event, calling all registered listeners.
59
+ * @param event The name of the event.
60
+ * @param args Arguments to pass to the listeners.
61
+ */
62
+ emit(event: String | Symbol, ...args: any[]): void;
63
+ /**
64
+ * Removes all listeners for a specific event.
65
+ * @param event The name of the event.
66
+ */
67
+ removeAllListeners(event: String | Symbol): void;
68
+ }
69
+
70
+ declare class withGlobals {
71
+ _: any;
72
+ constructor(value: any);
73
+ isIP(): boolean;
74
+ isIPv4(): boolean;
75
+ isIPv6(): boolean;
76
+ isTypeof(v: any): boolean;
77
+ isFunction(): boolean;
78
+ isArray(): boolean;
79
+ isNull(): boolean;
80
+ isString(): boolean;
81
+ isNumber(): boolean;
82
+ isObject(): boolean;
83
+ isEmpty(): boolean;
84
+ isEmail(): boolean;
85
+ isUrl(): boolean;
86
+ toLowerCase(): this;
87
+ /**
88
+ * Performs a deep equality check for arrays and objects, otherwise a strict equality check.
89
+ * @param v The value to compare against.
90
+ * @returns {boolean} True if the values are equal, false otherwise.
91
+ */
92
+ equals(v: any): boolean;
93
+ private isObjectValue;
94
+ ucfirst(): this;
95
+ formatString(v: string | number, ...vv: (string | number)[]): this;
96
+ camelCase(): this;
97
+ /**
98
+ * Sorts the keys of the internal object in ascending or descending order.
99
+ * If the internal value is not an object, it remains unchanged.
100
+ * @param order The sort order: 'asc' for ascending (default), 'desc' for descending.
101
+ * @returns {this} The current instance for chaining.
102
+ */
103
+ sort(order?: 'asc' | 'desc'): this;
104
+ value(): any;
105
+ valueOf(): any;
106
+ toString(): string;
107
+ [Symbol.toPrimitive](hint: string): string | number | boolean;
108
+ }
109
+ declare const _: <T>(value: T) => withGlobals;
110
+
111
+ declare const __SALT: string;
112
+
113
+ declare const numberInRange: (min: number, max: number) => number;
114
+ declare const toHash: (n: number, len?: number, SALT?: string | null) => string;
115
+ declare const fromHash: (str: string, SALT?: string | null) => number;
116
+ declare const MD5: (str: string) => string;
117
+ declare const uuid: (len: number) => string;
118
+ declare const ucfirst: (o: any) => string;
119
+ declare const urldecode: (str: string) => string;
120
+ declare const urlencode: (str: string) => string;
121
+ declare const pluralize: (word: string, count: number) => string;
122
+ declare const isHexColor: (color: string) => boolean;
123
+ declare const isRgbaColor: (color: string) => boolean;
124
+ declare const isHslColor: (color: string) => boolean;
125
+ declare const isColorName: (color: string) => boolean;
126
+ declare const isColor: (color: string) => boolean;
127
+ declare const hexToRgba: (hex: string, alpha?: number) => string;
128
+ declare const removeDuplicates: <T>(array: T[]) => T[];
129
+ declare const getCancelToken: () => CancelTokenSource;
130
+ declare const withCredentials: (include: boolean) => boolean;
131
+ declare const withPost: <T>(uri: string, data: any, // 'dynamic' usually maps to 'any' or 'Record<string, any>'
132
+ timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"], onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
133
+ declare const withGet: <T>(uri: string, timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"]) => Promise<T>;
134
+ declare const withTime: (fun: (...args: any[]) => any) => {
135
+ result: any;
136
+ executionTime: number;
137
+ };
138
+ declare const time: (stamp?: number, format?: string) => string;
139
+ declare const timeSince: (stamp: number) => string;
140
+ declare const arrayRand: (arr: any[]) => any;
141
+ declare const formatNumber: ({ number, locale, style, decimal, forceDecimal, currency }: FormatNumberParams) => string;
142
+ declare const formatSize: (bytes: number | string) => string;
143
+ declare const copyToClipboard: (text: string) => Promise<unknown>;
144
+ declare const natsort: (options?: sortOptions) => (a: string | number, b: string | number) => number;
145
+ declare const camelCase: (str: string, ucf?: boolean) => string;
146
+ declare const camelCaseToDash: (str: string) => string;
147
+ declare const clamp: (value: number, min: number, max: number) => number;
148
+ declare const slugify: (text: string, separator?: string) => string;
149
+ declare const animateCSSVar: (ref: RefObject<HTMLElement>, variable: string, to: number, { lerpFactor, threshold, multiplier, }?: {
150
+ lerpFactor?: number;
151
+ threshold?: number;
152
+ multiplier?: number;
153
+ }) => void;
154
+ declare const sleep: (ms: number) => Promise<any>;
155
+ declare const enumToKeys: <T extends Record<string, any>>(obj: T) => Array<keyof T>;
156
+ declare const exists: (path: string) => Promise<boolean>;
157
+ declare const urlBase64ToUint8Array: (base64String: string) => Uint8Array;
158
+ declare const addPropsToChildren: (children: ReactNode, conditions: (child: ReactElement<any>) => boolean, getProps: (index: number, element: ReactElement<any>) => object) => ReactNode;
159
+ declare const checkPasswordStrength: (password: string) => {
160
+ score: number;
161
+ result: string;
162
+ suggestion: string[];
163
+ };
164
+
165
+ export { _ as "_", type EventListener, type FormatNumberParams, MD5, Events as PubSub, SORT, __SALT, addPropsToChildren, animateCSSVar, arrayRand, camelCase, camelCaseToDash, checkPasswordStrength, clamp, copyToClipboard, type dynamic, enumToKeys, exists, formatNumber, formatSize, fromHash, getCancelToken, hexToRgba, isColor, isColorName, isHexColor, isHslColor, isRgbaColor, natsort, numberInRange, pluralize, removeDuplicates, sleep, slugify, type sortOptions, time, timeSince, toHash, ucfirst, urlBase64ToUint8Array, urldecode, urlencode, uuid, withCredentials, withGet, withPost, withTime };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import _ from'axios';import G from'fs/promises';import B from'hashids';import W from'js-cookie';import J from'md5';import R from'moment';import {Children,isValidElement,cloneElement}from'react';import q 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 M=/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/,I=/^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 K=(r=>(r.Asc="ASC",r.Desc="DESC",r))(K||{});var T=class{_;constructor(t){this._=t;}isIP(){return this.isIPv4()||this.isIPv6()}isIPv4(){return q.v4({exact:true}).test(this._)}isIPv6(){return q.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"&&/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(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=(i,c)=>{if(i===c)return true;if(i===null||typeof i!="object"||c===null||typeof c!="object")return false;if(Array.isArray(i)&&Array.isArray(c)){if(i.length!==c.length)return false;for(let a=0;a<i.length;a++)if(!s(i[a],c[a]))return false;return true}if(this.isObjectValue(i)&&this.isObjectValue(c)){let a=Object.keys(i),l=Object.keys(c);if(a.length!==l.length)return false;for(let p of a)if(!l.includes(p)||!s(i[p],c[p]))return false;return true}return false},o=i=>typeof i=="object"&&i!==null&&!Array.isArray(i);return this.isObjectValue=o,Array.isArray(r)&&Array.isArray(n)||o(r)&&o(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,o)=>n[Number(o)]?.toString()||`%${o}`),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((o,i)=>t==="desc"?i.localeCompare(o):o.localeCompare(i)),s={};for(let o of n)s[o]=r[o];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._)}},V=e=>new T(e),S=V;var E=class{_events;constructor(){this._events=[];}on(t,r,n){let s=this._events.find(c=>c.event===t),o=Symbol("listener_id"),i={fun:r,context:n,id:o};return s?s.listeners.push(i):this._events.push({event:t,listeners:[i]}),()=>{let c=this._events.find(a=>a.event===t);c&&(c.listeners=c.listeners.filter(a=>a.id!==o),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:o})=>{try{s.apply(o,r);}catch(i){console.error(`Error during event '${String(t)}' emission:`,i);}});}removeAllListeners(t){this._events=this._events.filter(r=>r.event!==t);}},Z=E;var Y="zuzjs-core",ee=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,te=(e,t=6,r=null)=>new B(r||Y,t).encode(e),Pe=(e,t=null)=>{try{let r=new B(t||Y,+process.env.HASHIDS_LENGTH).decode(e);return r.length>=0?Number(r[0]):0}catch{return 0}},De=e=>J(e),Fe=e=>te(ee(11111111111,999999999999)),H=e=>`${e.charAt(0).toUpperCase()}${e.substring(1,e.length)}`,Oe=e=>decodeURIComponent(e.replace(/\+/g,"%20")),Le=e=>encodeURIComponent(e),Me=(e,t)=>`${e}${t!==1?"s":""}`,re=e=>M.test(e),ne=e=>I.test(e),se=e=>U.test(e),Ie=e=>L.includes(e.toLowerCase()),Ue=e=>re(e)||ne(e)||se(e),qe=(e,t=1)=>{e=e.replace(/^#/,""),e.length===3&&(e=e.split("").map(i=>i+i).join(""));let r=parseInt(e,16),n=r>>16&255,s=r>>8&255,o=r&255;return `rgba(${n}, ${s}, ${o}, ${t})`},ze=e=>e.reduce((t,r)=>(t.includes(r)||t.push(r),t),[]),He=()=>_.CancelToken.source(),Be=e=>_.defaults.withCredentials=e,Ye=async(e,t,r=60,n=false,s={},o)=>{let i=W.get(),c=t,a="application/json";if(t instanceof FormData){a="multipart/form-data";for(let[l,p]of Object.entries(i))t.append(l,p);}else if(typeof t=="object"&&!Array.isArray(t)&&t!==null)c={...t,...i,__stmp:Date.now()/1e3};else if(!S(t).isString())throw new Error("Unsupported data type for withPost");try{let l=await _({method:"post",url:e,data:c,timeout:r*1e3,headers:{"Content-Type":a,...s},onUploadProgress:o});if(l.data&&(n||"kind"in l.data))return l.data;throw l.data}catch(l){throw l?.response?.data?l.response.data:l.code==="ERR_NETWORK"?{error:l.code,message:navigator.onLine?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}:l}},Ke=async(e,t=60,r=false,n={})=>{try{let s=await _.get(e,{timeout:t*1e3,headers:n});if(s.data&&(r||"kind"in s.data))return s.data;throw s.data}catch(s){throw s?.response?.data?s.response.data:s.code==="ERR_NETWORK"?{error:s.code,message:navigator.onLine?"Unable to connect to the server. It may be temporarily down.":"Network error: Unable to connect. Please check your internet connection and try again."}:s}},Ve=e=>{let t=new Date().getTime(),r=e(),n=new Date().getTime();return {result:r,executionTime:n-t}},Ze=(e,t)=>e?R.unix(+e/1e3).format(t||"YYYY-MM-DD HH:mm:ss"):R().format(t||"YYYY-MM-DD HH:mm:ss"),Ge=e=>R(e).fromNow(),We=e=>e[Math.floor(Math.random()*e.length)],Je=({number:e,locale:t="en-US",style:r="decimal",decimal:n=2,forceDecimal:s=false,currency:o})=>{if(r==="currency"&&!o)throw new TypeError("Currency code is required with currency style.");if(o){let{code:i,style:c,symbol:a}=o,l=new Intl.NumberFormat(t,{style:"currency",currency:i,currencyDisplay:c,minimumFractionDigits:s||+e%1>0?n:0,maximumFractionDigits:s||+e%1>0?n:0}).format(+e);return a?l.replace(new RegExp(`\\${i}`,"g"),a):l}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)},Qe=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]},Xe=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);}),et=(e={direction:"ASC",caseSensitive:false})=>{let t=/^0/,r=/\s+/g,n=/^\s+|\s+$/g,s=/[^\x00-\x80]/,o=/^0x[0-9a-f]+$/i,i=/(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,l=-a,p=e.caseSensitive?u=>`${u}`.replace(n,""):u=>u.toString().toLowerCase().replace(n,""),$=u=>u.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),j=(u,A)=>(!u.match(t)||A===1)&&parseFloat(u)||u.replace(r," ").replace(n,"")||0;return function(u,A){let h=p(u),g=p(A);if(!h&&!g)return 0;if(!h&&g)return l;if(h&&!g)return a;let k=$(h),N=$(g),v=h.match(o),C=g.match(o),y=v&&C?parseInt(v[0],16):k.length!==1&&Date.parse(h),f=v&&C?parseInt(C[0],16):y&&g.match(c)&&Date.parse(g)||null;if(f){if(y===f)return 0;if(typeof y=="number"&&typeof f=="number"&&y<f)return l;if(typeof y=="number"&&y>f)return a}let P=k.length,D=N.length;for(let b=0,F=Math.max(P,D);b<F;b+=1){let m=j(k[b]||"",P),d=j(N[b]||"",D);if(isNaN(m)!==isNaN(d))return isNaN(m)?a:l;if(s.test(m+d)&&m.localeCompare){let O=m.localeCompare(d);if(O>0)return a;if(O<0)return l;if(b===F-1)return 0}if(m<d)return l;if(m>d)return a;if(`${m}`<`${d}`)return l;if(`${m}`>`${d}`)return a}return 0}},tt=(e,t=false)=>e.toLowerCase().split(/[^a-zA-Z0-9]+/).map((r,n)=>n===0?t?H(r):r:H(r)).join(""),rt=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),nt=(e,t,r)=>Math.min(Math.max(e,t),r),st=(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"),""),ot=(e,t,r,{lerpFactor:n=.1,threshold:s=.1,multiplier:o=1}={})=>{if(!e.current)return;let i=parseFloat(getComputedStyle(e.current).getPropertyValue(t))||0,c=r*o,a=null,l=()=>{i+=(c-i)*n,e.current&&e.current.style.setProperty(t,`${i}px`),Math.abs(c-i)>s&&(a=requestAnimationFrame(l));};a&&cancelAnimationFrame(a),requestAnimationFrame(l);},it=e=>new Promise(t=>setTimeout(t,e)),at=e=>Object.keys(e).filter(t=>isNaN(Number(t))),lt=async e=>{try{return await G.access(e),!0}catch{return false}},ct=e=>{let t="=".repeat((4-e.length%4)%4),r=(e+t).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(r),s=new Uint8Array(n.length);for(let o=0;o<n.length;++o)s[o]=n.charCodeAt(o);return s},oe=(e,t,r)=>{let n=0;return Children.map(e,s=>{if(isValidElement(s)){let o=s,i=t(o)?cloneElement(o,r(n++,o)):o;return o.props.children?cloneElement(i,{children:oe(o.props.children,t,r)}):i}return s})},ut=e=>{let t=[],r=0;return e.length>=8?r++:t.push("Use at least 8 characters"),/[a-z]/.test(e)?r++:t.push("Add lowercase letters"),/[A-Z]/.test(e)?r++:t.push("Add uppercase letters"),/\d/.test(e)?r++:t.push("Include numbers"),/[^A-Za-z0-9]/.test(e)?r++:t.push("Add special characters (e.g. !, @, #)"),{score:r,result:r<=2?"Weak":r==3?"Moderate":r==4?"Strong":"Excellent",suggestion:t}};export{De as MD5,Z as PubSub,K as SORT,S as _,Y as __SALT,oe as addPropsToChildren,ot as animateCSSVar,We as arrayRand,tt as camelCase,rt as camelCaseToDash,ut as checkPasswordStrength,nt as clamp,Xe as copyToClipboard,at as enumToKeys,lt as exists,Je as formatNumber,Qe as formatSize,Pe as fromHash,He as getCancelToken,qe as hexToRgba,Ue as isColor,Ie as isColorName,re as isHexColor,se as isHslColor,ne as isRgbaColor,et as natsort,ee as numberInRange,Me as pluralize,ze as removeDuplicates,it as sleep,st as slugify,Ze as time,Ge as timeSince,te as toHash,H as ucfirst,ct as urlBase64ToUint8Array,Oe as urldecode,Le as urlencode,Fe as uuid,Be as withCredentials,Ke as withGet,Ye as withPost,Ve as withTime};
package/package.json CHANGED
@@ -1,61 +1,46 @@
1
1
  {
2
- "name": "@zuzjs/core",
3
- "version": "0.3.0",
4
- "keywords": [
5
- "core",
6
- "zuz",
7
- "zuz.js",
8
- "zuz orm",
9
- "zuzjs"
10
- ],
11
- "description": "ZuzJS Core Library",
12
- "author": "Zuz.js Team <support@zuz.com.pk>",
13
- "license": "MIT",
14
- "type": "module",
15
- "main": "./dist/cjs/index.js",
16
- "module": "./dist/esm/index.js",
17
- "types": "./dist/esm/index.d.ts",
18
- "exports": {
19
- ".": {
20
- "import": {
21
- "types": "./dist/esm/index.d.ts",
22
- "default": "./dist/esm/index.js"
23
- },
24
- "require": {
25
- "types": "./dist/cjs/index.d.ts",
26
- "default": "./dist/cjs/index.js"
27
- }
28
- }
29
- },
30
- "files": [
31
- "dist"
32
- ],
33
- "scripts": {
34
- "dev:cjs": "tsc -d -w -p tsconfig.json",
35
- "dev:esm": "tsc -d -w -p tsconfig.esm.json",
36
- "dev": "npm-run-all -p dev:*"
37
- },
38
- "engines": {
39
- "node": ">=18.17.0"
40
- },
41
- "sideEffects": [
42
- "reflect-metadata"
43
- ],
44
- "dependencies": {
45
- "@types/hashids": "^2.0.1",
46
- "@types/md5": "^2.3.5",
47
- "axios": "^1.8.4",
48
- "date-fns": "^4.1.0",
49
- "hashids": "^2.3.0",
50
- "ip-regex": "^5.0.0",
51
- "js-cookie": "^3.0.5",
52
- "md5": "^2.3.0",
53
- "moment": "^2.30.1",
54
- "nanoid": "^5.1.6"
55
- },
56
- "devDependencies": {
57
- "husky": "^9.1.7",
58
- "ts-node": "^10.9.2",
59
- "typescript": "^5.7.3"
2
+ "name": "@zuzjs/core",
3
+ "version": "0.3.2",
4
+ "keywords": [
5
+ "core",
6
+ "zuz",
7
+ "zuz.js",
8
+ "zuz orm",
9
+ "zuzjs"
10
+ ],
11
+ "description": "ZuzJS Core Library",
12
+ "author": "Zuz.js Team <support@zuz.com.pk>",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.cjs"
60
23
  }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "engines": {
29
+ "node": ">=18.17.0"
30
+ },
31
+ "sideEffects": [
32
+ "reflect-metadata"
33
+ ],
34
+ "dependencies": {
35
+ "@types/hashids": "^2.0.0",
36
+ "@types/md5": "^2.3.6",
37
+ "axios": "^1.13.4",
38
+ "date-fns": "^4.1.0",
39
+ "hashids": "^2.3.0",
40
+ "ip-regex": "^5.0.0",
41
+ "js-cookie": "^3.0.5",
42
+ "md5": "^2.3.0",
43
+ "moment": "^2.30.1",
44
+ "nanoid": "^5.1.6"
45
+ }
61
46
  }
@@ -1,24 +0,0 @@
1
- /**
2
- * An array of color names.
3
- *
4
- * @remarks
5
- * This array contains a list of color names that can be used in CSS or other color-related operations.
6
- */
7
- export declare const colorNames: string[];
8
- /**
9
- * colorPalatter contains colors and their corresponding shades.
10
- */
11
- export declare const colorPalette: {
12
- green: {
13
- 50: string;
14
- 100: string;
15
- 200: string;
16
- 300: string;
17
- 400: string;
18
- 500: string;
19
- 600: string;
20
- 700: string;
21
- 800: string;
22
- 900: string;
23
- };
24
- };
@@ -1,26 +0,0 @@
1
- /**
2
- * An array of color names.
3
- *
4
- * @remarks
5
- * This array contains a list of color names that can be used in CSS or other color-related operations.
6
- */
7
- export const colorNames = [
8
- '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'
9
- ];
10
- /**
11
- * colorPalatter contains colors and their corresponding shades.
12
- */
13
- export const colorPalette = {
14
- green: {
15
- 50: '#e8f5e9',
16
- 100: '#c8e6c9',
17
- 200: '#a5d6a7',
18
- 300: '#81c784',
19
- 400: '#66bb6a',
20
- 500: '#4caf50',
21
- 600: '#43a047',
22
- 700: '#388e3c',
23
- 800: '#2e7d32',
24
- 900: '#1b5e20',
25
- },
26
- };
@@ -1,51 +0,0 @@
1
- import { AxiosProgressEvent, AxiosRequestConfig, CancelTokenSource } from "axios";
2
- import { RefObject } from "react";
3
- import { FormatNumberParams, sortOptions } from "./types.js";
4
- export { CancelTokenSource, AxiosProgressEvent as UploadProgressEvent };
5
- export * from "./types.js";
6
- export declare const __SALT: string;
7
- export { default as "_" } from "./withGlobals.js";
8
- export declare const numberInRange: (min: number, max: number) => number;
9
- export declare const toHash: (n: number, len?: number, SALT?: string | null) => string;
10
- export declare const fromHash: (str: string, SALT?: string | null) => number;
11
- export declare const MD5: (str: string) => string;
12
- export declare const uuid: (len: number) => string;
13
- export declare const ucfirst: (o: any) => string;
14
- export declare const urldecode: (str: string) => string;
15
- export declare const urlencode: (str: string) => string;
16
- export declare const pluralize: (word: string, count: number) => string;
17
- export declare const isHexColor: (color: string) => boolean;
18
- export declare const isRgbaColor: (color: string) => boolean;
19
- export declare const isHslColor: (color: string) => boolean;
20
- export declare const isColorName: (color: string) => boolean;
21
- export declare const isColor: (color: string) => boolean;
22
- export declare const hexToRgba: (hex: string, alpha?: number) => string;
23
- export declare const removeDuplicates: <T>(array: T[]) => T[];
24
- export declare const getCancelToken: () => CancelTokenSource;
25
- export declare const withCredentials: (include: boolean) => boolean;
26
- export declare const withPost: <T>(uri: string, data: any, // 'dynamic' usually maps to 'any' or 'Record<string, any>'
27
- timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"], onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
28
- export declare const withGet: <T>(uri: string, timeout?: number, ignoreKind?: boolean, headers?: AxiosRequestConfig["headers"]) => Promise<T>;
29
- export declare const withTime: (fun: (...args: any[]) => any) => {
30
- result: any;
31
- executionTime: number;
32
- };
33
- export declare const time: (stamp?: number, format?: string) => string;
34
- export declare const timeSince: (stamp: number) => string;
35
- export declare const arrayRand: (arr: any[]) => any;
36
- export declare const formatNumber: ({ number, locale, style, decimal, forceDecimal, currency }: FormatNumberParams) => string;
37
- export declare const formatSize: (bytes: number | string) => string;
38
- export declare const copyToClipboard: (text: string) => Promise<unknown>;
39
- export declare const natsort: (options?: sortOptions) => (a: string | number, b: string | number) => number;
40
- export declare const camelCase: (str: string, ucf?: boolean) => string;
41
- export declare const camelCaseToDash: (str: string) => string;
42
- export declare const clamp: (value: number, min: number, max: number) => number;
43
- export declare const slugify: (text: string, separator?: string) => string;
44
- export declare const animateCSSVar: (ref: RefObject<HTMLElement>, variable: string, to: number, { lerpFactor, threshold, multiplier, }?: {
45
- lerpFactor?: number;
46
- threshold?: number;
47
- multiplier?: number;
48
- }) => void;
49
- export declare const sleep: (ms: number) => Promise<any>;
50
- export declare const enumToKeys: <T extends Record<string, any>>(obj: T) => Array<keyof T>;
51
- export declare const exists: (path: string) => Promise<boolean>;