@andrewcaires/utils.js 0.1.2 → 0.1.5
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 +48 -26
- package/dist/index.esm.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.umd.js +2 -2
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @andrewcaires/utils.js v0.1.5
|
|
3
|
+
* (c) 2022 Andrew Caires
|
|
4
|
+
* @license: MIT
|
|
5
|
+
*/
|
|
1
6
|
declare const chunkArray: <T>(array: T[], length?: number) => T[][];
|
|
2
7
|
declare const toArray: (value: any) => Array<any>;
|
|
3
8
|
|
|
@@ -5,6 +10,7 @@ declare const toBool: (value: string) => boolean;
|
|
|
5
10
|
|
|
6
11
|
declare const shadeColor: (color: string, percent: number) => string;
|
|
7
12
|
|
|
13
|
+
declare const simpleID: () => string;
|
|
8
14
|
declare const uniqueID: () => string;
|
|
9
15
|
declare const uuidv4: () => string;
|
|
10
16
|
|
|
@@ -24,45 +30,61 @@ declare class EventEmitter {
|
|
|
24
30
|
emit(event: string, data?: any): void;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
declare type
|
|
28
|
-
declare type
|
|
29
|
-
declare type
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
33
|
+
declare type TypeArray<T> = Array<T>;
|
|
34
|
+
declare type TypeArrayAny = TypeArray<any>;
|
|
35
|
+
declare type TypeArrayString = TypeArray<string>;
|
|
36
|
+
declare type TypeArrayNumber = TypeArray<number>;
|
|
37
|
+
declare type TypeArrayFunction = TypeArray<Function>;
|
|
38
|
+
declare type TypeObject<T> = {
|
|
39
|
+
[key: string]: T;
|
|
40
|
+
};
|
|
41
|
+
declare type TypeObjectAny = TypeObject<any>;
|
|
42
|
+
declare type TypeObjectString = TypeObject<string>;
|
|
43
|
+
declare type TypeObjectNumber = TypeObject<number>;
|
|
44
|
+
declare type TypeObjectFunction = TypeObject<Function>;
|
|
45
|
+
declare type TypeCallback<T, K, O, R> = (value: T, key: K, object: O) => R;
|
|
46
|
+
declare type TypeCallbackArray<T> = TypeCallback<T, number, TypeArray<T>, any>;
|
|
47
|
+
declare type TypeCallbackMap<T> = TypeCallback<T, number, TypeArray<T>, T>;
|
|
48
|
+
declare type TypeCallbackObject<T> = TypeCallback<T, string, TypeObject<T>, any>;
|
|
49
|
+
|
|
50
|
+
declare type EachCallback = TypeCallback<any, string | number, any, any>;
|
|
51
|
+
declare type LoopCallback = (index: number, count: number) => any;
|
|
52
|
+
declare const forEachIndex: <T>(array: T[], callback: TypeCallbackArray<T>, thisArg?: any) => T[];
|
|
53
|
+
declare const forEachKey: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
|
|
54
|
+
declare const each: (object: any, callback: EachCallback, thisArg?: any) => any;
|
|
55
|
+
declare const loop: (count: number, callback: LoopCallback, thisArg?: any) => number;
|
|
56
|
+
declare const map: <T>(object: TypeObject<T>, callback: TypeCallbackObject<T>, thisArg?: any) => TypeObject<T>;
|
|
33
57
|
declare const noop: () => void;
|
|
34
58
|
|
|
35
59
|
declare const mask: (mask: string, text: string) => string;
|
|
36
60
|
declare const maskMoney: (mask: string, text: string, decimal?: number) => string;
|
|
37
61
|
declare const maskReverse: (mask: string, text: string) => string;
|
|
38
62
|
|
|
39
|
-
declare
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
declare const allowedObject: (allowed: string[], raw: objectRaw) => objectRaw;
|
|
43
|
-
declare const deniedObject: (denied: string[], raw: objectRaw) => objectRaw;
|
|
63
|
+
declare const allowedObject: (allowed: string[], raw: TypeObjectAny) => TypeObjectAny;
|
|
64
|
+
declare const deniedObject: (denied: string[], raw: TypeObjectAny) => TypeObjectAny;
|
|
44
65
|
|
|
45
|
-
declare type
|
|
46
|
-
declare const forEachAsync: <T>(
|
|
47
|
-
declare const forEachSeries: <T>(
|
|
66
|
+
declare type ForEachCallback<T> = TypeCallback<T, number, Array<T>, Promise<void>>;
|
|
67
|
+
declare const forEachAsync: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
68
|
+
declare const forEachSeries: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
48
69
|
declare const sleep: (ms: number) => Promise<void>;
|
|
49
70
|
|
|
71
|
+
declare const cutText: (text: string, length: number) => string;
|
|
50
72
|
declare const lowerCamelCase: (text: string) => string;
|
|
51
73
|
declare const camelCase: (text: string) => string;
|
|
52
74
|
declare const upperCamelCase: (text: string) => string;
|
|
53
75
|
declare const stringReverse: (text: string) => string;
|
|
54
76
|
|
|
55
|
-
declare const isArray: (test: any) =>
|
|
56
|
-
declare const isBoolean: (test: any) => boolean;
|
|
57
|
-
declare const isDef: (test: any) =>
|
|
58
|
-
declare const isFunction: (test: any) =>
|
|
59
|
-
declare const isNumber: (test: any) =>
|
|
60
|
-
declare const isObject: (test: any) =>
|
|
61
|
-
declare const isString: (test: any) =>
|
|
62
|
-
declare const isFloat: (test: any) =>
|
|
63
|
-
declare const isInteger: (test: any) =>
|
|
64
|
-
declare const isNull: (test: any) =>
|
|
65
|
-
declare const isUndefined: (test: any) =>
|
|
77
|
+
declare const isArray: (test: any) => test is any[];
|
|
78
|
+
declare const isBoolean: (test: any) => test is boolean;
|
|
79
|
+
declare const isDef: (test: any) => test is any;
|
|
80
|
+
declare const isFunction: (test: any) => test is Function;
|
|
81
|
+
declare const isNumber: (test: any) => test is number;
|
|
82
|
+
declare const isObject: (test: any) => test is object;
|
|
83
|
+
declare const isString: (test: any) => test is string;
|
|
84
|
+
declare const isFloat: (test: any) => test is number;
|
|
85
|
+
declare const isInteger: (test: any) => test is number;
|
|
86
|
+
declare const isNull: (test: any) => test is null;
|
|
87
|
+
declare const isUndefined: (test: any) => test is undefined;
|
|
66
88
|
declare const type: (test: any) => string;
|
|
67
89
|
|
|
68
|
-
export { EventCallback, EventDisposable, EventEmitter, EventList, allowedObject, camelCase, chunkArray, dateFormat, deniedObject,
|
|
90
|
+
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.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.5
|
|
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
|
|
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 h=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},v=function(n){return t(n)?n:r(n)?[n]:[]},g=function(n){return"true"===n||"1"===n},b=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"+b(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=0;r<n.length&&!1!==t.call(e,n[r],r,n);r++);return n},A=function(n,t,e){for(var r="",u=Object.keys(n),o=0;o<u.length&&(r=u[o],!1!==t.call(e,n[r],r,n));o++);return n},L=function(n,e,r){return t(n)?U(n,e,r):c(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){for(var r="",u=Object.keys(n),o=0;o<u.length;o++)n[r=u[o]]=t.call(e,n[r],r,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 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 K(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 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,h 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,c as isObject,i 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,v as toArray,g 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.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.5
|
|
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"==
|
|
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=0;r<n.length&&!1!==t.call(e,n[r],r,n);r++);return n},g=function(n,t,e){for(var r="",u=Object.keys(n),o=0;o<u.length&&(r=u[o],!1!==t.call(e,n[r],r,n));o++);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){for(var r="",u=Object.keys(n),o=0;o<u.length;o++)n[r=u[o]]=t.call(e,n[r],r,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.
|
|
2
|
+
* @andrewcaires/utils.js v0.1.5
|
|
3
3
|
* (c) 2022 Andrew Caires
|
|
4
4
|
* @license: MIT
|
|
5
5
|
*/
|
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
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()},h=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}(),x=function(t,e,n){for(var r=0;r<t.length&&!1!==e.call(n,t[r],r,t);r++);return t},v=function(t,e,n){for(var r="",o=Object.keys(t),u=0;u<o.length&&(r=o[u],!1!==e.call(n,t[r],r,t));u++);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=h,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)?x(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=x,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){for(var r="",o=Object.keys(t),u=0;u<o.length;u++)t[r=o[u]]=e.call(n,t[r],r,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.
|
|
3
|
+
"version": "0.1.5",
|
|
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,11 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/andrewcaires/npm/tree/main/utils.js#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@rollup/plugin-commonjs": "^22.0.
|
|
33
|
-
"@rollup/plugin-typescript": "^8.3.
|
|
34
|
-
"
|
|
35
|
-
"rollup": "^2.75.5",
|
|
32
|
+
"@rollup/plugin-commonjs": "^22.0.1",
|
|
33
|
+
"@rollup/plugin-typescript": "^8.3.3",
|
|
34
|
+
"rollup": "^2.76.0",
|
|
36
35
|
"rollup-plugin-dts": "^4.2.2",
|
|
37
|
-
"rollup-plugin-terser": "^7.0.2"
|
|
36
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
37
|
+
"tslib": "^2.4.0"
|
|
38
38
|
}
|
|
39
39
|
}
|