devix 0.0.20-beta.2 → 0.0.20-beta.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.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";const t={string:t=>"string"==typeof t,number:t=>"number"==typeof t,boolean:t=>"boolean"==typeof t,null:t=>null===t,undefined:t=>void 0===t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,date:t=>t instanceof Date,regexp:t=>t instanceof RegExp},e=(e,n)=>t[e]?.(n)||!1;var n;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(n||(n={}));class o{constructor(t){this.storage=t===n.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,n,o){const r=this.getCache(t);e("object",r)&&(r[n]=o,this.setCache(t,r))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const r=new o(n.Local),s=new o(n.Session);
1
+ "use strict";function t(t,e){return t.slice(0,1)["upper"===e?"toUpperCase":"toLowerCase"]()+t.slice(1).toLowerCase()}const e={undefined:t=>void 0===t,null:t=>null===t,number:t=>"number"==typeof t,string:t=>"string"==typeof t,boolean:t=>"boolean"==typeof t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),date:t=>t instanceof Date,function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,regexp:t=>t instanceof RegExp,promise:t=>t instanceof Promise},n=(t,n)=>{const o=e[t]?e[t](n):function(t){const e=typeof t;return"object"!=e?e:Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}(n)===t;return o};var o;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(o||(o={}));class r{constructor(t){this.storage=t===o.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,o){const r=this.getCache(t);n("object",r)&&(r[e]=o,this.setCache(t,r))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const s=new r(o.Local),i=new r(o.Session);
2
2
  //! Function Deep Copy
3
- const i=t=>e("object",t)||e("function",t);var c;function a(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function u(t,e,n){return n===c.ASC?t>e:t<e}!function(t){t.ASC="ASC",t.DESC="DESC"}(c||(c={}));const l=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),f=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function p(t){return t.toString().padStart(2,"0")}exports.bubblingSort=function(t,e=c.ASC,n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let s=0;s<o-1-r;s++){u(n?t[s][n]:t[s],n?t[s+1][n]:t[s+1],e)&&a(t,s,s+1)}return t},exports.compose=function(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}},exports.currying=function(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}},exports.debounce=function(t,e=0,n=!1){let o=null,r=!1;function s(...s){return new Promise(((i,c)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,s);i(e)}catch(t){c(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,s);i(e)}catch(t){c(t)}r=!0}}))}return s.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},s},exports.deepClone=function t(n,o=new WeakMap){if(o.get(n))return o.get(n);const r=function(t,n,o){if(e("symbol",t))return Symbol(t.description);if(!i(t))return t;if(e("set",t)){const e=new Set;return t.forEach((t=>e.add(n(t,o)))),e}if(e("map",t)){const e=new Map;return t.forEach(((t,r)=>e.set(r,n(t,o)))),e}}(n,t,o);if(r)return r;const s=e("array",n),c=s?[]:{};return o.set(n,c),s?n.forEach(((e,n)=>{c[n]=t(e,o)})):(Object.keys(n).forEach((e=>{c[e]=t(n[e],o)})),Object.getOwnPropertySymbols(n).forEach((e=>{c[Symbol(e.description)]=t(n[e],o)}))),c},exports.formatTimer=(t,n="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const o=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:p(t.getMonth()+1),day:p(t.getDate()),hours:p(t.getHours()),minutes:p(t.getMinutes()),seconds:p(t.getSeconds()),week:(n=e,f.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(e("string",n)&&!n.trim())return o;return Array.from(l).reduce(((t,[e,n])=>t.replace(new RegExp(e,"g"),o[n])),n)},exports.insertStr=function(t,e,n){return t.slice(0,e)+n+t.slice(e)},exports.isType=e,exports.localCache=r,exports.sessionCache=s,exports.setTimer=function(t,e=0,n=!1){let o=null;const r=()=>{t(),o=setTimeout(r,e)};return n&&t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}},exports.shallowClone=
3
+ const c=t=>n("object",t)||n("function",t);var a;function u(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function l(t,e,n){return n===exports.SortType.ASC?t>e:t<e}exports.SortType=void 0,(a=exports.SortType||(exports.SortType={})).ASC="ASC",a.DESC="DESC";const p=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),f=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function y(t){return t.toString().padStart(2,"0")}exports.bubblingSort=function(t,e="ASC",n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let s=0;s<o-1-r;s++){l(n?t[s][n]:t[s],n?t[s+1][n]:t[s+1],e)&&u(t,s,s+1)}return t},exports.compose=function(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}},exports.currying=function(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}},exports.debounce=function(t,e=0,n=!1){let o=null,r=!1;function s(...s){return new Promise(((i,c)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,s);i(e)}catch(t){c(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,s);i(e)}catch(t){c(t)}r=!0}}))}return s.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},s},exports.deepClone=function t(e,o=new WeakMap){if(o.get(e))return o.get(e);const r=function(t,e,o){if(n("symbol",t))return Symbol(t.description);if(!c(t))return t;if(n("set",t)){const n=new Set;return t.forEach((t=>n.add(e(t,o)))),n}if(n("map",t)){const n=new Map;return t.forEach(((t,r)=>n.set(r,e(t,o)))),n}}(e,t,o);if(r)return r;const s=n("array",e),i=s?[]:{};return o.set(e,i),s?e.forEach(((e,n)=>{i[n]=t(e,o)})):(Object.keys(e).forEach((n=>{i[n]=t(e[n],o)})),Object.getOwnPropertySymbols(e).forEach((n=>{i[Symbol(n.description)]=t(e[n],o)}))),i},exports.formatTimer=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const o=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:y(t.getMonth()+1),day:y(t.getDate()),hours:y(t.getHours()),minutes:y(t.getMinutes()),seconds:y(t.getSeconds()),week:(n=e,f.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(n("string",e)&&!e.trim())return o;return Array.from(p).reduce(((t,[e,n])=>t.replace(new RegExp(e,"g"),o[n])),e)},exports.insertStr=function(t,e,n){return t.slice(0,e)+n+t.slice(e)},exports.isType=n,exports.localCache=s,exports.sessionCache=i,exports.setTimer=async function(t,e=0,n=!1){let o=null;const r=async()=>{await t(),o=setTimeout(r,e)};return n&&await t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}},exports.shallowClone=
4
4
  //! Function Shallow Copy
