@andrewcaires/utils.js 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,10 +3,9 @@ declare const toArray: (value: any) => Array<any>;
3
3
 
4
4
  declare const toBool: (value: string) => boolean;
5
5
 
6
- declare const cache: (object: any) => object;
7
-
8
6
  declare const shadeColor: (color: string, percent: number) => string;
9
7
 
8
+ declare const simpleID: () => string;
10
9
  declare const uniqueID: () => string;
11
10
  declare const uuidv4: () => string;
12
11
 
@@ -26,43 +25,61 @@ declare class EventEmitter {
26
25
  emit(event: string, data?: any): void;
27
26
  }
28
27
 
29
- declare type forEachCallback$1 = (value: any, key: string, object: any) => void | boolean;
30
- declare type forLoopCallback = (index: number, count: number) => void;
31
- declare type forMapCallback = (value: any, key: string, object: any) => any;
32
- declare const forEach: (object: any, callback: forEachCallback$1, thisArg?: any) => any;
33
- declare const forLoop: (count: number, callback: forLoopCallback, thisArg?: any) => number;
34
- declare const forMap: (object: any, callback: forMapCallback, thisArg?: any) => any;
28
+ declare type TypeArray<T> = Array<T>;
29
+ declare type TypeArrayAny = TypeArray<any>;
30
+ declare type TypeArrayString = TypeArray<string>;
31
+ declare type TypeArrayNumber = TypeArray<number>;
32
+ declare type TypeArrayFunction = TypeArray<Function>;
33
+ declare type TypeObject<T> = {
34
+ [key: string]: T;
35
+ };
36
+ declare type TypeObjectAny = TypeObject<any>;
37
+ declare type TypeObjectString = TypeObject<string>;
38
+ declare type TypeObjectNumber = TypeObject<number>;
39
+ declare type TypeObjectFunction = TypeObject<Function>;
40
+ declare type TypeCallback<T, K, O, R> = (value: T, key: K, object: O) => R;
41
+ declare type TypeCallbackArray<T> = TypeCallback<T, number, TypeArray<T>, any>;
42
+ declare type TypeCallbackMap<T> = TypeCallback<T, number, TypeArray<T>, T>;
43
+ declare type TypeCallbackObject<T> = TypeCallback<T, string, TypeObject<T>, any>;
44
+
45
+ declare type EachCallback = TypeCallback<any, string | number, any, any>;
46
+ declare type LoopCallback = (index: number, count: number) => any;
47
+ declare const forEachIndex: <T>(array: T[], callback: TypeCallbackArray<T>, thisArg?: any) => T[];
48
+ declare const forEachKey: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
49
+ declare const each: (object: any, callback: EachCallback, thisArg?: any) => any;
50
+ declare const loop: (count: number, callback: LoopCallback, thisArg?: any) => number;
51
+ declare const map: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
35
52
  declare const noop: () => void;
36
53
 
37
54
  declare const mask: (mask: string, text: string) => string;
38
55
  declare const maskMoney: (mask: string, text: string, decimal?: number) => string;
39
56
  declare const maskReverse: (mask: string, text: string) => string;
40
57
 
41
- declare type objectRaw = {
42
- [key: string]: any;
43
- };
44
- declare const allowedObject: (allowed: string[], raw: objectRaw) => objectRaw;
45
- declare const deniedObject: (denied: string[], raw: objectRaw) => objectRaw;
58
+ declare const allowedObject: (allowed: string[], raw: TypeObjectAny) => TypeObjectAny;
59
+ declare const deniedObject: (denied: string[], raw: TypeObjectAny) => TypeObjectAny;
46
60
 
