devix 0.0.16 → 0.0.18
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/README.md +84 -16
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +3 -3
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,36 +1,104 @@
|
|
|
1
1
|
# devix
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> devix 是一个全面的、强大的、紧凑的 JavaScript 实用程序库( 简体中文 | [English](README_en.md) )
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
请确保您在 Node.js 环境下使用 npm 或其他包管理器安装此库。
|
|
6
8
|
|
|
7
9
|
```shell
|
|
8
10
|
npm install --save-dev devix
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
然后,利用现代的模块捆绑工具,如 Vite 或 Webpack,以模块化的语法引入此库。
|
|
12
14
|
|
|
13
15
|
```javascript
|
|
14
|
-
//
|
|
16
|
+
// 使用 ES Module
|
|
15
17
|
import { [[ModuleName]] } from 'devix'
|
|
16
18
|
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
+
// 使用 CommonJS
|
|
20
|
+
const { [[ModuleName]] } = require('devix')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使用
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { localCache, bubblingSort, isType } from 'devix'
|
|
27
|
+
|
|
28
|
+
// 使用 localCache
|
|
29
|
+
localCache.setCache('userInfo', { name: 'king', age: 18 })
|
|
30
|
+
const userInfo = localCache.get('userInfo')
|
|
31
|
+
console.log('userInfo', userInfo)
|
|
32
|
+
|
|
33
|
+
// 使用 bubblingSort、
|
|
34
|
+
const arr1 = [123, 346, 62, 2456, 56123, 1, 64, 61, 453, 72345]
|
|
35
|
+
const sortArr1 = bubblingSort(arr1, 'DESC')
|
|
36
|
+
console.log('sortArr1', sortArr1)
|
|
37
|
+
const arr2 = [
|
|
38
|
+
{ name: 'zsan', age: 16 },
|
|
39
|
+
{ name: 'lisi', age: 32 },
|
|
40
|
+
{ name: 'wawu', age: 25 },
|
|
41
|
+
{ name: 'king', age: 18 }
|
|
42
|
+
]
|
|
43
|
+
const sortArr2 = bubblingSort(arr2, 'DESC', 'age')
|
|
44
|
+
console.log('sortArr2', sortArr2)
|
|
45
|
+
|
|
46
|
+
// 使用 isType
|
|
47
|
+
console.log(`isType(userInfo,'object') -> true`, isType(userInfo, 'object'))
|
|
48
|
+
console.log(
|
|
49
|
+
`isType(userInfo.name,'string') -> true`,
|
|
50
|
+
isType(userInfo, 'string')
|
|
51
|
+
)
|
|
52
|
+
console.log(`isType(userInfo.age,'number') -> true`, isType(userInfo, 'number'))
|
|
19
53
|
```
|
|
20
54
|
|
|
21
|
-
##
|
|
55
|
+
## 方法
|
|
56
|
+
|
|
57
|
+
### 缓存相关
|
|
58
|
+
|
|
59
|
+
提供缓存操作的相关方法。
|
|
60
|
+
|
|
61
|
+
- localCache
|
|
62
|
+
- sessionCache
|
|
63
|
+
|
|
64
|
+
### 拷贝相关
|
|
65
|
+
|
|
66
|
+
用于数据复制操作的相关方法。
|
|
67
|
+
|
|
68
|
+
- deepClone
|
|
69
|
+
- shallowClone
|
|
70
|
+
|
|
71
|
+
### 限频相关
|
|
72
|
+
|
|
73
|
+
包含控制操作触发频率的相关方法。
|
|
74
|
+
|
|
75
|
+
- throttle
|
|
76
|
+
- debounce
|
|
77
|
+
|
|
78
|
+
### 排序相关
|
|
79
|
+
|
|
80
|
+
提供各种排序操作的方法。
|
|
22
81
|
|
|
23
82
|
- bubblingSort
|
|
83
|
+
|
|
84
|
+
### 时间相关
|
|
85
|
+
|
|
86
|
+
包括处理时间相关操作的方法。
|
|
87
|
+
|
|
88
|
+
- formatTimer
|
|
89
|
+
- setTimer
|
|
90
|
+
|
|
91
|
+
### 类型相关
|
|
92
|
+
|
|
93
|
+
用于数据类型检测的相关方法。
|
|
94
|
+
|
|
95
|
+
- isType
|
|
96
|
+
|
|
97
|
+
### 其他方法
|
|
98
|
+
|
|
99
|
+
包括各种其他功能性函数和方法。
|
|
100
|
+
|
|
24
101
|
- compose
|
|
25
102
|
- currying
|
|
26
|
-
- debounce
|
|
27
|
-
- deepClone
|
|
28
|
-
- formatTimer
|
|
29
103
|
- insertStr
|
|
30
|
-
- isType
|
|
31
|
-
- localCache
|
|
32
|
-
- sessionCache
|
|
33
|
-
- setTimer
|
|
34
|
-
- shallowClone
|
|
35
104
|
- stringCase
|
|
36
|
-
- throttle
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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);
|
|
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,n){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 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=
|
|
4
4
|
//! Function Shallow Copy
|
|
5
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};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ declare function currying(fn: Function): (this: any, ...args: any[]) => any;
|
|
|
2
2
|
declare function compose(...fns: Function[]): ((this: any, ...args: any[]) => any) | undefined;
|
|
3
3
|
declare function insertStr(soure: string, start: number, newStr: string): string;
|
|
4
4
|
declare function stringCase(soure: string, separator?: string, separate?: string): string;
|
|
5
|
-
declare function setTimer(execute: (...args: any[]) => any, delay: number, immediate: boolean): {
|
|
6
|
-
cancel: () => void;
|
|
7
|
-
};
|
|
8
5
|
|
|
9
6
|
declare const isType: (type: string, target: any) => boolean;
|
|
10
7
|
|
|
@@ -63,5 +60,8 @@ declare enum SortType {
|
|
|
63
60
|
declare function bubblingSort<T>(array: T[], type?: SortType, key?: keyof T): T[];
|
|
64
61
|
|
|
65
62
|
declare const formatTimer: TFormatTimer;
|
|
63
|
+
declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): {
|
|
64
|
+
cancel: () => void;
|
|
65
|
+
};
|
|
66
66
|
|
|
67
67
|
export { 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)}
|
|
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}
|
|
2
2
|
//! Function Shallow Copy
|
|
3
|
-
function
|
|
3
|
+
function y(t){return c("array",t)?t.slice():c("object",t)?{...t}:t}
|
|
4
4
|
//! Function Deep Copy
|
|
5
|
-
const
|
|
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};
|
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).
|
|
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);
|
|
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,n){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 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=
|
|
4
4
|
//! Function Shallow Copy
|
|
5
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}}));
|
package/package.json
CHANGED