5
- function(t){return e("array",t)?t.slice():e("object",t)?{...t}:t},exports.stringCase=function(t,e="",n=""){const o=t.split(e);for(let t=0;t<o.length;t++)o[t]=o[t].slice(0,1).toUpperCase()+o[t].slice(1).toLowerCase();return o.join(n)},exports.throttle=function(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let s=0,i=null;function c(...n){return new Promise(((c,a)=>{try{const a=Date.now();let u;o||0!==s||(s=a);const l=e-(a-s);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),c(u),s=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),c(u),s=Date.now(),i=null}),l))}catch(t){a(t)}}))}return c.cancel=function(){i&&clearTimeout(i),s=0,i=null},c};
5
+ function(t){return n("array",t)?t.slice():n("object",t)?{...t}:t},exports.stringCase=function(e,n=["",""],o=["upper","upper"]){const[r,s]=n,[i,c]=o,a=e.split(r);for(let e=0;e<a.length;e++)a[e]=t(a[e],0===e?i:c);return a.join(s)},exports.throttle=function(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let s=0,i=null;function c(...n){return new Promise(((c,a)=>{try{const a=Date.now();let u;o||0!==s||(s=a);const l=e-(a-s);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),c(u),s=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),c(u),s=Date.now(),i=null}),l))}catch(t){a(t)}}))}return c.cancel=function(){i&&clearTimeout(i),s=0,i=null},c};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,25 @@
1
+ interface ITimerObj {
2
+ year: string;
3
+ month: string;
4
+ day: string;
5
+ hours: string;
6
+ minutes: string;
7
+ seconds: string;
8
+ week: string;
9
+ weekNum: string;
10
+ }
11
+ type TFormatTimer = (cellValue: string | number | Date, formatType?: string) => string | ITimerObj;
12
+ type ThrottleOptions = {
13
+ leading?: boolean;
14
+ trailing?: boolean;
15
+ };
16
+ type Tcase = 'upper' | 'lower';
17
+ type TCases = [Tcase, Tcase];
18
+
1
19
  declare function currying(fn: Function): (this: any, ...args: any[]) => any;