47
- declare type forEachCallback<T> = (value: T, index: number, arr: Array<T>) => Promise<void>;
48
- declare const forEachAsync: <T>(arr: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
49
- declare const forEachSeries: <T>(arr: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
61
+ declare type ForEachCallback<T> = TypeCallback<T, number, Array<T>, Promise<void>>;
62
+ declare const forEachAsync: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
63
+ declare const forEachSeries: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
50
64
  declare const sleep: (ms: number) => Promise<void>;
51
65
 
52
- declare const camelCase: (str: string) => string;
53
- declare const stringReverse: (str: string) => string;
66
+ declare const cutText: (text: string, length: number) => string;
67
+ declare const lowerCamelCase: (text: string) => string;
68
+ declare const camelCase: (text: string) => string;
69
+ declare const upperCamelCase: (text: string) => string;
70
+ declare const stringReverse: (text: string) => string;
54
71
 
55
- declare const isArray: (test: any) => boolean;
56
- declare const isBoolean: (test: any) => boolean;
57
- declare const isDef: (test: any) => boolean;
58
- declare const isFunction: (test: any) => boolean;
59
- declare const isNumber: (test: any) => boolean;
60
- declare const isObject: (test: any) => boolean;
61
- declare const isString: (test: any) => boolean;
62
- declare const isFloat: (test: any) => boolean;
63
- declare const isInteger: (test: any) => boolean;
64
- declare const isNull: (test: any) => boolean;
65
- declare const isUndefined: (test: any) => boolean;
72
+ declare const isArray: (test: any) => test is any[];
73
+ declare const isBoolean: (test: any) => test is boolean;
74
+ declare const isDef: (test: any) => test is any;
75
+ declare const isFunction: (test: any) => test is Function;
76
+ declare const isNumber: (test: any) => test is number;
77
+ declare const isObject: (test: any) => test is object;
78
+ declare const isString: (test: any) => test is string;
79
+ declare const isFloat: (test: any) => test is number;
80
+ declare const isInteger: (test: any) => test is number;
81
+ declare const isNull: (test: any) => test is null;
82
+ declare const isUndefined: (test: any) => test is undefined;
66
83
  declare const type: (test: any) => string;
67
84
 
68
- export { EventCallback, EventDisposable, EventEmitter, EventList, allowedObject, cache, camelCase, chunkArray, dateFormat, deniedObject, forEach, forEachAsync, forEachSeries, forLoop, forMap, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, mask, maskMoney, maskReverse, noop, shadeColor, sleep, stringReverse, toArray, toBool, type, uniqueID, uuidv4 };
85
+ export { EventCallback, EventDisposable, EventEmitter, EventList, TypeArray, TypeArrayAny, TypeArrayFunction, TypeArrayNumber, TypeArrayString, TypeCallback, TypeCallbackArray, TypeCallbackMap, TypeCallbackObject, TypeObject, TypeObjectAny, TypeObjectFunction, TypeObjectNumber, TypeObjectString, allowedObject, camelCase, chunkArray, cutText, dateFormat, deniedObject, each, forEachAsync, forEachIndex, forEachKey, forEachSeries, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, loop, lowerCamelCase, map, mask, maskMoney, maskReverse, noop, shadeColor, simpleID, sleep, stringReverse, toArray, toBool, type, uniqueID, upperCamelCase, uuidv4 };
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.1.1
2
+ * @andrewcaires/utils.js v0.1.4
3
3
  * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- var n={},t=function(n){return"array"==p(n)},e=function(n){return"boolean"==p(n)},r=function(n){return"null"!=p(n)},u=function(n){return"function"==p(n)},o=function(n){return"number"==p(n)},i=function(n){return"object"==p(n)},c=function(n){return"string"==p(n)},a=function(n){return o(n)&&!!(n%1)},f=function(n){return o(n)&&!(n%1)},s=function(n){return null===n},l=function(n){return void 0===n},p=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var v=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},h=function(n){return t(n)?n:r(n)?[n]:[]},b=function(n){return"true"===n||"1"===n},g=[],d=[],y=function(n){var t=g.indexOf(n);if(t>=0)return d[t];var e={};return g.push(n),d.push(e),e},m=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},k=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+m(n,t)).substr(-2)}))},w=function(n){return Math.random().toString(16).slice(n)},x=function(){return w(-4)},S=function(){return x()+x()},j=function(){return S()+S()},O=function(){return j()+j()+j()+j()},M=function(){return S()+"-"+x()+"-4"+w(-3)+"-"+x()+"-"+(S()+x())},C=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},A=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),L=function(n,t,e){var r=Object.keys(n);for(var u in r)if(!1===t.call(e,n[u],u,n))return n;return n},P=function(n,t,e){for(var r=1;r<=n;r++)t.call(e,r,n);return n},U=function(n,t,e){var r=Object.keys(n);for(var u in r)n[u]=t.call(e,n[u],u,n);return n},Y=function(){},E=function(n){return n.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(n){return n.toUpperCase()})).replace(/ /g,"")},F=function(n){return n.split("").reverse().join("")},H=function(n){return/^[A-Za-z]$/.test(n)},Z=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return l(r)||l(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return H(t)?t:(e.mask--,"");case"L":return H(t)?t.toLowerCase():(e.mask--,"");case"U":return H(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+Z(n,t,e)},$=function(n,t){return Z(n,t,{mask:-1,text:-1})},z=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),T(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},I=$,T=function(n,t){return F(I(F(n),F(t)))},W=function(){return W=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},W.apply(this,arguments)};function B(n,t,e,r){return new(e||(e=Promise))((function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,c)}a((r=r.apply(n,t||[])).next())}))}function D(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var G=function(n,t){return n.reduce((function(n,e){var r;return W(W({},n),((r={})[e]=t[e],r))}),{})},N=function(n,t){return G(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},q=function(n,t,e){return B(void 0,void 0,void 0,(function(){return D(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e||null,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},J=function(n,t,e){return B(void 0,void 0,void 0,(function(){var r;return D(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e||null,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},K=function(n){return new Promise((function(t){return setTimeout(t,n)}))};export{A as EventEmitter,G as allowedObject,y as cache,E as camelCase,v as chunkArray,C as dateFormat,N as deniedObject,L as forEach,q as forEachAsync,J as forEachSeries,P as forLoop,U as forMap,t as isArray,e as isBoolean,r as isDef,a as isFloat,u as isFunction,f as isInteger,s as isNull,o as isNumber,i as isObject,c as isString,l as isUndefined,$ as mask,z as maskMoney,T as maskReverse,Y as noop,k as shadeColor,K as sleep,F as stringReverse,h as toArray,b as toBool,p as type,O as uniqueID,M as uuidv4};
6
+ var n={},t=function(n){return"array"==p(n)},e=function(n){return"boolean"==p(n)},r=function(n){return"null"!=p(n)},u=function(n){return"function"==p(n)},o=function(n){return"number"==p(n)},i=function(n){return"object"==p(n)},c=function(n){return"string"==p(n)},a=function(n){return o(n)&&!!(n%1)},f=function(n){return o(n)&&!(n%1)},s=function(n){return null===n},l=function(n){return void 0===n},p=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var v=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},h=function(n){return t(n)?n:r(n)?[n]:[]},b=function(n){return"true"===n||"1"===n},g=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},y=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+g(n,t)).slice(-2)}))},d=function(n){return Math.random().toString(16).slice(n)},m=function(){return d(-3)},w=function(){return d(-4)},k=function(){return w()+w()},x=function(){return k()+k()},S=function(){return m()+w()},j=function(){return x()+x()+x()+x()},O=function(){return k()+"-"+w()+"-4"+m()+"-"+w()+"-"+(k()+w())},M=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},C=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),U=function(n,t,e){for(var r=n.length,u=0;u<=r&&!1!==t.call(e,n[u],u,n);u++);return n},A=function(n,t,e){var r=Object.keys(n);for(var u in r)if(!1===t.call(e,n[u],u,n))break;return n},L=function(n,e,r){return t(n)?U(n,e,r):i(n)?A(n,e,r):null},P=function(n,t,e){for(var r=1;r<=n&&!1!==t.call(e,r,n);r++);return n},Y=function(n,t,e){var r=Object.keys(n);for(var u in r)n[u]=t.call(e,n[u],u,n);return n},E=function(){},F=function(n,t){if(n.length>t){var e=n.substring(0,t).split(" ");return e.pop(),e.join(" ")+"..."}return n},H=function(n,t){return t(n.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},Z=function(n){return H(n,(function(n){return n.replace(/\s(\w)/g,(function(n){return n.toUpperCase()}))}))},$=Z,z=function(n){return H(n,(function(n){return n.replace(/(\w)(\w*)/g,(function(n,t,e){return t.toUpperCase()+e}))}))},I=function(n){return n.split("").reverse().join("")},T=function(n){return/^[A-Za-z]$/.test(n)},W=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return l(r)||l(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return T(t)?t:(e.mask--,"");case"L":return T(t)?t.toLowerCase():(e.mask--,"");case"U":return T(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+W(n,t,e)},B=function(n,t){return W(n,t,{mask:-1,text:-1})},D=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),N(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},G=B,N=function(n,t){return I(G(I(n),I(t)))},q=function(){return q=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},q.apply(this,arguments)};function J(n,t,e,r){return new(e||(e=Promise))((function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,c)}a((r=r.apply(n,t||[])).next())}))}function K(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var Q=function(n,t){return n.reduce((function(n,e){var r;return q(q({},n),((r={})[e]=t[e],r))}),{})},R=function(n,t){return Q(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},V=function(n,t,e){return J(void 0,void 0,void 0,(function(){return K(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},X=function(n,t,e){return J(void 0,void 0,void 0,(function(){var r;return K(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},_=function(n){return new Promise((function(t){return setTimeout(t,n)}))};export{C as EventEmitter,Q as allowedObject,$ as camelCase,v as chunkArray,F as cutText,M as dateFormat,R as deniedObject,L as each,V as forEachAsync,U as forEachIndex,A as forEachKey,X as forEachSeries,t as isArray,e as isBoolean,r as isDef,a as isFloat,u as isFunction,f as isInteger,s as isNull,o as isNumber,i as isObject,c as isString,l as isUndefined,P as loop,Z as lowerCamelCase,Y as map,B as mask,D as maskMoney,N as maskReverse,E as noop,y as shadeColor,S as simpleID,_ as sleep,I as stringReverse,h as toArray,b as toBool,p as type,j as uniqueID,z as upperCamelCase,O as uuidv4};
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.1.1
2
+ * @andrewcaires/utils.js v0.1.4
3
3
  * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- var UtilsJS=function(n){"use strict";var t={},e=function(n){return"array"==i(n)},r=function(n){return"null"!=i(n)},u=function(n){return"number"==i(n)},o=function(n){return void 0===n},i=function(n){return null==n?"null":t[t.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return t["[object "+n+"]"]=n.toLowerCase()}));var c=[],a=[],s=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},f=function(n){return Math.random().toString(16).slice(n)},l=function(){return f(-4)},p=function(){return l()+l()},v=function(){return p()+p()},h=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),b=function(n){return n.split("").reverse().join("")},d=function(n){return/^[A-Za-z]$/.test(n)},g=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return o(r)||o(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return d(t)?t:(e.mask--,"");case"L":return d(t)?t.toLowerCase():(e.mask--,"");case"U":return d(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+g(n,t,e)},y=function(n,t){return g(n,t,{mask:-1,text:-1})},m=y,k=function(n,t){return b(m(b(n),b(t)))},w=function(){return w=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},w.apply(this,arguments)};function S(n,t,e,r){return new(e||(e=Promise))((function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,c)}a((r=r.apply(n,t||[])).next())}))}function j(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var O=function(n,t){return n.reduce((function(n,e){var r;return w(w({},n),((r={})[e]=t[e],r))}),{})};return n.EventEmitter=h,n.allowedObject=O,n.cache=function(n){var t=c.indexOf(n);if(t>=0)return a[t];var e={};return c.push(n),a.push(e),e},n.camelCase=function(n){return n.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(n){return n.toUpperCase()})).replace(/ /g,"")},n.chunkArray=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},n.dateFormat=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},n.deniedObject=function(n,t){return O(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},n.forEach=function(n,t,e){var r=Object.keys(n);for(var u in r)if(!1===t.call(e,n[u],u,n))return n;return n},n.forEachAsync=function(n,t,e){return S(void 0,void 0,void 0,(function(){return j(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e||null,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},n.forEachSeries=function(n,t,e){return S(void 0,void 0,void 0,(function(){var r;return j(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e||null,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},n.forLoop=function(n,t,e){for(var r=1;r<=n;r++)t.call(e,r,n);return n},n.forMap=function(n,t,e){var r=Object.keys(n);for(var u in r)n[u]=t.call(e,n[u],u,n);return n},n.isArray=e,n.isBoolean=function(n){return"boolean"==i(n)},n.isDef=r,n.isFloat=function(n){return u(n)&&!!(n%1)},n.isFunction=function(n){return"function"==i(n)},n.isInteger=function(n){return u(n)&&!(n%1)},n.isNull=function(n){return null===n},n.isNumber=u,n.isObject=function(n){return"object"==i(n)},n.isString=function(n){return"string"==i(n)},n.isUndefined=o,n.mask=y,n.maskMoney=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),k(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},n.maskReverse=k,n.noop=function(){},n.shadeColor=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+s(n,t)).substr(-2)}))},n.sleep=function(n){return new Promise((function(t){return setTimeout(t,n)}))},n.stringReverse=b,n.toArray=function(n){return e(n)?n:r(n)?[n]:[]},n.toBool=function(n){return"true"===n||"1"===n},n.type=i,n.uniqueID=function(){return v()+v()+v()+v()},n.uuidv4=function(){return p()+"-"+l()+"-4"+f(-3)+"-"+l()+"-"+(p()+l())},Object.defineProperty(n,"__esModule",{value:!0}),n}({});
6
+ var UtilsJS=function(n){"use strict";var t={},e=function(n){return"array"==c(n)},r=function(n){return"null"!=c(n)},u=function(n){return"number"==c(n)},o=function(n){return"object"==c(n)},i=function(n){return void 0===n},c=function(n){return null==n?"null":t[t.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return t["[object "+n+"]"]=n.toLowerCase()}));var a=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},s=function(n){return Math.random().toString(16).slice(n)},f=function(){return s(-3)},l=function(){return s(-4)},p=function(){return l()+l()},h=function(){return p()+p()},v=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),b=function(n,t,e){for(var r=n.length,u=0;u<=r&&!1!==t.call(e,n[u],u,n);u++);return n},g=function(n,t,e){var r=Object.keys(n);for(var u in r)if(!1===t.call(e,n[u],u,n))break;return n},d=function(n,t){return t(n.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},y=function(n){return d(n,(function(n){return n.replace(/\s(\w)/g,(function(n){return n.toUpperCase()}))}))},m=y,k=function(n){return n.split("").reverse().join("")},w=function(n){return/^[A-Za-z]$/.test(n)},S=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return i(r)||i(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return w(t)?t:(e.mask--,"");case"L":return w(t)?t.toLowerCase():(e.mask--,"");case"U":return w(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+S(n,t,e)},j=function(n,t){return S(n,t,{mask:-1,text:-1})},x=j,C=function(n,t){return k(x(k(n),k(t)))},O=function(){return O=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},O.apply(this,arguments)};function M(n,t,e,r){return new(e||(e=Promise))((function(u,o){function i(n){try{a(r.next(n))}catch(n){o(n)}}function c(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,c)}a((r=r.apply(n,t||[])).next())}))}function E(n,t){var e,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;i;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(n,i)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var A=function(n,t){return n.reduce((function(n,e){var r;return O(O({},n),((r={})[e]=t[e],r))}),{})};return n.EventEmitter=v,n.allowedObject=A,n.camelCase=m,n.chunkArray=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},n.cutText=function(n,t){if(n.length>t){var e=n.substring(0,t).split(" ");return e.pop(),e.join(" ")+"..."}return n},n.dateFormat=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},n.deniedObject=function(n,t){return A(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},n.each=function(n,t,r){return e(n)?b(n,t,r):o(n)?g(n,t,r):null},n.forEachAsync=function(n,t,e){return M(void 0,void 0,void 0,(function(){return E(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},n.forEachIndex=b,n.forEachKey=g,n.forEachSeries=function(n,t,e){return M(void 0,void 0,void 0,(function(){var r;return E(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},n.isArray=e,n.isBoolean=function(n){return"boolean"==c(n)},n.isDef=r,n.isFloat=function(n){return u(n)&&!!(n%1)},n.isFunction=function(n){return"function"==c(n)},n.isInteger=function(n){return u(n)&&!(n%1)},n.isNull=function(n){return null===n},n.isNumber=u,n.isObject=o,n.isString=function(n){return"string"==c(n)},n.isUndefined=i,n.loop=function(n,t,e){for(var r=1;r<=n&&!1!==t.call(e,r,n);r++);return n},n.lowerCamelCase=y,n.map=function(n,t,e){var r=Object.keys(n);for(var u in r)n[u]=t.call(e,n[u],u,n);return n},n.mask=j,n.maskMoney=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),C(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},n.maskReverse=C,n.noop=function(){},n.shadeColor=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+a(n,t)).slice(-2)}))},n.simpleID=function(){return f()+l()},n.sleep=function(n){return new Promise((function(t){return setTimeout(t,n)}))},n.stringReverse=k,n.toArray=function(n){return e(n)?n:r(n)?[n]:[]},n.toBool=function(n){return"true"===n||"1"===n},n.type=c,n.uniqueID=function(){return h()+h()+h()+h()},n.upperCamelCase=function(n){return d(n,(function(n){return n.replace(/(\w)(\w*)/g,(function(n,t,e){return t.toUpperCase()+e}))}))},n.uuidv4=function(){return p()+"-"+l()+"-4"+f()+"-"+l()+"-"+(p()+l())},Object.defineProperty(n,"__esModule",{value:!0}),n}({});
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.1.1
2
+ * @andrewcaires/utils.js v0.1.4
3
3
  * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t={},e=function(t){return"array"==u(t)},r=function(t){return"null"!=u(t)},n=function(t){return"number"==u(t)},o=function(t){return void 0===t},u=function(e){return null==e?"null":t[t.toString.call(e)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(e){return t["[object "+e+"]"]=e.toLowerCase()}));var i=[],s=[],c=function(t,e){return(r=parseInt(t,16)+e,Math.min(255,Math.max(0,r))).toString(16);var r},a=function(t){return Math.random().toString(16).slice(t)},f=function(){return a(-4)},l=function(){return f()+f()},p=function(){return l()+l()},h=function(){function t(){this.events=new Map}return t.prototype.on=function(t,e){var r=this,n=this.events.get(t);return n?n.push(e):this.events.set(t,[e]),{dispose:function(){return r.off(t,e)}}},t.prototype.once=function(t,e){var r=this,n=function(o){e(o),r.off(t,n)};return this.on(t,n),{dispose:function(){return r.off(t,n)}}},t.prototype.off=function(t,e){var r=this.events.get(t);if(e){if(r){var n=r.indexOf(e);n>=0&&r.splice(n,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,e){var r=this.events.get(t);r&&r.forEach((function(t){return t(e)}))},t}(),v=function(t){return t.split("").reverse().join("")},x=function(t){return/^[A-Za-z]$/.test(t)},b=function(t,e,r){r.mask++,r.text++;var n=t[r.mask],u=e[r.text];return o(n)||o(u)?"":function(t,e,r){switch(t.toUpperCase()){case"#":return e;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(e)?e:(r.mask--,"");case"A":case"Z":return x(e)?e:(r.mask--,"");case"L":return x(e)?e.toLowerCase():(r.mask--,"");case"U":return x(e)?e.toUpperCase():(r.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(e)?e:(r.mask--,"");default:return t!=e&&r.text--,t}}(n,u,r)+b(t,e,r)},d=function(t,e){return b(t,e,{mask:-1,text:-1})},g=d,y=function(t,e){return v(g(v(t),v(e)))},m=function(){return m=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},m.apply(this,arguments)};function k(t,e,r,n){return new(r||(r=Promise))((function(o,u){function i(t){try{c(n.next(t))}catch(t){u(t)}}function s(t){try{c(n.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,s)}c((n=n.apply(t,e||[])).next())}))}function w(t,e){var r,n,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function s(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(t,i)}catch(t){u=[6,t],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}var S=function(t,e){return t.reduce((function(t,r){var n;return m(m({},t),((n={})[r]=e[r],n))}),{})};exports.EventEmitter=h,exports.allowedObject=S,exports.cache=function(t){var e=i.indexOf(t);if(e>=0)return s[e];var r={};return i.push(t),s.push(r),r},exports.camelCase=function(t){return t.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(t){return t.toUpperCase()})).replace(/ /g,"")},exports.chunkArray=function(t,e){void 0===e&&(e=1);for(var r=[],n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},exports.dateFormat=function(t,e){return e.replace(/%[yYmdHMS]/g,(function(e){var r;switch(e){case"%y":r=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":r=t.getMonth()+1;break;case"%d":r=t.getDate();break;case"%H":r=t.getHours();break;case"%M":r=t.getMinutes();break;case"%S":r=t.getSeconds();break;default:return e.slice(1)}return("0"+r.toString()).slice(-2)}))},exports.deniedObject=function(t,e){return S(Object.keys(e).filter((function(e){return-1==t.indexOf(e)})),e)},exports.forEach=function(t,e,r){var n=Object.keys(t);for(var o in n)if(!1===e.call(r,t[o],o,t))return t;return t},exports.forEachAsync=function(t,e,r){return k(void 0,void 0,void 0,(function(){return w(this,(function(n){switch(n.label){case 0:return[4,Promise.all(t.map((function(n,o){return e.call(r||null,n,o,t)})))];case 1:return n.sent(),[2]}}))}))},exports.forEachSeries=function(t,e,r){return k(void 0,void 0,void 0,(function(){var n;return w(this,(function(o){switch(o.label){case 0:n=0,o.label=1;case 1:return n<t.length?[4,e.call(r||null,t[n],n,t)]:[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2]}}))}))},exports.forLoop=function(t,e,r){for(var n=1;n<=t;n++)e.call(r,n,t);return t},exports.forMap=function(t,e,r){var n=Object.keys(t);for(var o in n)t[o]=e.call(r,t[o],o,t);return t},exports.isArray=e,exports.isBoolean=function(t){return"boolean"==u(t)},exports.isDef=r,exports.isFloat=function(t){return n(t)&&!!(t%1)},exports.isFunction=function(t){return"function"==u(t)},exports.isInteger=function(t){return n(t)&&!(t%1)},exports.isNull=function(t){return null===t},exports.isNumber=n,exports.isObject=function(t){return"object"==u(t)},exports.isString=function(t){return"string"==u(t)},exports.isUndefined=o,exports.mask=d,exports.maskMoney=function(t,e,r){return void 0===r&&(r=2),r++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),y(t,e.length<r?("0".repeat(r)+e).slice(-1*r):e)},exports.maskReverse=y,exports.noop=function(){},exports.shadeColor=function(t,e){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+c(t,e)).substr(-2)}))},exports.sleep=function(t){return new Promise((function(e){return setTimeout(e,t)}))},exports.stringReverse=v,exports.toArray=function(t){return e(t)?t:r(t)?[t]:[]},exports.toBool=function(t){return"true"===t||"1"===t},exports.type=u,exports.uniqueID=function(){return p()+p()+p()+p()},exports.uuidv4=function(){return l()+"-"+f()+"-4"+a(-3)+"-"+f()+"-"+(l()+f())};
6
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t={},e=function(t){return"array"==i(t)},n=function(t){return"null"!=i(t)},r=function(t){return"number"==i(t)},o=function(t){return"object"==i(t)},u=function(t){return void 0===t},i=function(e){return null==e?"null":t[t.toString.call(e)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(e){return t["[object "+e+"]"]=e.toLowerCase()}));var c=function(t,e){return(n=parseInt(t,16)+e,Math.min(255,Math.max(0,n))).toString(16);var n},s=function(t){return Math.random().toString(16).slice(t)},a=function(){return s(-3)},f=function(){return s(-4)},l=function(){return f()+f()},p=function(){return l()+l()},x=function(){function t(){this.events=new Map}return t.prototype.on=function(t,e){var n=this,r=this.events.get(t);return r?r.push(e):this.events.set(t,[e]),{dispose:function(){return n.off(t,e)}}},t.prototype.once=function(t,e){var n=this,r=function(o){e(o),n.off(t,r)};return this.on(t,r),{dispose:function(){return n.off(t,r)}}},t.prototype.off=function(t,e){var n=this.events.get(t);if(e){if(n){var r=n.indexOf(e);r>=0&&n.splice(r,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,e){var n=this.events.get(t);n&&n.forEach((function(t){return t(e)}))},t}(),h=function(t,e,n){for(var r=t.length,o=0;o<=r&&!1!==e.call(n,t[o],o,t);o++);return t},v=function(t,e,n){var r=Object.keys(t);for(var o in r)if(!1===e.call(n,t[o],o,t))break;return t},b=function(t,e){return e(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},g=function(t){return b(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},d=g,y=function(t){return t.split("").reverse().join("")},m=function(t){return/^[A-Za-z]$/.test(t)},k=function(t,e,n){n.mask++,n.text++;var r=t[n.mask],o=e[n.text];return u(r)||u(o)?"":function(t,e,n){switch(t.toUpperCase()){case"#":return e;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(e)?e:(n.mask--,"");case"A":case"Z":return m(e)?e:(n.mask--,"");case"L":return m(e)?e.toLowerCase():(n.mask--,"");case"U":return m(e)?e.toUpperCase():(n.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(e)?e:(n.mask--,"");default:return t!=e&&n.text--,t}}(r,o,n)+k(t,e,n)},w=function(t,e){return k(t,e,{mask:-1,text:-1})},j=w,S=function(t,e){return y(j(y(t),y(e)))},C=function(){return C=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},C.apply(this,arguments)};function O(t,e,n,r){return new(n||(n=Promise))((function(o,u){function i(t){try{s(r.next(t))}catch(t){u(t)}}function c(t){try{s(r.throw(t))}catch(t){u(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,c)}s((r=r.apply(t,e||[])).next())}))}function M(t,e){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(t,i)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}var E=function(t,e){return t.reduce((function(t,n){var r;return C(C({},t),((r={})[n]=e[n],r))}),{})};exports.EventEmitter=x,exports.allowedObject=E,exports.camelCase=d,exports.chunkArray=function(t,e){void 0===e&&(e=1);for(var n=[],r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n},exports.cutText=function(t,e){if(t.length>e){var n=t.substring(0,e).split(" ");return n.pop(),n.join(" ")+"..."}return t},exports.dateFormat=function(t,e){return e.replace(/%[yYmdHMS]/g,(function(e){var n;switch(e){case"%y":n=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":n=t.getMonth()+1;break;case"%d":n=t.getDate();break;case"%H":n=t.getHours();break;case"%M":n=t.getMinutes();break;case"%S":n=t.getSeconds();break;default:return e.slice(1)}return("0"+n.toString()).slice(-2)}))},exports.deniedObject=function(t,e){return E(Object.keys(e).filter((function(e){return-1==t.indexOf(e)})),e)},exports.each=function(t,n,r){return e(t)?h(t,n,r):o(t)?v(t,n,r):null},exports.forEachAsync=function(t,e,n){return O(void 0,void 0,void 0,(function(){return M(this,(function(r){switch(r.label){case 0:return[4,Promise.all(t.map((function(r,o){return e.call(n,r,o,t)})))];case 1:return r.sent(),[2]}}))}))},exports.forEachIndex=h,exports.forEachKey=v,exports.forEachSeries=function(t,e,n){return O(void 0,void 0,void 0,(function(){var r;return M(this,(function(o){switch(o.label){case 0:r=0,o.label=1;case 1:return r<t.length?[4,e.call(n,t[r],r,t)]:[3,4];case 2:o.sent(),o.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},exports.isArray=e,exports.isBoolean=function(t){return"boolean"==i(t)},exports.isDef=n,exports.isFloat=function(t){return r(t)&&!!(t%1)},exports.isFunction=function(t){return"function"==i(t)},exports.isInteger=function(t){return r(t)&&!(t%1)},exports.isNull=function(t){return null===t},exports.isNumber=r,exports.isObject=o,exports.isString=function(t){return"string"==i(t)},exports.isUndefined=u,exports.loop=function(t,e,n){for(var r=1;r<=t&&!1!==e.call(n,r,t);r++);return t},exports.lowerCamelCase=g,exports.map=function(t,e,n){var r=Object.keys(t);for(var o in r)t[o]=e.call(n,t[o],o,t);return t},exports.mask=w,exports.maskMoney=function(t,e,n){return void 0===n&&(n=2),n++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),S(t,e.length<n?("0".repeat(n)+e).slice(-1*n):e)},exports.maskReverse=S,exports.noop=function(){},exports.shadeColor=function(t,e){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+c(t,e)).slice(-2)}))},exports.simpleID=function(){return a()+f()},exports.sleep=function(t){return new Promise((function(e){return setTimeout(e,t)}))},exports.stringReverse=y,exports.toArray=function(t){return e(t)?t:n(t)?[t]:[]},exports.toBool=function(t){return"true"===t||"1"===t},exports.type=i,exports.uniqueID=function(){return p()+p()+p()+p()},exports.upperCamelCase=function(t){return b(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,e,n){return e.toUpperCase()+n}))}))},exports.uuidv4=function(){return l()+"-"+f()+"-4"+a()+"-"+f()+"-"+(l()+f())};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/utils.js",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "JavaScript utility library for web and nodejs development",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",
@@ -29,11 +29,10 @@
29
29
  },
30
30
  "homepage": "https://github.com/andrewcaires/npm/tree/main/utils.js#readme",
31
31
  "devDependencies": {
32
- "@rollup/plugin-commonjs": "^21.0.1",
33
- "@rollup/plugin-typescript": "^8.3.0",
34
- "fs": "^0.0.1-security",
35
- "rollup": "^2.58.3",
36
- "rollup-plugin-dts": "^4.0.0",
32
+ "@rollup/plugin-commonjs": "^22.0.0",
33
+ "@rollup/plugin-typescript": "^8.3.2",
34
+ "rollup": "^2.75.6",
35
+ "rollup-plugin-dts": "^4.2.2",
37
36
  "rollup-plugin-terser": "^7.0.2"
38
37
  }
39
38
  }