@andrewcaires/utils.js 0.1.2 → 0.1.3
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 +30 -15
- package/dist/index.esm.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.umd.js +2 -2
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -24,27 +24,42 @@ declare class EventEmitter {
|
|
|
24
24
|
emit(event: string, data?: any): void;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
declare type
|
|
28
|
-
declare type
|
|
29
|
-
declare type
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
27
|
+
declare type TypeArray<T> = Array<T>;
|
|
28
|
+
declare type TypeArrayAny = TypeArray<any>;
|
|
29
|
+
declare type TypeArrayString = TypeArray<string>;
|
|
30
|
+
declare type TypeArrayNumber = TypeArray<number>;
|
|
31
|
+
declare type TypeArrayFunction = TypeArray<Function>;
|
|
32
|
+
declare type TypeObject<T> = {
|
|
33
|
+
[key: string]: T;
|
|
34
|
+
};
|
|
35
|
+
declare type TypeObjectAny = TypeObject<any>;
|
|
36
|
+
declare type TypeObjectString = TypeObject<string>;
|
|
37
|
+
declare type TypeObjectNumber = TypeObject<number>;
|
|
38
|
+
declare type TypeObjectFunction = TypeObject<Function>;
|
|
39
|
+
declare type TypeCallback<T, K, O, R> = (value: T, key: K, object: O) => R;
|
|
40
|
+
declare type TypeCallbackArray<T> = TypeCallback<T, number, TypeArray<T>, any>;
|
|
41
|
+
declare type TypeCallbackMap<T> = TypeCallback<T, number, TypeArray<T>, T>;
|
|
42
|
+
declare type TypeCallbackObject<T> = TypeCallback<T, string, TypeObject<T>, any>;
|
|
43
|
+
|
|
44
|
+
declare type EachCallback = TypeCallback<any, string | number, any, any>;
|
|
45
|
+
declare type LoopCallback = (index: number, count: number) => any;
|
|
46
|
+
declare const forEachIndex: <T>(array: T[], callback: TypeCallbackArray<T>, thisArg?: any) => T[];
|
|
47
|
+
declare const forEachKey: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
|
|
48
|
+
declare const each: (object: any, callback: EachCallback, thisArg?: any) => any;
|
|
49
|
+
declare const loop: (count: number, callback: LoopCallback, thisArg?: any) => number;
|
|
50
|
+
declare const map: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
|
|
33
51
|
declare const noop: () => void;
|
|
34
52
|
|
|
35
53
|
declare const mask: (mask: string, text: string) => string;
|
|
36
54
|
declare const maskMoney: (mask: string, text: string, decimal?: number) => string;
|
|
37
55
|
declare const maskReverse: (mask: string, text: string) => string;
|
|
38
56
|
|
|
39
|
-
declare
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
declare const allowedObject: (allowed: string[], raw: objectRaw) => objectRaw;
|
|
43
|
-
declare const deniedObject: (denied: string[], raw: objectRaw) => objectRaw;
|
|
57
|
+
declare const allowedObject: (allowed: string[], raw: TypeObjectAny) => TypeObjectAny;
|
|
58
|
+
declare const deniedObject: (denied: string[], raw: TypeObjectAny) => TypeObjectAny;
|
|
44
59
|
|
|
45
|
-
declare type
|
|
46
|
-
declare const forEachAsync: <T>(
|
|
47
|
-
declare const forEachSeries: <T>(
|
|
60
|
+
declare type ForEachCallback<T> = TypeCallback<T, number, Array<T>, Promise<void>>;
|
|
61
|
+
declare const forEachAsync: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
62
|
+
declare const forEachSeries: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
48
63
|
declare const sleep: (ms: number) => Promise<void>;
|
|
49
64
|
|
|
50
65
|
declare const lowerCamelCase: (text: string) => string;
|
|
@@ -65,4 +80,4 @@ declare const isNull: (test: any) => boolean;
|
|
|
65
80
|
declare const isUndefined: (test: any) => boolean;
|
|
66
81
|
declare const type: (test: any) => string;
|
|
67
82
|
|
|
68
|
-
export { EventCallback, EventDisposable, EventEmitter, EventList, allowedObject, camelCase, chunkArray, dateFormat, deniedObject,
|
|
83
|
+
export { EventCallback, EventDisposable, EventEmitter, EventList, TypeArray, TypeArrayAny, TypeArrayFunction, TypeArrayNumber, TypeArrayString, TypeCallback, TypeCallbackArray, TypeCallbackMap, TypeCallbackObject, TypeObject, TypeObjectAny, TypeObjectFunction, TypeObjectNumber, TypeObjectString, allowedObject, camelCase, chunkArray, 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, 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.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.3
|
|
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)},c=function(n){return"object"==p(n)},i=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)).
|
|
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)},c=function(n){return"object"==p(n)},i=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(-4)},w=function(){return m()+m()},k=function(){return w()+w()},x=function(){return k()+k()+k()+k()},S=function(){return w()+"-"+m()+"-4"+d(-3)+"-"+m()+"-"+(w()+m())},j=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)}))},O=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}(),M=function(n,t,e){for(var r=n.length,u=0;u<=r&&!1!==t.call(e,n[u],u,n);u++);return n},C=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},U=function(n,e,r){return t(n)?M(n,e,r):c(n)?C(n,e,r):null},A=function(n,t,e){for(var r=1;r<=n&&!1!==t.call(e,r,n);r++);return n},L=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},P=function(){},Y=function(n,t){return t(n.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},E=function(n){return Y(n,(function(n){return n.replace(/\s(\w)/g,(function(n){return n.toUpperCase()}))}))},F=E,H=function(n){return Y(n,(function(n){return n.replace(/(\w)(\w*)/g,(function(n,t,e){return t.toUpperCase()+e}))}))},Z=function(n){return n.split("").reverse().join("")},$=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 $(t)?t:(e.mask--,"");case"L":return $(t)?t.toLowerCase():(e.mask--,"");case"U":return $(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)},I=function(n,t){return z(n,t,{mask:-1,text:-1})},T=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),B(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},W=I,B=function(n,t){return Z(W(Z(n),Z(t)))},D=function(){return D=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},D.apply(this,arguments)};function G(n,t,e,r){return new(e||(e=Promise))((function(u,o){function c(n){try{a(r.next(n))}catch(n){o(n)}}function i(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(c,i)}a((r=r.apply(n,t||[])).next())}))}function N(n,t){var e,r,u,o,c={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;c;)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 c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(u=c.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){c.label=o[1];break}if(6===o[0]&&c.label<u[1]){c.label=u[1],u=o;break}if(u&&c.label<u[2]){c.label=u[2],c.ops.push(o);break}u[2]&&c.ops.pop(),c.trys.pop();continue}o=t.call(n,c)}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,i])}}}var q=function(n,t){return n.reduce((function(n,e){var r;return D(D({},n),((r={})[e]=t[e],r))}),{})},J=function(n,t){return q(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},K=function(n,t,e){return G(void 0,void 0,void 0,(function(){return N(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]}}))}))},Q=function(n,t,e){return G(void 0,void 0,void 0,(function(){var r;return N(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]}}))}))},R=function(n){return new Promise((function(t){return setTimeout(t,n)}))};export{O as EventEmitter,q as allowedObject,F as camelCase,v as chunkArray,j as dateFormat,J as deniedObject,U as each,K as forEachAsync,M as forEachIndex,C as forEachKey,Q 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,c as isObject,i as isString,l as isUndefined,A as loop,E as lowerCamelCase,L as map,I as mask,T as maskMoney,B as maskReverse,P as noop,y as shadeColor,R as sleep,Z as stringReverse,h as toArray,b as toBool,p as type,x as uniqueID,H as upperCamelCase,S as uuidv4};
|
package/dist/index.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/utils.js v0.1.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.3
|
|
3
3
|
* (c) 2022 Andrew Caires
|
|
4
4
|
* @license: MIT
|
|
5
5
|
*/
|
|
6
|
-
var UtilsJS=function(n){"use strict";var
|
|
6
|
+
var UtilsJS=function(n){"use strict";var e={},t=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":e[e.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return e["[object "+n+"]"]=n.toLowerCase()}));var a=function(n,e){return(t=parseInt(n,16)+e,Math.min(255,Math.max(0,t))).toString(16);var t},s=function(n){return Math.random().toString(16).slice(n)},f=function(){return s(-4)},l=function(){return f()+f()},p=function(){return l()+l()},h=function(){function n(){this.events=new Map}return n.prototype.on=function(n,e){var t=this,r=this.events.get(n);return r?r.push(e):this.events.set(n,[e]),{dispose:function(){return t.off(n,e)}}},n.prototype.once=function(n,e){var t=this,r=function(u){e(u),t.off(n,r)};return this.on(n,r),{dispose:function(){return t.off(n,r)}}},n.prototype.off=function(n,e){var t=this.events.get(n);if(e){if(t){var r=t.indexOf(e);r>=0&&t.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,e){var t=this.events.get(n);t&&t.forEach((function(n){return n(e)}))},n}(),v=function(n,e,t){for(var r=n.length,u=0;u<=r&&!1!==e.call(t,n[u],u,n);u++);return n},b=function(n,e,t){var r=Object.keys(n);for(var u in r)if(!1===e.call(t,n[u],u,n))break;return n},d=function(n,e){return e(n.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},g=function(n){return d(n,(function(n){return n.replace(/\s(\w)/g,(function(n){return n.toUpperCase()}))}))},y=g,m=function(n){return n.split("").reverse().join("")},k=function(n){return/^[A-Za-z]$/.test(n)},w=function(n,e,t){t.mask++,t.text++;var r=n[t.mask],u=e[t.text];return i(r)||i(u)?"":function(n,e,t){switch(n.toUpperCase()){case"#":return e;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(e)?e:(t.mask--,"");case"A":case"Z":return k(e)?e:(t.mask--,"");case"L":return k(e)?e.toLowerCase():(t.mask--,"");case"U":return k(e)?e.toUpperCase():(t.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(e)?e:(t.mask--,"");default:return n!=e&&t.text--,n}}(r,u,t)+w(n,e,t)},S=function(n,e){return w(n,e,{mask:-1,text:-1})},j=S,x=function(n,e){return m(j(m(n),m(e)))},C=function(){return C=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var u in e=arguments[t])Object.prototype.hasOwnProperty.call(e,u)&&(n[u]=e[u]);return n},C.apply(this,arguments)};function O(n,e,t,r){return new(t||(t=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 e;n.done?u(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(i,c)}a((r=r.apply(n,e||[])).next())}))}function M(n,e){var t,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(t)throw new TypeError("Generator is already executing.");for(;i;)try{if(t=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=e.call(n,i)}catch(n){o=[6,n],r=0}finally{t=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var E=function(n,e){return n.reduce((function(n,t){var r;return C(C({},n),((r={})[t]=e[t],r))}),{})};return n.EventEmitter=h,n.allowedObject=E,n.camelCase=y,n.chunkArray=function(n,e){void 0===e&&(e=1);for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t},n.dateFormat=function(n,e){return e.replace(/%[yYmdHMS]/g,(function(e){var t;switch(e){case"%y":t=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":t=n.getMonth()+1;break;case"%d":t=n.getDate();break;case"%H":t=n.getHours();break;case"%M":t=n.getMinutes();break;case"%S":t=n.getSeconds();break;default:return e.slice(1)}return("0"+t.toString()).slice(-2)}))},n.deniedObject=function(n,e){return E(Object.keys(e).filter((function(e){return-1==n.indexOf(e)})),e)},n.each=function(n,e,r){return t(n)?v(n,e,r):o(n)?b(n,e,r):null},n.forEachAsync=function(n,e,t){return O(void 0,void 0,void 0,(function(){return M(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return e.call(t,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},n.forEachIndex=v,n.forEachKey=b,n.forEachSeries=function(n,e,t){return O(void 0,void 0,void 0,(function(){var r;return M(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,e.call(t,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=t,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,e,t){for(var r=1;r<=n&&!1!==e.call(t,r,n);r++);return n},n.lowerCamelCase=g,n.map=function(n,e,t){var r=Object.keys(n);for(var u in r)n[u]=e.call(t,n[u],u,n);return n},n.mask=S,n.maskMoney=function(n,e,t){return void 0===t&&(t=2),t++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),x(n,e.length<t?("0".repeat(t)+e).slice(-1*t):e)},n.maskReverse=x,n.noop=function(){},n.shadeColor=function(n,e){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+a(n,e)).slice(-2)}))},n.sleep=function(n){return new Promise((function(e){return setTimeout(e,n)}))},n.stringReverse=m,n.toArray=function(n){return t(n)?n:r(n)?[n]:[]},n.toBool=function(n){return"true"===n||"1"===n},n.type=c,n.uniqueID=function(){return p()+p()+p()+p()},n.upperCamelCase=function(n){return d(n,(function(n){return n.replace(/(\w)(\w*)/g,(function(n,e,t){return e.toUpperCase()+t}))}))},n.uuidv4=function(){return l()+"-"+f()+"-4"+s(-3)+"-"+f()+"-"+(l()+f())},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.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.3
|
|
3
3
|
* (c) 2022 Andrew Caires
|
|
4
4
|
* @license: MIT
|
|
5
5
|
*/
|
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={},t=function(e){return"array"==
|
|
6
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={},t=function(e){return"array"==i(e)},r=function(e){return"null"!=i(e)},n=function(e){return"number"==i(e)},o=function(e){return"object"==i(e)},u=function(e){return void 0===e},i=function(t){return null==t?"null":e[e.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return e["[object "+t+"]"]=t.toLowerCase()}));var c=function(e,t){return(r=parseInt(e,16)+t,Math.min(255,Math.max(0,r))).toString(16);var r},s=function(e){return Math.random().toString(16).slice(e)},a=function(){return s(-4)},f=function(){return a()+a()},l=function(){return f()+f()},p=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var r=this,n=this.events.get(e);return n?n.push(t):this.events.set(e,[t]),{dispose:function(){return r.off(e,t)}}},e.prototype.once=function(e,t){var r=this,n=function(o){t(o),r.off(e,n)};return this.on(e,n),{dispose:function(){return r.off(e,n)}}},e.prototype.off=function(e,t){var r=this.events.get(e);if(t){if(r){var n=r.indexOf(t);n>=0&&r.splice(n,1)}}else this.events.set(e,[])},e.prototype.emit=function(e,t){var r=this.events.get(e);r&&r.forEach((function(e){return e(t)}))},e}(),h=function(e,t,r){for(var n=e.length,o=0;o<=n&&!1!==t.call(r,e[o],o,e);o++);return e},x=function(e,t,r){var n=Object.keys(e);for(var o in n)if(!1===t.call(r,e[o],o,e))break;return e},v=function(e,t){return t(e.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},b=function(e){return v(e,(function(e){return e.replace(/\s(\w)/g,(function(e){return e.toUpperCase()}))}))},d=b,g=function(e){return e.split("").reverse().join("")},y=function(e){return/^[A-Za-z]$/.test(e)},m=function(e,t,r){r.mask++,r.text++;var n=e[r.mask],o=t[r.text];return u(n)||u(o)?"":function(e,t,r){switch(e.toUpperCase()){case"#":return t;case"0":case"9":return function(e){return/^[0-9]$/.test(e)}(t)?t:(r.mask--,"");case"A":case"Z":return y(t)?t:(r.mask--,"");case"L":return y(t)?t.toLowerCase():(r.mask--,"");case"U":return y(t)?t.toUpperCase():(r.mask--,"");case"S":return function(e){return/^[^A-Za-z0-9]$/.test(e)}(t)?t:(r.mask--,"");default:return e!=t&&r.text--,e}}(n,o,r)+m(e,t,r)},k=function(e,t){return m(e,t,{mask:-1,text:-1})},w=k,S=function(e,t){return g(w(g(e),g(t)))},j=function(){return j=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},j.apply(this,arguments)};function C(e,t,r,n){return new(r||(r=Promise))((function(o,u){function i(e){try{s(n.next(e))}catch(e){u(e)}}function c(e){try{s(n.throw(e))}catch(e){u(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,c)}s((n=n.apply(e,t||[])).next())}))}function O(e,t){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: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(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=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}var M=function(e,t){return e.reduce((function(e,r){var n;return j(j({},e),((n={})[r]=t[r],n))}),{})};exports.EventEmitter=p,exports.allowedObject=M,exports.camelCase=d,exports.chunkArray=function(e,t){void 0===t&&(t=1);for(var r=[],n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r},exports.dateFormat=function(e,t){return t.replace(/%[yYmdHMS]/g,(function(t){var r;switch(t){case"%y":r=e.getFullYear();break;case"%Y":return e.getFullYear().toString();case"%m":r=e.getMonth()+1;break;case"%d":r=e.getDate();break;case"%H":r=e.getHours();break;case"%M":r=e.getMinutes();break;case"%S":r=e.getSeconds();break;default:return t.slice(1)}return("0"+r.toString()).slice(-2)}))},exports.deniedObject=function(e,t){return M(Object.keys(t).filter((function(t){return-1==e.indexOf(t)})),t)},exports.each=function(e,r,n){return t(e)?h(e,r,n):o(e)?x(e,r,n):null},exports.forEachAsync=function(e,t,r){return C(void 0,void 0,void 0,(function(){return O(this,(function(n){switch(n.label){case 0:return[4,Promise.all(e.map((function(n,o){return t.call(r,n,o,e)})))];case 1:return n.sent(),[2]}}))}))},exports.forEachIndex=h,exports.forEachKey=x,exports.forEachSeries=function(e,t,r){return C(void 0,void 0,void 0,(function(){var n;return O(this,(function(o){switch(o.label){case 0:n=0,o.label=1;case 1:return n<e.length?[4,t.call(r,e[n],n,e)]:[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2]}}))}))},exports.isArray=t,exports.isBoolean=function(e){return"boolean"==i(e)},exports.isDef=r,exports.isFloat=function(e){return n(e)&&!!(e%1)},exports.isFunction=function(e){return"function"==i(e)},exports.isInteger=function(e){return n(e)&&!(e%1)},exports.isNull=function(e){return null===e},exports.isNumber=n,exports.isObject=o,exports.isString=function(e){return"string"==i(e)},exports.isUndefined=u,exports.loop=function(e,t,r){for(var n=1;n<=e&&!1!==t.call(r,n,e);n++);return e},exports.lowerCamelCase=b,exports.map=function(e,t,r){var n=Object.keys(e);for(var o in n)e[o]=t.call(r,e[o],o,e);return e},exports.mask=k,exports.maskMoney=function(e,t,r){return void 0===r&&(r=2),r++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),S(e,t.length<r?("0".repeat(r)+t).slice(-1*r):t)},exports.maskReverse=S,exports.noop=function(){},exports.shadeColor=function(e,t){return"#"+e.replace(/^#/,"").replace(/../g,(function(e){return("0"+c(e,t)).slice(-2)}))},exports.sleep=function(e){return new Promise((function(t){return setTimeout(t,e)}))},exports.stringReverse=g,exports.toArray=function(e){return t(e)?e:r(e)?[e]:[]},exports.toBool=function(e){return"true"===e||"1"===e},exports.type=i,exports.uniqueID=function(){return l()+l()+l()+l()},exports.upperCamelCase=function(e){return v(e,(function(e){return e.replace(/(\w)(\w*)/g,(function(e,t,r){return t.toUpperCase()+r}))}))},exports.uuidv4=function(){return f()+"-"+a()+"-4"+s(-3)+"-"+a()+"-"+(f()+a())};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/utils.js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
33
33
|
"@rollup/plugin-typescript": "^8.3.2",
|
|
34
|
-
"
|
|
35
|
-
"rollup": "^2.75.5",
|
|
34
|
+
"rollup": "^2.75.6",
|
|
36
35
|
"rollup-plugin-dts": "^4.2.2",
|
|
37
36
|
"rollup-plugin-terser": "^7.0.2"
|
|
38
37
|
}
|