2
20
  declare function compose(...fns: Function[]): ((this: any, ...args: any[]) => any) | undefined;
3
21
  declare function insertStr(soure: string, start: number, newStr: string): string;
4
- declare function stringCase(soure: string, separator?: string, separate?: string): string;
22
+ declare function stringCase(soure: string, separa?: string[], cases?: TCases): string;
5
23
 
6
24
  declare const isType: (type: string, target: any) => boolean;
7
25
 
@@ -27,22 +45,6 @@ declare class StorageCache<T = any> {
27
45
  declare const localCache: StorageCache<any>;
28
46
  declare const sessionCache: StorageCache<any>;
29
47
 
30
- interface ITimerObj {
31
- year: string;
32
- month: string;
33
- day: string;
34
- hours: string;
35
- minutes: string;
36
- seconds: string;
37
- week: string;
38
- weekNum: string;
39
- }
40
- type TFormatTimer = (cellValue: string | number | Date, formatType?: string) => string | ITimerObj;
41
- type ThrottleOptions = {
42
- leading?: boolean;
43
- trailing?: boolean;
44
- };
45
-
46
48
  declare function debounce<T extends (...args: any[]) => any>(callback: T, delay?: number, immediate?: boolean): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
47
49
  cancel: () => void;
48
50
  };
@@ -57,11 +59,11 @@ declare enum SortType {
57
59
  ASC = "ASC",
58
60
  DESC = "DESC"
59
61
  }
60
- declare function bubblingSort<T>(array: T[], type?: SortType, key?: keyof T): T[];
62
+ declare function bubblingSort<T>(array: T[], type?: string, key?: keyof T): T[];
61
63
 
62
64
  declare const formatTimer: TFormatTimer;
63
- declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): {
65
+ declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): Promise<{
64
66
  cancel: () => void;
65
- };
67
+ }>;
66
68
 
67
- export { bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, localCache, sessionCache, setTimer, shallowClone, stringCase, throttle };
69
+ export { SortType, bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, localCache, sessionCache, setTimer, shallowClone, stringCase, throttle };
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- function t(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}}function e(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}}function n(t,e,n){return t.slice(0,e)+n+t.slice(e)}function o(t,e="",n=""){const o=t.split(e);for(let t=0;t<o.length;t++)o[t]=o[t].slice(0,1).toUpperCase()+o[t].slice(1).toLowerCase();return o.join(n)}const r={string:t=>"string"==typeof t,number:t=>"number"==typeof t,boolean:t=>"boolean"==typeof t,null:t=>null===t,undefined:t=>void 0===t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,date:t=>t instanceof Date,regexp:t=>t instanceof RegExp},c=(t,e)=>r[t]?.(e)||!1;var i;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(i||(i={}));class s{constructor(t){this.storage=t===i.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,n){const o=this.getCache(t);c("object",o)&&(o[e]=n,this.setCache(t,o))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const a=new s(i.Local),u=new s(i.Session);function l(t,e=0,n=!1){let o=null,r=!1;function c(...c){return new Promise(((i,s)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}r=!0}}))}return c.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},c}function f(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let c=0,i=null;function s(...n){return new Promise(((s,a)=>{try{const a=Date.now();let u;o||0!==c||(c=a);const l=e-(a-c);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),s(u),c=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),s(u),c=Date.now(),i=null}),l))}catch(t){a(t)}}))}return s.cancel=function(){i&&clearTimeout(i),c=0,i=null},s}
1
+ function t(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}}function e(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}}function n(t,e,n){return t.slice(0,e)+n+t.slice(e)}function o(t,e=["",""],n=["upper","upper"]){const[o,c]=e,[i,s]=n,a=t.split(o);for(let t=0;t<a.length;t++)a[t]=r(a[t],0===t?i:s);return a.join(c)}function r(t,e){return t.slice(0,1)["upper"===e?"toUpperCase":"toLowerCase"]()+t.slice(1).toLowerCase()}const c={undefined:t=>void 0===t,null:t=>null===t,number:t=>"number"==typeof t,string:t=>"string"==typeof t,boolean:t=>"boolean"==typeof t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),date:t=>t instanceof Date,function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,regexp:t=>t instanceof RegExp,promise:t=>t instanceof Promise},i=(t,e)=>{const n=c[t]?c[t](e):function(t){const e=typeof t;return"object"!=e?e:Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}(e)===t;return n};var s;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(s||(s={}));class a{constructor(t){this.storage=t===s.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,n){const o=this.getCache(t);i("object",o)&&(o[e]=n,this.setCache(t,o))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const u=new a(s.Local),l=new a(s.Session);function f(t,e=0,n=!1){let o=null,r=!1;function c(...c){return new Promise(((i,s)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}r=!0}}))}return c.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},c}function p(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let c=0,i=null;function s(...n){return new Promise(((s,a)=>{try{const a=Date.now();let u;o||0!==c||(c=a);const l=e-(a-c);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),s(u),c=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),s(u),c=Date.now(),i=null}),l))}catch(t){a(t)}}))}return s.cancel=function(){i&&clearTimeout(i),c=0,i=null},s}
2
2
  //! Function Shallow Copy
3
- function y(t){return c("array",t)?t.slice():c("object",t)?{...t}:t}
3
+ function y(t){return i("array",t)?t.slice():i("object",t)?{...t}:t}
4
4
  //! Function Deep Copy
5
- const g=t=>c("object",t)||c("function",t);function p(t,e=new WeakMap){if(e.get(t))return e.get(t);const n=function(t,e,n){if(c("symbol",t))return Symbol(t.description);if(!g(t))return t;if(c("set",t)){const o=new Set;return t.forEach((t=>o.add(e(t,n)))),o}if(c("map",t)){const o=new Map;return t.forEach(((t,r)=>o.set(r,e(t,n)))),o}}(t,p,e);if(n)return n;const o=c("array",t),r=o?[]:{};return e.set(t,r),o?t.forEach(((t,n)=>{r[n]=p(t,e)})):(Object.keys(t).forEach((n=>{r[n]=p(t[n],e)})),Object.getOwnPropertySymbols(t).forEach((n=>{r[Symbol(n.description)]=p(t[n],e)}))),r}var h;function m(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function S(t,e,n){return n===h.ASC?t>e:t<e}function d(t,e=h.ASC,n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let c=0;c<o-1-r;c++){S(n?t[c][n]:t[c],n?t[c+1][n]:t[c+1],e)&&m(t,c,c+1)}return t}!function(t){t.ASC="ASC",t.DESC="DESC"}(h||(h={}));const w=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),b=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function C(t){return t.toString().padStart(2,"0")}const M=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const n=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:C(t.getMonth()+1),day:C(t.getDate()),hours:C(t.getHours()),minutes:C(t.getMinutes()),seconds:C(t.getSeconds()),week:(n=e,b.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(c("string",e)&&!e.trim())return n;return Array.from(w).reduce(((t,[e,o])=>t.replace(new RegExp(e,"g"),n[o])),e)};function D(t,e=0,n=!1){let o=null;const r=()=>{t(),o=setTimeout(r,e)};return n&&t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}}export{d as bubblingSort,e as compose,t as currying,l as debounce,p as deepClone,M as formatTimer,n as insertStr,c as isType,a as localCache,u as sessionCache,D as setTimer,y as shallowClone,o as stringCase,f as throttle};
5
+ const g=t=>i("object",t)||i("function",t);function h(t,e=new WeakMap){if(e.get(t))return e.get(t);const n=function(t,e,n){if(i("symbol",t))return Symbol(t.description);if(!g(t))return t;if(i("set",t)){const o=new Set;return t.forEach((t=>o.add(e(t,n)))),o}if(i("map",t)){const o=new Map;return t.forEach(((t,r)=>o.set(r,e(t,n)))),o}}(t,h,e);if(n)return n;const o=i("array",t),r=o?[]:{};return e.set(t,r),o?t.forEach(((t,n)=>{r[n]=h(t,e)})):(Object.keys(t).forEach((n=>{r[n]=h(t[n],e)})),Object.getOwnPropertySymbols(t).forEach((n=>{r[Symbol(n.description)]=h(t[n],e)}))),r}var m;function w(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function S(t,e,n){return n===m.ASC?t>e:t<e}function d(t,e="ASC",n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let c=0;c<o-1-r;c++){S(n?t[c][n]:t[c],n?t[c+1][n]:t[c+1],e)&&w(t,c,c+1)}return t}!function(t){t.ASC="ASC",t.DESC="DESC"}(m||(m={}));const b=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),C=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function M(t){return t.toString().padStart(2,"0")}const j=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const n=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:M(t.getMonth()+1),day:M(t.getDate()),hours:M(t.getHours()),minutes:M(t.getMinutes()),seconds:M(t.getSeconds()),week:(n=e,C.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(i("string",e)&&!e.trim())return n;return Array.from(b).reduce(((t,[e,o])=>t.replace(new RegExp(e,"g"),n[o])),e)};async function D(t,e=0,n=!1){let o=null;const r=async()=>{await t(),o=setTimeout(r,e)};return n&&await t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}}export{m as SortType,d as bubblingSort,e as compose,t as currying,f as debounce,h as deepClone,j as formatTimer,n as insertStr,i as isType,u as localCache,l as sessionCache,D as setTimer,y as shallowClone,o as stringCase,p as throttle};
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Devix={})}(this,(function(t){"use strict";const e={string:t=>"string"==typeof t,number:t=>"number"==typeof t,boolean:t=>"boolean"==typeof t,null:t=>null===t,undefined:t=>void 0===t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,date:t=>t instanceof Date,regexp:t=>t instanceof RegExp},n=(t,n)=>e[t]?.(n)||!1;var o;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(o||(o={}));class r{constructor(t){this.storage=t===o.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,o){const r=this.getCache(t);n("object",r)&&(r[e]=o,this.setCache(t,r))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const i=new r(o.Local),s=new r(o.Session);
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Devix={})}(this,(function(t){"use strict";function e(t,e){return t.slice(0,1)["upper"===e?"toUpperCase":"toLowerCase"]()+t.slice(1).toLowerCase()}const n={undefined:t=>void 0===t,null:t=>null===t,number:t=>"number"==typeof t,string:t=>"string"==typeof t,boolean:t=>"boolean"==typeof t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),date:t=>t instanceof Date,function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,regexp:t=>t instanceof RegExp,promise:t=>t instanceof Promise},o=(t,e)=>{const o=n[t]?n[t](e):function(t){const e=typeof t;return"object"!=e?e:Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}(e)===t;return o};var r;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(r||(r={}));class i{constructor(t){this.storage=t===r.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,n){const r=this.getCache(t);o("object",r)&&(r[e]=n,this.setCache(t,r))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const s=new i(r.Local),c=new i(r.Session);
2
2
  //! Function Deep Copy
3
- const c=t=>n("object",t)||n("function",t);var a;function u(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function l(t,e,n){return n===a.ASC?t>e:t<e}!function(t){t.ASC="ASC",t.DESC="DESC"}(a||(a={}));const f=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),y=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function p(t){return t.toString().padStart(2,"0")}t.bubblingSort=function(t,e=a.ASC,n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let i=0;i<o-1-r;i++){l(n?t[i][n]:t[i],n?t[i+1][n]:t[i+1],e)&&u(t,i,i+1)}return t},t.compose=function(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}},t.currying=function(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}},t.debounce=function(t,e=0,n=!1){let o=null,r=!1;function i(...i){return new Promise(((s,c)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,i);s(e)}catch(t){c(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,i);s(e)}catch(t){c(t)}r=!0}}))}return i.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},i},t.deepClone=function t(e,o=new WeakMap){if(o.get(e))return o.get(e);const r=function(t,e,o){if(n("symbol",t))return Symbol(t.description);if(!c(t))return t;if(n("set",t)){const n=new Set;return t.forEach((t=>n.add(e(t,o)))),n}if(n("map",t)){const n=new Map;return t.forEach(((t,r)=>n.set(r,e(t,o)))),n}}(e,t,o);if(r)return r;const i=n("array",e),s=i?[]:{};return o.set(e,s),i?e.forEach(((e,n)=>{s[n]=t(e,o)})):(Object.keys(e).forEach((n=>{s[n]=t(e[n],o)})),Object.getOwnPropertySymbols(e).forEach((n=>{s[Symbol(n.description)]=t(e[n],o)}))),s},t.formatTimer=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const o=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:p(t.getMonth()+1),day:p(t.getDate()),hours:p(t.getHours()),minutes:p(t.getMinutes()),seconds:p(t.getSeconds()),week:(n=e,y.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(n("string",e)&&!e.trim())return o;return Array.from(f).reduce(((t,[e,n])=>t.replace(new RegExp(e,"g"),o[n])),e)},t.insertStr=function(t,e,n){return t.slice(0,e)+n+t.slice(e)},t.isType=n,t.localCache=i,t.sessionCache=s,t.setTimer=function(t,e=0,n=!1){let o=null;const r=()=>{t(),o=setTimeout(r,e)};return n&&t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}},t.shallowClone=
3
+ const a=t=>o("object",t)||o("function",t);var u;function l(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function f(e,n,o){return o===t.SortType.ASC?e>n:e<n}t.SortType=void 0,(u=t.SortType||(t.SortType={})).ASC="ASC",u.DESC="DESC";const p=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),y=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function g(t){return t.toString().padStart(2,"0")}t.bubblingSort=function(t,e="ASC",n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let i=0;i<o-1-r;i++){f(n?t[i][n]:t[i],n?t[i+1][n]:t[i+1],e)&&l(t,i,i+1)}return t},t.compose=function(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}},t.currying=function(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}},t.debounce=function(t,e=0,n=!1){let o=null,r=!1;function i(...i){return new Promise(((s,c)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,i);s(e)}catch(t){c(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,i);s(e)}catch(t){c(t)}r=!0}}))}return i.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},i},t.deepClone=function t(e,n=new WeakMap){if(n.get(e))return n.get(e);const r=function(t,e,n){if(o("symbol",t))return Symbol(t.description);if(!a(t))return t;if(o("set",t)){const o=new Set;return t.forEach((t=>o.add(e(t,n)))),o}if(o("map",t)){const o=new Map;return t.forEach(((t,r)=>o.set(r,e(t,n)))),o}}(e,t,n);if(r)return r;const i=o("array",e),s=i?[]:{};return n.set(e,s),i?e.forEach(((e,o)=>{s[o]=t(e,n)})):(Object.keys(e).forEach((o=>{s[o]=t(e[o],n)})),Object.getOwnPropertySymbols(e).forEach((o=>{s[Symbol(o.description)]=t(e[o],n)}))),s},t.formatTimer=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const n=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:g(t.getMonth()+1),day:g(t.getDate()),hours:g(t.getHours()),minutes:g(t.getMinutes()),seconds:g(t.getSeconds()),week:(n=e,y.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(o("string",e)&&!e.trim())return n;return Array.from(p).reduce(((t,[e,o])=>t.replace(new RegExp(e,"g"),n[o])),e)},t.insertStr=function(t,e,n){return t.slice(0,e)+n+t.slice(e)},t.isType=o,t.localCache=s,t.sessionCache=c,t.setTimer=async function(t,e=0,n=!1){let o=null;const r=async()=>{await t(),o=setTimeout(r,e)};return n&&await t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}},t.shallowClone=
4
4
  //! Function Shallow Copy
5
- function(t){return n("array",t)?t.slice():n("object",t)?{...t}:t},t.stringCase=function(t,e="",n=""){const o=t.split(e);for(let t=0;t<o.length;t++)o[t]=o[t].slice(0,1).toUpperCase()+o[t].slice(1).toLowerCase();return o.join(n)},t.throttle=function(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let i=0,s=null;function c(...n){return new Promise(((c,a)=>{try{const a=Date.now();let u;o||0!==i||(i=a);const l=e-(a-i);if(l<=0)return s&&clearTimeout(s),u=t.apply(this,n),c(u),i=a,void(s=null);r&&!s&&(s=setTimeout((()=>{u=t.apply(this,n),c(u),i=Date.now(),s=null}),l))}catch(t){a(t)}}))}return c.cancel=function(){s&&clearTimeout(s),i=0,s=null},c}}));
5
+ function(t){return o("array",t)?t.slice():o("object",t)?{...t}:t},t.stringCase=function(t,n=["",""],o=["upper","upper"]){const[r,i]=n,[s,c]=o,a=t.split(r);for(let t=0;t<a.length;t++)a[t]=e(a[t],0===t?s:c);return a.join(i)},t.throttle=function(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let i=0,s=null;function c(...n){return new Promise(((c,a)=>{try{const a=Date.now();let u;o||0!==i||(i=a);const l=e-(a-i);if(l<=0)return s&&clearTimeout(s),u=t.apply(this,n),c(u),i=a,void(s=null);r&&!s&&(s=setTimeout((()=>{u=t.apply(this,n),c(u),i=Date.now(),s=null}),l))}catch(t){a(t)}}))}return c.cancel=function(){s&&clearTimeout(s),i=0,s=null},c}}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "devix",
3
3
  "type": "module",
4
- "version": "0.0.20-beta.2",
4
+ "version": "0.0.20-beta.4",
5
5
  "description": "Devix is a comprehensive, powerful, and compact JavaScript utility library.",
6
6
  "author": "king-3 <w2196592083@gmail.com>",
7
7
  "license": "MIT",
@@ -32,6 +32,14 @@
32
32
  "files": [
33
33
  "dist"
34
34
  ],
35
+ "scripts": {
36
+ "build": " pnpm prettier && pnpm lint && rollup -c",
37
+ "dev": "npx --yes tsx --watch example/index.ts",
38
+ "test": "jest",
39
+ "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
40
+ "prettier": "prettier --config .prettierrc.json --write src/**/*.{js,jsx,ts,tsx,json}",
41
+ "releases": "npx bump && tsx publish.ts"
42
+ },
35
43
  "devDependencies": {
36
44
  "@babel/core": "^7.24.0",
37
45
  "@babel/preset-env": "^7.24.0",
@@ -58,13 +66,5 @@
58
66
  "typescript": "^5.4.2",
59
67
  "version-bump-prompt": "^6.1.0",
60
68
  "zx": "^7.2.3"
61
- },
62
- "scripts": {
63
- "build": "pnpm lint && pnpm prettier && rollup -c",
64
- "dev": "npx --yes tsx example/index.ts",
65
- "test": "jest",
66
- "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
67
- "prettier": "prettier --config .prettierrc.json --write src/**/*.{js,jsx,ts,tsx,json}",
68
- "releases": "npx bump && tsx publish.ts"
69
69
  }
70
- }
70
+ }