super-toolkit 1.0.2 → 1.0.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/.babelrc +8 -1
- package/README.md +50 -9
- package/index.d.ts +39 -28
- package/index.ts +68 -31
- package/lib/super-toolkit.min.js +47 -1
- package/package.json +6 -3
- package/src/array.ts +81 -56
- package/src/data.ts +175 -18
- package/src/element.ts +86 -5
- package/src/event.ts +101 -27
- package/src/file.ts +188 -96
- package/src/localStorage.ts +175 -17
- package/src/random.ts +161 -0
- package/src/reg.ts +164 -40
- package/src/time.ts +170 -85
- package/tsconfig.json +15 -8
- package/webpack.config.js +76 -4
- package/test.html +0 -20
package/.babelrc
CHANGED
package/README.md
CHANGED
|
@@ -42,20 +42,46 @@ npm i super-toolkit -S
|
|
|
42
42
|
* @return:{Array}
|
|
43
43
|
*/
|
|
44
44
|
```
|
|
45
|
-
#####
|
|
45
|
+
##### deepClone
|
|
46
46
|
```js
|
|
47
47
|
/**
|
|
48
|
-
* @desc
|
|
49
|
-
* @param:{
|
|
50
|
-
* @return:{
|
|
48
|
+
* @desc:深克隆
|
|
49
|
+
* @param:{Any} value
|
|
50
|
+
* @return:{Any}
|
|
51
51
|
*/
|
|
52
52
|
```
|
|
53
|
-
#####
|
|
53
|
+
##### isEmpty
|
|
54
54
|
```js
|
|
55
55
|
/**
|
|
56
|
-
* @desc
|
|
57
|
-
* @param:{
|
|
58
|
-
* @return:{
|
|
56
|
+
* @desc:判断是否为空字符串、null、undefined、空对象、空数组
|
|
57
|
+
* @param:{String | Number | Array | Object | null | undefined} value
|
|
58
|
+
* @return:{Boolean}
|
|
59
|
+
*/
|
|
60
|
+
```
|
|
61
|
+
##### group
|
|
62
|
+
```js
|
|
63
|
+
/**
|
|
64
|
+
* @desc:数据分组筛选
|
|
65
|
+
* @param:{Array} array
|
|
66
|
+
* @param:{Array} keys
|
|
67
|
+
* @return:{Array}
|
|
68
|
+
*/
|
|
69
|
+
```
|
|
70
|
+
##### isSame
|
|
71
|
+
```js
|
|
72
|
+
/**
|
|
73
|
+
* @desc:判断两个参数的数据是否一样
|
|
74
|
+
* @param:{any} sourceData
|
|
75
|
+
* @param:{any} compareData
|
|
76
|
+
* @return:{Boolean}
|
|
77
|
+
*/
|
|
78
|
+
```
|
|
79
|
+
##### getDataType
|
|
80
|
+
```js
|
|
81
|
+
/**
|
|
82
|
+
* @desc:返回参数的数据类型
|
|
83
|
+
* @param:{any} data
|
|
84
|
+
* @return:{String}
|
|
59
85
|
*/
|
|
60
86
|
```
|
|
61
87
|
##### getElementContent
|
|
@@ -67,7 +93,7 @@ npm i super-toolkit -S
|
|
|
67
93
|
* @return:{String} content
|
|
68
94
|
*/
|
|
69
95
|
```
|
|
70
|
-
#####
|
|
96
|
+
##### onDebounce or onThrottle
|
|
71
97
|
```js
|
|
72
98
|
/**
|
|
73
99
|
* @desc:防抖 or 节流函数
|
|
@@ -137,6 +163,21 @@ npm i super-toolkit -S
|
|
|
137
163
|
* @return:{void}
|
|
138
164
|
*/
|
|
139
165
|
```
|
|
166
|
+
##### getRandomColor
|
|
167
|
+
```js
|
|
168
|
+
/**
|
|
169
|
+
* @desc:随机生成16进制颜色
|
|
170
|
+
* @return:{String}
|
|
171
|
+
*/
|
|
172
|
+
```
|
|
173
|
+
##### getRandomString
|
|
174
|
+
```js
|
|
175
|
+
/**
|
|
176
|
+
* @desc:随机生成指定长度的字符串
|
|
177
|
+
* @param:{Number} size
|
|
178
|
+
* @return:{String}
|
|
179
|
+
*/
|
|
180
|
+
```
|
|
140
181
|
##### validate
|
|
141
182
|
```js
|
|
142
183
|
/**
|
package/index.d.ts
CHANGED
|
@@ -1,63 +1,74 @@
|
|
|
1
1
|
|
|
2
|
-
type Format='YYYY/MM/DD HH:MM:SS' | 'YYYY-MM-DD HH:MM:SS' | 'YYYY/MM/DD' | 'YYYY-MM-DD' | 'MM/DD' | 'MM-DD' | 'MM' | 'DD'
|
|
2
|
+
type Format = 'YYYY/MM/DD HH:MM:SS' | 'YYYY-MM-DD HH:MM:SS' | 'YYYY/MM/DD' | 'YYYY-MM-DD' | 'MM/DD' | 'MM-DD' | 'MM' | 'DD'
|
|
3
3
|
declare module "super-toolkit" {
|
|
4
4
|
/** 数组去重 */
|
|
5
|
-
export const unique
|
|
5
|
+
export const unique: <T>(oldArr: Record<string, any>[], key?: string) => T
|
|
6
6
|
/** 数组升序排序 */
|
|
7
|
-
export const minSort
|
|
7
|
+
export const minSort: <T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T
|
|
8
8
|
/** 数组降序排序 */
|
|
9
|
-
export const maxSort
|
|
9
|
+
export const maxSort: <T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T
|
|
10
10
|
|
|
11
|
-
/** 获取指定长度的随机数 */
|
|
12
|
-
export const getRandomSixNum:(size: number) => string
|
|
13
11
|
/** 深克隆 */
|
|
14
|
-
export const deepClone
|
|
15
|
-
|
|
12
|
+
export const deepClone: <T>(val: T) => T
|
|
13
|
+
/** 判断是否为空字符串、null、undefined、空对象、空数组 */
|
|
14
|
+
export const isEmpty: (value: string | number | any[] | Record<string, any> | null | undefined) => boolean
|
|
15
|
+
/** 数据分组筛选 */
|
|
16
|
+
export const group: <T extends Record<string, any>[] = any[]>(array: T, keys: string[]) => {group: string;data: T;}[]
|
|
17
|
+
/** 判断两个参数的数据是否一样 */
|
|
18
|
+
const isSame: (sourceData: any, compareData: any) => boolean
|
|
19
|
+
/** 返回参数的数据类型 */
|
|
20
|
+
const getDataType: (data: any) => string
|
|
21
|
+
|
|
16
22
|
/** 获取指定节点内容 */
|
|
17
|
-
export const getElementContent:(msg: string, el: string) => string | null
|
|
23
|
+
export const getElementContent: (msg: string, el: string) => string | null
|
|
18
24
|
|
|
19
25
|
/** 防抖 */
|
|
20
|
-
export const
|
|
26
|
+
export const onDebounce: (fn: Function, wait: number) => (this: Window) => void
|
|
21
27
|
/** 节流 */
|
|
22
|
-
export const
|
|
28
|
+
export const onThrottle: (fn: Function, wait: number) => (this: Window) => void
|
|
23
29
|
|
|
24
30
|
/** 根据url获取指定的application类型 */
|
|
25
|
-
export const getApplication:(url: string) => string | null
|
|
31
|
+
export const getApplication: (url: string) => string | null
|
|
26
32
|
/** file转base64 */
|
|
27
33
|
export const fileToBase64: (file: File | Blob) => Promise<string>
|
|
28
34
|
/** base64转blob */
|
|
29
|
-
export const base64ToBlob:(dataURL: string, mimeType?: string) => Blob
|
|
35
|
+
export const base64ToBlob: (dataURL: string, mimeType?: string) => Blob
|
|
30
36
|
/** blob转File */
|
|
31
37
|
export const blobToFile: (blob: Blob, fileName: string, mimeType: string) => File
|
|
32
38
|
/** base64转file */
|
|
33
|
-
export const base64ToFile:(dataURL: string, fileName: string, mimeType?: string) => File
|
|
39
|
+
export const base64ToFile: (dataURL: string, fileName: string, mimeType?: string) => File
|
|
34
40
|
|
|
35
41
|
/** 获取浏览器localStorage的数据 */
|
|
36
|
-
export const getLocalStorage
|
|
42
|
+
export const getLocalStorage: <T>(key: string) => T | null
|
|
37
43
|
/** 设置浏览器localStorage的数据 */
|
|
38
|
-
export const setLocalStorage
|
|
44
|
+
export const setLocalStorage: <T = any>(key: string, value: T) => void
|
|
45
|
+
|
|
46
|
+
/** 随机生成指定长度的字符串 */
|
|
47
|
+
export const getRandomString: (size: number) => string
|
|
48
|
+
/** 随机生成16进制颜色 */
|
|
49
|
+
export const getRandomColor: () => string
|
|
39
50
|
|
|
40
51
|
/** 验证整数 */
|
|
41
|
-
export const validateInt:(value: string) => boolean
|
|
52
|
+
export const validateInt: (value: string) => boolean
|
|
42
53
|
/** 验证正整数 */
|
|
43
|
-
export const validateRightInt:(value: string) => boolean
|
|
54
|
+
export const validateRightInt: (value: string) => boolean
|
|
44
55
|
/** 验证负整数 */
|
|
45
|
-
export const validateLeftInt:(value: string) => boolean
|
|
56
|
+
export const validateLeftInt: (value: string) => boolean
|
|
46
57
|
/** 验证手机号 */
|
|
47
|
-
export const validatePhone:(value: string) => boolean
|
|
48
|
-
/**
|
|
49
|
-
export const validateIDCard:(value: string) => boolean
|
|
58
|
+
export const validatePhone: (value: string) => boolean
|
|
59
|
+
/** 验证身份证号 */
|
|
60
|
+
export const validateIDCard: (value: string) => boolean
|
|
50
61
|
/** 验证邮箱地址 */
|
|
51
|
-
export const validateEmail:(value: string) => boolean
|
|
62
|
+
export const validateEmail: (value: string) => boolean
|
|
52
63
|
/** 验证金额 */
|
|
53
|
-
export const validateAmount:(value: string) => boolean
|
|
64
|
+
export const validateAmount: (value: string) => boolean
|
|
54
65
|
/** 验证邮政编码 */
|
|
55
|
-
export const validatePostCode:(value: string) => boolean
|
|
66
|
+
export const validatePostCode: (value: string) => boolean
|
|
56
67
|
|
|
57
68
|
/** 获取指定格式的时间 */
|
|
58
|
-
export const getDate:(date: string | Date, format: Format, day?: number) => string
|
|
69
|
+
export const getDate: (date: string | Date, format: Format, day?: number) => string
|
|
59
70
|
/** 获取当月指定周数的开始时间与结束时间 */
|
|
60
|
-
export const getMonday:(type: "s" | "e", start?: number | undefined) => string
|
|
71
|
+
export const getMonday: (type: "s" | "e", start?: number | undefined) => string
|
|
61
72
|
/** 获取时间对应的星期几 */
|
|
62
|
-
export const getWeek:(date: string | Date) => string
|
|
73
|
+
export const getWeek: (date: string | Date) => string
|
|
63
74
|
}
|
package/index.ts
CHANGED
|
@@ -1,65 +1,102 @@
|
|
|
1
1
|
import * as array from './src/array'
|
|
2
2
|
import * as data from './src/data'
|
|
3
|
-
import * as
|
|
3
|
+
import * as element from './src/element'
|
|
4
4
|
import * as event from './src/event'
|
|
5
5
|
import * as file from './src/file'
|
|
6
6
|
import * as localStorage from './src/localStorage'
|
|
7
|
+
import * as random from './src/random'
|
|
7
8
|
import * as reg from './src/reg'
|
|
8
9
|
import * as time from './src/time'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
const {getRandomSixNum,deepClone}=data
|
|
13
|
-
const {getElementContent}=elelemt
|
|
14
|
-
const {debounce,throttle}=event
|
|
15
|
-
const { getApplication,fileToBase64,base64ToBlob,blobToFile,base64ToFile } = file
|
|
16
|
-
const { getLocalStorage, setLocalStorage } = localStorage
|
|
17
|
-
const {validateInt,validateRightInt,validateLeftInt,validatePhone,validateIDCard,validateEmail,validateAmount,validatePostCode}=reg
|
|
18
|
-
const { getDate, getMonday, getWeek } = time
|
|
19
|
-
const superToolkit = {
|
|
11
|
+
// 导出所有模块
|
|
12
|
+
export const superToolkit = {
|
|
20
13
|
...array,
|
|
21
14
|
...data,
|
|
22
|
-
...
|
|
15
|
+
...element,
|
|
23
16
|
...event,
|
|
24
17
|
...file,
|
|
25
18
|
...localStorage,
|
|
19
|
+
...random,
|
|
20
|
+
...reg,
|
|
26
21
|
...time,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 导出默认对象
|
|
25
|
+
export default superToolkit
|
|
31
26
|
|
|
27
|
+
// 单独导出常用函数
|
|
28
|
+
export const {
|
|
29
|
+
// array
|
|
32
30
|
unique,
|
|
33
31
|
minSort,
|
|
34
32
|
maxSort,
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
|
|
34
|
+
// data
|
|
37
35
|
deepClone,
|
|
38
|
-
|
|
36
|
+
isEmpty,
|
|
37
|
+
group,
|
|
38
|
+
isSame,
|
|
39
|
+
getDataType,
|
|
40
|
+
|
|
41
|
+
// element
|
|
39
42
|
getElementContent,
|
|
40
|
-
|
|
43
|
+
getElementText,
|
|
44
|
+
getAllElements,
|
|
45
|
+
|
|
46
|
+
// event
|
|
41
47
|
debounce,
|
|
42
48
|
throttle,
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
|
|
50
|
+
// file
|
|
45
51
|
fileToBase64,
|
|
46
52
|
base64ToBlob,
|
|
47
53
|
blobToFile,
|
|
48
54
|
base64ToFile,
|
|
49
|
-
|
|
55
|
+
getApplication,
|
|
56
|
+
downloadFile,
|
|
57
|
+
getFileFromUrl,
|
|
58
|
+
|
|
59
|
+
// localStorage
|
|
50
60
|
getLocalStorage,
|
|
51
61
|
setLocalStorage,
|
|
52
|
-
|
|
62
|
+
removeLocalStorage,
|
|
63
|
+
clearLocalStorage,
|
|
64
|
+
getLocalStorageKeys,
|
|
65
|
+
createNamespacedStorage,
|
|
66
|
+
|
|
67
|
+
// random
|
|
68
|
+
getRandomColor,
|
|
69
|
+
getRandomString,
|
|
70
|
+
getRandomInt,
|
|
71
|
+
getRandomFloat,
|
|
72
|
+
getRandomElement,
|
|
73
|
+
shuffleArray,
|
|
74
|
+
generateRandomId,
|
|
75
|
+
|
|
76
|
+
// reg
|
|
53
77
|
validateInt,
|
|
54
|
-
|
|
55
|
-
|
|
78
|
+
validatePositiveInt,
|
|
79
|
+
validateNegativeInt,
|
|
56
80
|
validatePhone,
|
|
81
|
+
validateTelephone,
|
|
57
82
|
validateIDCard,
|
|
58
83
|
validateEmail,
|
|
59
84
|
validateAmount,
|
|
60
85
|
validatePostCode,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
validateUrl,
|
|
87
|
+
validatePassword,
|
|
88
|
+
validateDate,
|
|
89
|
+
validateTime,
|
|
90
|
+
validateIPv4,
|
|
91
|
+
REGEX,
|
|
92
|
+
|
|
93
|
+
// time
|
|
94
|
+
getWeek,
|
|
95
|
+
getWeekRange,
|
|
96
|
+
formatDate,
|
|
97
|
+
getDaysDiff,
|
|
98
|
+
isToday,
|
|
99
|
+
getRelativeTime,
|
|
100
|
+
getDaysInMonth,
|
|
101
|
+
getTimestamp
|
|
102
|
+
} = superToolkit
|
package/lib/super-toolkit.min.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["super-toolkit"]=e():t["super-toolkit"]=e()}(this,(function(){return function(){"use strict";var t={d:function(e,n){for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{base64ToBlob:function(){return K},base64ToFile:function(){return V},blobToFile:function(){return Q},debounce:function(){return W},deepClone:function(){return U},default:function(){return dt},fileToBase64:function(){return G},getApplication:function(){return X},getDate:function(){return lt},getElementContent:function(){return q},getLocalStorage:function(){return tt},getMonday:function(){return ft},getRandomSixNum:function(){return _},getWeek:function(){return st},maxSort:function(){return z},minSort:function(){return B},setLocalStorage:function(){return et},throttle:function(){return Z},unique:function(){return J},validateAmount:function(){return ut},validateEmail:function(){return ct},validateIDCard:function(){return at},validateInt:function(){return nt},validateLeftInt:function(){return rt},validatePhone:function(){return it},validatePostCode:function(){return pt},validateRightInt:function(){return ot}});var n={};t.r(n),t.d(n,{maxSort:function(){return s},minSort:function(){return f},unique:function(){return l}});var o={};t.r(o),t.d(o,{deepClone:function(){return y},getRandomSixNum:function(){return m}});var r={};t.r(r),t.d(r,{getElementContent:function(){return g}});var i={};t.r(i),t.d(i,{debounce:function(){return v},throttle:function(){return b}});var a={};t.r(a),t.d(a,{base64ToBlob:function(){return w},base64ToFile:function(){return x},blobToFile:function(){return S},fileToBase64:function(){return h},getApplication:function(){return D}});var c={};t.r(c),t.d(c,{getLocalStorage:function(){return M},setLocalStorage:function(){return O}});var u={};t.r(u),t.d(u,{validateAmount:function(){return E},validateEmail:function(){return A},validateIDCard:function(){return T},validateInt:function(){return j},validateLeftInt:function(){return P},validatePhone:function(){return Y},validatePostCode:function(){return C},validateRightInt:function(){return k}});var p={};function l(t,e){if(e){for(var n=JSON.parse(JSON.stringify(t)),o=0;o<n.length;o++)for(var r=o+1;r<n.length;r++)n[o][e]==n[r][e]&&(n.splice(r,1),r--);return n}for(var i=JSON.parse(JSON.stringify(t)),a=0;a<i.length;a++)for(var c=a+1;c<i.length;c++)i[a]==i[c]&&(i.splice(c,1),c--);return i}function f(t,e){if(e){var n=t;return n.sort((function(t,n){var o=t[e],r=n[e],i=0;return o>r?i=1:o<r&&(i=-1),i})),n}return t.sort((function(t,e){return t-e}))}function s(t,e){if(e){var n=t;return n.sort((function(t,n){var o=t[e],r=n[e],i=0;return o>r?i=1:o<r&&(i=-1),-1*i})),n}return t.sort((function(t,e){return e-t}))}function d(t){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},d(t)}t.r(p),t.d(p,{getDate:function(){return N},getMonday:function(){return F},getWeek:function(){return I}});var m=function(t){for(var e="",n=0;n<t;n++)e+=String(Math.floor(10*Math.random()));return e};function y(t){if(Array.isArray(t)){for(var e=[],n=0;n<t.length;n++)e[n]=y(t[n]);return e}if("object"===d(t)&&null!==t){var o={};for(var r in t)o[r]=y(t[r]);return o}return t}function g(t,e){var n=new RegExp("<"+e+"[\\s\\S]*<\\/"+e+">");console.log(n);var o=n.exec(t);return null!=o&&o.length?o[0]:null}function v(t,e){var n=null;return function(){var o=this;clearTimeout(n),n=setTimeout((function(){t.apply(o,arguments)}),e)}}function b(t,e){var n,o=new Date;return function(){var r=this,i=new Date;clearTimeout(n),i-o>=e?(t.apply(r,arguments),o=i):n=setTimeout((function(){t.apply(r,arguments)}),e)}}function h(t){return new Promise((function(e,n){var o=new FileReader;o.readAsDataURL(t),o.onload=function(t){var n;e(null===(n=t.target)||void 0===n?void 0:n.result)}}))}function w(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=t.split(","),o=n[0].match(/:(.*?);/)[1],r=atob(n[1]),i=r.length,a=new Uint8Array(i);i--;)a[i]=r.charCodeAt(i);return new Blob([a],{type:e||o})}function S(t,e,n){return new File([t],e,{type:n})}function x(t,e){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=t.split(","),r=o[0].match(/:(.*?);/)[1],i=atob(o[1]),a=i.length,c=new Uint8Array(a);a--;)c[a]=i.charCodeAt(a);return new File([c],e,{type:n||r})}function D(t){var e=t.split(".").pop(),n=[{type:"doc",application:"application/msword"},{type:"docx",application:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"},{type:"dot",application:"application/msword"},{type:"dotx",application:"application/vnd.openxmlformats-officedocument.wordprocessingml.template"},{type:"xls",application:"application/vnd.ms-excel"},{type:"xlsx",application:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},{type:"ppt",application:"application/vnd.ms-powerpoint"},{type:"pptx",application:"application/vnd.openxmlformats-officedocument.presentationml.presentation"},{type:"pdf",application:"application/pdf"},{type:"txt",application:"text/plain"},{type:"gif",application:"image/gif"},{type:"jpeg",application:"image/jpeg"},{type:"jpg",application:"image/jpeg"},{type:"png",application:"image/png"},{type:"css",application:"text/css"},{type:"html",application:"text/html"},{type:"htm",application:"text/html"},{type:"xsl",application:"text/xml"},{type:"xml",application:"text/xml"},{type:"mpeg",application:"video/mpeg"},{type:"mpg",application:"video/mpeg"},{type:"avi",application:"video/x-msvideo"},{type:"movie",application:"video/x-sgi-movie"},{type:"bin",application:"application/octet-stream"},{type:"exe",application:"application/octet-stream"},{type:"so",application:"application/octet-stream"},{type:"dll",application:"application/octet-stream"},{type:"ai",application:"application/postscript"},{type:"dir",application:"application/x-director"},{type:"js",application:"application/x-javascript"},{type:"swf",application:"application/x-shockwave-flash"},{type:"xhtml",application:"application/xhtml+xml"},{type:"xht",application:"application/xhtml+xml"},{type:"zip",application:"application/zip"},{type:"mid",application:"audio/midi"},{type:"midi",application:"audio/midi"},{type:"mp3",application:"audio/mpeg"},{type:"rm",application:"audio/x-pn-realaudio"},{type:"rpm",application:"audio/x-pn-realaudio-plugin"},{type:"wav",application:"audio/x-wav"},{type:"bmp",application:"image/bmp"}].find((function(t){return t.type==e}));return(null==n?void 0:n.type)||null}var M=function(t){if(!window)throw new Error("非web环境禁止使用localStorage");if(!t)throw new Error("key的值不能为空");var e=localStorage.getItem(t);return e?JSON.parse(e):null},O=function(t,e){if(!window)throw new Error("非web环境禁止使用localStorage");if(!t||!e)throw new Error("key or value的值不能为空");var n=JSON.stringify(e);localStorage.setItem(t,n)};function j(t){return/^-?[1-9]\d*|0$/.test(t)}function k(t){return/^[1-9]\d*$/.test(t)}function P(t){return/^-[1-9]\d*$/.test(t)}function Y(t){return/^(86)?1[3-9]\d{9}$/.test(t)}function T(t){return/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}(\d|X|x)$/.test(t)}function A(t){return/^[\w.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(t)}function E(t){return/^[0-9]+(.[0-9]{1,2})?$/.test(t)}function C(t){return/[1-9]\d{5}(?!\d)/.test(t)}function I(t){var e="";switch(new Date(t).getDay()){case 0:e="周日";break;case 1:e="周一";break;case 2:e="周二";break;case 3:e="周三";break;case 4:e="周四";break;case 5:e="周五";break;case 6:e="周六"}return e}function F(t,e){if(!t)throw new Error("getMonday的type参数必传");var n=new Date,o=n.getTime(),r=n.getDay(),i=864e5,a=6048e5*(e||0),c=0;"s"==t&&(c=o-(r-1)*i+a),"e"==t&&(c=o+(7-r)*i+a);var u=new Date(c),p=u.getFullYear(),l=u.getMonth()+1,f=u.getDate();return p+"-"+(l=l<10?"0"+l:l)+"-"+(f=f<10?"0"+f:f)}function N(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=new Date(t).getTime()+864e5*n,r=new Date(o),i=r.getFullYear(),a=r.getMonth()+1<10?"0"+(r.getMonth()+1):r.getMonth()+1,c=r.getDate()<10?"0"+r.getDate():r.getDate(),u=r.getHours()<10?"0"+r.getHours():r.getHours(),p=r.getMinutes()<10?"0"+r.getMinutes():r.getMinutes(),l=r.getSeconds()<10?"0"+r.getSeconds():r.getSeconds(),f="";switch(e){case"YYYY/MM/DD HH:MM:SS":f="".concat(i,"/").concat(a,"/").concat(c," ").concat(u,":").concat(p,":").concat(l);break;case"YYYY-MM-DD HH:MM:SS":f="".concat(i,"-").concat(a,"-").concat(c," ").concat(u,":").concat(p,":").concat(l);break;case"YYYY/MM/DD":f="".concat(i,"/").concat(a,"/").concat(c);break;case"YYYY-MM-DD":f="".concat(i,"-").concat(a,"-").concat(c);break;case"MM/DD":f="".concat(a,"/").concat(c);break;case"MM-DD":f="".concat(a,"-").concat(c);break;case"MM":f="".concat(p);case"DD":f="".concat(c)}return f}function H(t){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H(t)}function L(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function R(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?L(Object(n),!0).forEach((function(e){$(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function $(t,e,n){return(e=function(t){var e=function(t,e){if("object"!==H(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==H(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===H(e)?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var J=l,B=f,z=s,_=m,U=y,q=g,W=v,Z=b,X=D,G=h,K=w,Q=S,V=x,tt=M,et=O,nt=j,ot=k,rt=P,it=Y,at=T,ct=A,ut=E,pt=C,lt=N,ft=F,st=I,dt=R(R(R(R(R(R(R(R({},n),o),r),i),a),c),p),u);return e}()}));
|
|
1
|
+
return t=function(){return(function(){function t(t){return(function(t){if(Array.isArray(t))return e(t)})(t)||(function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)})(t)||(function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}
|
|
2
|
+
})(t)||(function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})()}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);e>n;n++)r[n]=t[n];return r}function n(e,n){var r,o,i=t(e);return n?(r=new Map,i.filter(function(t){var e=t[n];return!r.has(e)&&(r.set(e,!0),!0)})):Array.isArray(i[0])?(o=new Set,i.filter(function(t){var e=JSON.stringify(t)
|
|
3
|
+
;return!o.has(e)&&(o.add(e),!0)})):Array.from(new Set(i))}function r(e,n){var r=t(e);return n?r.sort(function(t,e){var r=t[n],o=e[n];return"string"==typeof r&&"string"==typeof o?r.localeCompare(o,void 0,{sensitivity:"base"}):r>o?1:o>r?-1:0}):r.sort(function(t,e){return"string"==typeof t&&"string"==typeof e?t.localeCompare(e,void 0,{sensitivity:"base"}):t-e}),r}function o(e,n){var r=t(e);return n?r.sort(function(t,e){var r=t[n],o=e[n]
|
|
4
|
+
;return"string"==typeof r&&"string"==typeof o?o.localeCompare(r,void 0,{sensitivity:"base"}):o>r?1:r>o?-1:0}):r.sort(function(t,e){return"string"==typeof t&&"string"==typeof e?e.localeCompare(t,void 0,{sensitivity:"base"}):e-t}),r}function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function a(t){var e,n,r,o
|
|
5
|
+
;if(null===t||"object"!==i(t))return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return RegExp(t.source,t.flags);if(Array.isArray(t)){for(e=[],n=0;n<t.length;n++)e.push(a(t[n]));return e}if("object"===i(t)){for(o in r={},t)({}).hasOwnProperty.call(t,o)&&(r[o]=a(t[o]));return r}return t}function u(t){var e,n;if(""===t||null==t)return!0;if("object"===i(t)){if(Array.isArray(t))return 0===t.length;for(n in e=!1,t)if({}.hasOwnProperty.call(t,n)){e=!0;break}return!e}
|
|
6
|
+
return!1}function l(t,e){var n,r,o,i,a,u,l,c,f,s={};for(n=0;n<t.length;n++){for(r=t[n],o=[],i=0;i<e.length;i++)o.push(r[e[i]]);for(a=!1,u=0;u<o.length;u++)if(void 0===o[u]){a=!0;break}if(a)throw Error("\u4f20\u5165\u7684keys\u6709\u8bef");s[l=o.join(",")]?s[l].push(r):s[l]=[r]}for(f in c=[],s)({}).hasOwnProperty.call(s,f)&&c.push({group:f,data:s[f]});return c}function c(t){return{}.toString.call(t).slice(8,-1)}function f(t,e){var n,r,o,i,a,u,l
|
|
7
|
+
;if(2>arguments.length)throw Error("Incorrect number of parameters");if((n=c(t))!==c(e))return!1;if("Array"!==n&&"Object"!==n)return"Number"===n&&isNaN(t)?isNaN(e):"Date"===n||"RegExp"===n?t.toString()===e.toString():t===e;if("Array"===n){if(t.length!==e.length)return!1;for(r=0;r<t.length;r++)if(!f(t[r],e[r]))return!1;return!0}if("Object"===n){for(i in o=[],t)({}).hasOwnProperty.call(t,i)&&o.push(i);for(i in a=[],e)({}).hasOwnProperty.call(e,i)&&a.push(i);if(o.length!==a.length)return!1
|
|
8
|
+
;for(r=0;r<o.length;r++){for(i=o[r],u=!1,l=0;l<a.length;l++)if(a[l]===i){u=!0;break}if(!u||!f(t[i],e[i]))return!1}return!0}return!0}function s(t,e){var n;if("string"!=typeof t||"string"!=typeof e)return null;if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e))return null;try{return(n=RegExp("<"+e+"[^>]*>([\\s\\S]*?)<\\/"+e+">","i").exec(t))?n[0]:null}catch(t){return null}}function d(t,e){var n;if("string"!=typeof t||"string"!=typeof e)return null;if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e))return null;try{
|
|
9
|
+
return(n=RegExp("<"+e+"[^>]*>([\\s\\S]*?)<\\/"+e+">","i").exec(t))?n[1].replace(/<[^>]+>/g,"").replace(/^\s+|\s+$/g,""):null}catch(t){return null}}function p(t,e){var n,r,o;if("string"!=typeof t||"string"!=typeof e)return[];if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e))return[];try{for(n=RegExp("<"+e+"[^>]*>([\\s\\S]*?)<\\/"+e+">","gi"),r=[];null!==(o=n.exec(t));)r.push(o[0]);return r}catch(t){return[]}}function m(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=null,o=function(){
|
|
10
|
+
var o,i=this,a=arguments;r&&clearTimeout(r),n?(o=!r,r=setTimeout(function(){r=null},e),o&&t.apply(i,a)):r=setTimeout(function(){t.apply(i,a)},e)};return o.cancel=function(){r&&(clearTimeout(r),r=null)},o}function g(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=null,o=0,i=!1!==n.leading,a=!1!==n.trailing,u=function(){var n,u=this,l=arguments,c=Date.now();o||i||(o=c),0>=(n=e-(c-o))||n>e?(r&&(clearTimeout(r),r=null),o=c,t.apply(u,l)):!r&&a&&(r=setTimeout(function(){
|
|
11
|
+
o=i?Date.now():0,r=null,t.apply(u,l)},n))};return u.cancel=function(){r&&(clearTimeout(r),r=null),o=0},u}function v(t,e){if(t){var n=new FileReader;n.readAsDataURL(t),n.onload=function(t){t.target&&t.target.result?e(null,t.target.result):e(Error("Failed to convert file to base64"),null)},n.onerror=function(){e(Error("Error reading file"),null)}}else e(Error("File is required"),null)}function y(t){var e,n,r,o,i,a,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:""
|
|
12
|
+
;if(!t||"string"!=typeof t)throw Error("Invalid dataURL");if(2>(e=t.split(",")).length)throw Error("Invalid dataURL format");if(!(n=e[0].match(/:(.*?);/)))throw Error("Invalid dataURL format");for(r=n[1],i=(o=atob(e[1])).length,a=new Uint8Array(i),u=0;i>u;u++)a[u]=o.charCodeAt(u);return new Blob([a],{type:l||r})}function h(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.type;if(!t||!e)throw Error("Blob and fileName are required");return new File([t],e,{type:n})}
|
|
13
|
+
function b(t,e){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(!t||!e)throw Error("dataURL and fileName are required");return h(n=y(t,r),e,r||n.type)}function S(t){var e,n;return t&&"string"==typeof t&&(n=(e=t.split(".")).length>0?e[e.length-1].toLowerCase():null)&&bt[n]||null}function w(t,e){var n,r;if(!t||!e)throw Error("Data and fileName are required");n=URL.createObjectURL(t),(r=document.createElement("a")).href=n,r.download=e,document.body.appendChild(r),r.click(),
|
|
14
|
+
document.body.removeChild(r),URL.revokeObjectURL(n)}function E(t,e){var n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="blob",n.onload=function(){200===n.status?e(null,n.response):e(Error("HTTP error! status: "+n.status),null)},n.onerror=function(){e(Error("Network error"),null)},n.send()}function T(t,e){if(!St())return e||null;if(!t)throw Error("key cannot be empty");try{var n=localStorage.getItem(t);return n?JSON.parse(n):e||null}catch(t){return e||null}}function D(t,e,n){if(St()){
|
|
15
|
+
if(!t)throw Error("key cannot be empty");try{var r={value:e,expire:n?Date.now()+n:null};localStorage.setItem(t,JSON.stringify(r))}catch(t){t.name}}}function A(t){if(St()){if(!t)throw Error("key cannot be empty");try{localStorage.removeItem(t)}catch(t){}}}function x(){if(St())try{localStorage.clear()}catch(t){}}function I(){var t,e,n;if(!St())return[];try{for(t=[],e=0;e<localStorage.length;e++)(n=localStorage.key(e))&&t.push(n);return t}catch(t){return[]}}function O(t){var e="".concat(t,":")
|
|
16
|
+
;return{get:function(t,n){return T("".concat(e).concat(t),n)},set:function(t,n,r){D("".concat(e).concat(t),n,r)},remove:function(t){A("".concat(e).concat(t))},clear:function(){I().forEach(function(t){t.startsWith(e)&&A(t)})},keys:function(){return I().filter(function(t){return t.startsWith(e)}).map(function(t){return t.replace(e,"")})}}}function R(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);e>n;n++)r[n]=t[n];return r}function P(){
|
|
17
|
+
var t=Math.floor(16777215*Math.random()).toString(16);return"#"+("000000".substring(0,6-t.length)+t)}function M(t){var e,n,r,o,i,a,u,l,c,f,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("number"!=typeof t||1>t)throw Error("Length must be a positive number");if(n=void 0===(e=s.includeLetters)||e,o=void 0===(r=s.includeNumbers)||r,a=void 0!==(i=s.includeSymbols)&&i,u=s.caseSensitive,l="",
|
|
18
|
+
n&&(l+=void 0===u||u?"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":"abcdefghijklmnopqrstuvwxyz"),o&&(l+="0123456789"),a&&(l+="!@#$%^&*()_+-=[]{}|;:,.<>?"),0===l.length)throw Error("At least one character set must be included");for(c="",f=0;t>f;f++)c+=l[Math.floor(Math.random()*l.length)];return c}function j(t,e){if("number"!=typeof t||"number"!=typeof e)throw Error("Min and max must be numbers");if(t>e){var n=[e,t];t=n[0],e=n[1]}return Math.floor(Math.random()*(e-t+1))+t}
|
|
19
|
+
function L(t,e){var n,r,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;if("number"!=typeof t||"number"!=typeof e)throw Error("Min and max must be numbers");return t>e&&(t=(n=[e,t])[0],e=n[1]),r=Math.random()*(e-t)+t,parseFloat(r.toFixed(o))}function N(t){if(Array.isArray(t)&&0!==t.length)return t[Math.floor(Math.random()*t.length)]}function C(t){var e,n,r,o,i;if(!Array.isArray(t))throw Error("Input must be an array");for(n=(i=t,e=(function(t){if(Array.isArray(t))return R(t)
|
|
20
|
+
})(i)||(function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)})(i)||(function(t,e){if(t){if("string"==typeof t)return R(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(t,e):void 0}})(i)||(function(){
|
|
21
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})()).length-1;n>0;n--)o=[e[r=Math.floor(Math.random()*(n+1))],e[n]],e[n]=o[0],e[r]=o[1];return e}function F(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=M(arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,{includeLetters:!0,includeNumbers:!0,caseSensitive:!0});return t?"".concat(t,"_").concat(e):e}function k(t){
|
|
22
|
+
var e=t+"";return Et.INT.test(e)}function _(t){var e=t+"";return Et.POSITIVE_INT.test(e)}function U(t){var e=t+"";return Et.NEGATIVE_INT.test(e)}function $(t){return Et.PHONE.test(t)}function z(t){return Et.TELEPHONE.test(t)}function Z(t){return Et.ID_CARD.test(t)}function Y(t){return Et.EMAIL.test(t)}function q(t){var e=t+"";return Et.AMOUNT.test(e)}function W(t){return Et.POST_CODE.test(t)}function H(t){return Et.URL.test(t)}function B(t){return Et.PASSWORD.test(t)}function G(t){
|
|
23
|
+
return Et.DATE.test(t)}function V(t){return Et.TIME.test(t)}function X(t){return Et.IPV4.test(t)}function J(t){if(!t)throw Error("Date parameter is required");return["\u5468\u65e5","\u5468\u4e00","\u5468\u4e8c","\u5468\u4e09","\u5468\u56db","\u5468\u4e94","\u5468\u516d"][new Date(t).getDay()]}function K(t){var e,n,r,o,i,a,u,l,c,f,s,d=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!t)throw Error("Type parameter is required");return n=(e=new Date).getTime(),r=e.getDay(),
|
|
24
|
+
i=7*(o=864e5)*d,u=(a=new Date("s"===t?n+(0===r?-6:1-r)*o+i:n+(0===r?0:7-r)*o+i)).getFullYear(),l=a.getMonth()+1+"",c=a.getDate()+"",f=("0"+l).slice(-2),s=("0"+c).slice(-2),"".concat(u,"-").concat(f,"-").concat(s)}function Q(t){var e,n,r,o,i,a,u,l,c,f,s,d,p,m=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD",g=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return t?(e=new Date(t).getTime()+864e5*g,r=(n=new Date(e)).getFullYear(),o=n.getMonth()+1+"",i=n.getDate()+"",
|
|
25
|
+
a=n.getHours()+"",u=n.getMinutes()+"",l=n.getSeconds()+"",c=("0"+o).slice(-2),f=("0"+i).slice(-2),s=("0"+a).slice(-2),d=("0"+u).slice(-2),p=("0"+l).slice(-2),m.replace("YYYY",r+"").replace("MM",c).replace("DD",f).replace("HH",s).replace("mm",d).replace("ss",p)):""}function tt(t,e){var n=new Date(t).getTime(),r=new Date(e).getTime();return Math.floor(Math.abs(n-r)/864e5)}function et(t){var e=new Date,n=new Date(t)
|
|
26
|
+
;return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function nt(t){var e=new Date,n=new Date(t),r=e.getTime()-n.getTime(),o=Math.floor(r/6e4),i=Math.floor(r/36e5),a=Math.floor(r/864e5)
|
|
27
|
+
;return 1>o?"\u521a\u521a":60>o?"".concat(o,"\u5206\u949f\u524d"):24>i?"".concat(i,"\u5c0f\u65f6\u524d"):7>a?"".concat(a,"\u5929\u524d"):30>a?"".concat(Math.floor(a/7),"\u5468\u524d"):365>a?"".concat(Math.floor(a/30),"\u4e2a\u6708\u524d"):"".concat(Math.floor(a/365),"\u5e74\u524d")}function rt(t,e){return new Date(t,e,0).getDate()}function ot(){return 0>=arguments.length||void 0===arguments[0]||arguments[0]?Date.now():Math.floor(Date.now()/1e3)}function it(t){
|
|
28
|
+
return it="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},it(t)}function at(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function ut(t){var e,n
|
|
29
|
+
;for(e=1;arguments.length>e;e++)n=null!=arguments[e]?arguments[e]:{},e%2?at(Object(n),!0).forEach(function(e){lt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):at(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))});return t}function lt(t,e,n){return(e=(function(t){var e=(function(t){var e,n;if("object"!=it(t)||!t)return t;if(void 0!==(e=t[Symbol.toPrimitive])){
|
|
30
|
+
if("object"!=it(n=e.call(t,"string")))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return t+""})(t);return"symbol"==it(e)?e:e+""})(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var ct,ft,st,dt,pt,mt,gt,vt,yt,ht,bt,St,wt,Et,Tt,Dt,At,xt,It,Ot,Rt,Pt,Mt,jt,Lt,Nt,Ct,Ft,kt,_t,Ut,$t,zt,Zt,Yt,qt,Wt,Ht,Bt,Gt,Vt,Xt,Jt,Kt,Qt,te,ee,ne,re,oe,ie,ae,ue,le,ce,fe,se,de,pe,me,ge,ve,ye,he,be,Se,we,Ee,Te,De,Ae,xe,Ie={d:function(t,e){
|
|
31
|
+
for(var n in e)Ie.o(e,n)&&!Ie.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:function(t,e){return{}.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};return ct={},Ie.r(ct),Ie.d(ct,{REGEX:function(){return he},base64ToBlob:function(){return Ut},base64ToFile:function(){return zt},blobToFile:function(){return $t},
|
|
32
|
+
clearLocalStorage:function(){return Gt},createNamespacedStorage:function(){return Xt},debounce:function(){return Ft},deepClone:function(){return Ot},default:function(){return Dt},downloadFile:function(){return Yt},fileToBase64:function(){return _t},formatDate:function(){return we},generateRandomId:function(){return re},getAllElements:function(){return Ct},getApplication:function(){return Zt},getDataType:function(){return jt},getDaysDiff:function(){return Ee},getDaysInMonth:function(){return Ae},
|
|
33
|
+
getElementContent:function(){return Lt},getElementText:function(){return Nt},getFileFromUrl:function(){return qt},getLocalStorage:function(){return Wt},getLocalStorageKeys:function(){return Vt},getRandomColor:function(){return Jt},getRandomElement:function(){return ee},getRandomFloat:function(){return te},getRandomInt:function(){return Qt},getRandomString:function(){return Kt},getRelativeTime:function(){return De},getTimestamp:function(){return xe},getWeek:function(){return be},
|
|
34
|
+
getWeekRange:function(){return Se},group:function(){return Pt},isEmpty:function(){return Rt},isSame:function(){return Mt},isToday:function(){return Te},maxSort:function(){return It},minSort:function(){return xt},removeLocalStorage:function(){return Bt},setLocalStorage:function(){return Ht},shuffleArray:function(){return ne},superToolkit:function(){return Tt},throttle:function(){return kt},unique:function(){return At},validateAmount:function(){return se},validateDate:function(){return ge},
|
|
35
|
+
validateEmail:function(){return fe},validateIDCard:function(){return ce},validateIPv4:function(){return ye},validateInt:function(){return oe},validateNegativeInt:function(){return ae},validatePassword:function(){return me},validatePhone:function(){return ue},validatePositiveInt:function(){return ie},validatePostCode:function(){return de},validateTelephone:function(){return le},validateTime:function(){return ve},validateUrl:function(){return pe}}),ft={},Ie.r(ft),Ie.d(ft,{maxSort:function(){
|
|
36
|
+
return o},minSort:function(){return r},unique:function(){return n}}),st={},Ie.r(st),Ie.d(st,{deepClone:function(){return a},getDataType:function(){return c},group:function(){return l},isEmpty:function(){return u},isSame:function(){return f}}),dt={},Ie.r(dt),Ie.d(dt,{getAllElements:function(){return p},getElementContent:function(){return s},getElementText:function(){return d}}),pt={},Ie.r(pt),Ie.d(pt,{debounce:function(){return m},throttle:function(){return g}}),mt={},Ie.r(mt),Ie.d(mt,{
|
|
37
|
+
base64ToBlob:function(){return y},base64ToFile:function(){return b},blobToFile:function(){return h},downloadFile:function(){return w},fileToBase64:function(){return v},getApplication:function(){return S},getFileFromUrl:function(){return E}}),gt={},Ie.r(gt),Ie.d(gt,{clearLocalStorage:function(){return x},createNamespacedStorage:function(){return O},default:function(){return wt},getLocalStorage:function(){return T},getLocalStorageKeys:function(){return I},removeLocalStorage:function(){return A},
|
|
38
|
+
setLocalStorage:function(){return D}}),vt={},Ie.r(vt),Ie.d(vt,{generateRandomId:function(){return F},getRandomColor:function(){return P},getRandomElement:function(){return N},getRandomFloat:function(){return L},getRandomInt:function(){return j},getRandomString:function(){return M},shuffleArray:function(){return C}}),yt={},Ie.r(yt),Ie.d(yt,{REGEX:function(){return Et},validateAmount:function(){return q},validateDate:function(){return G},validateEmail:function(){return Y},
|
|
39
|
+
validateIDCard:function(){return Z},validateIPv4:function(){return X},validateInt:function(){return k},validateNegativeInt:function(){return U},validatePassword:function(){return B},validatePhone:function(){return $},validatePositiveInt:function(){return _},validatePostCode:function(){return W},validateTelephone:function(){return z},validateTime:function(){return V},validateUrl:function(){return H}}),ht={},Ie.r(ht),Ie.d(ht,{formatDate:function(){return Q},getDaysDiff:function(){return tt},
|
|
40
|
+
getDaysInMonth:function(){return rt},getRelativeTime:function(){return nt},getTimestamp:function(){return ot},getWeek:function(){return J},getWeekRange:function(){return K},isToday:function(){return et}}),bt={doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",dot:"application/msword",dotx:"application/vnd.openxmlformats-officedocument.wordprocessingml.template",xls:"application/vnd.ms-excel",
|
|
41
|
+
xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",pdf:"application/pdf",txt:"text/plain",gif:"image/gif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",css:"text/css",html:"text/html",htm:"text/html",xsl:"text/xml",xml:"text/xml",mpeg:"video/mpeg",mpg:"video/mpeg",avi:"video/x-msvideo",movie:"video/x-sgi-movie",bin:"application/octet-stream",
|
|
42
|
+
exe:"application/octet-stream",so:"application/octet-stream",dll:"application/octet-stream",ai:"application/postscript",dir:"application/x-director",js:"application/x-javascript",swf:"application/x-shockwave-flash",xhtml:"application/xhtml+xml",xht:"application/xhtml+xml",zip:"application/zip",mid:"audio/midi",midi:"audio/midi",mp3:"audio/mpeg",rm:"audio/x-pn-realaudio",rpm:"audio/x-pn-realaudio-plugin",wav:"audio/x-wav",bmp:"image/bmp"},St=function(){if("undefined"==typeof window)return!1;try{
|
|
43
|
+
var t="__localStorage_test__";return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}},wt={get:T,set:D,remove:A,clear:x,keys:I,createNamespaced:O},Et={INT:/^-?\d+$/,POSITIVE_INT:/^[1-9]\d*$/,NEGATIVE_INT:/^-[1-9]\d*$/,PHONE:/^(86)?1[3-9]\d{9}$/,TELEPHONE:/^(\d{3}-?\d{7,8}|\d{4}-?\d{7,8})$/,ID_CARD:/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[0-1])\d{3}(\d|X|x)$/,EMAIL:/^[\w.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,AMOUNT:/^[0-9]+(\.[0-9]{1,2})?$/,
|
|
44
|
+
POST_CODE:/^[1-9]\d{5}$/,URL:/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/,PASSWORD:/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,DATE:/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,TIME:/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/,IPV4:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/},Tt=ut(ut(ut(ut(ut(ut(ut(ut(ut({},ft),st),dt),pt),mt),gt),vt),yt),ht),Dt=Tt,At=Tt.unique,xt=Tt.minSort,
|
|
45
|
+
It=Tt.maxSort,Ot=Tt.deepClone,Rt=Tt.isEmpty,Pt=Tt.group,Mt=Tt.isSame,jt=Tt.getDataType,Lt=Tt.getElementContent,Nt=Tt.getElementText,Ct=Tt.getAllElements,Ft=Tt.debounce,kt=Tt.throttle,_t=Tt.fileToBase64,Ut=Tt.base64ToBlob,$t=Tt.blobToFile,zt=Tt.base64ToFile,Zt=Tt.getApplication,Yt=Tt.downloadFile,qt=Tt.getFileFromUrl,Wt=Tt.getLocalStorage,Ht=Tt.setLocalStorage,Bt=Tt.removeLocalStorage,Gt=Tt.clearLocalStorage,Vt=Tt.getLocalStorageKeys,Xt=Tt.createNamespacedStorage,Jt=Tt.getRandomColor,
|
|
46
|
+
Kt=Tt.getRandomString,Qt=Tt.getRandomInt,te=Tt.getRandomFloat,ee=Tt.getRandomElement,ne=Tt.shuffleArray,re=Tt.generateRandomId,oe=Tt.validateInt,ie=Tt.validatePositiveInt,ae=Tt.validateNegativeInt,ue=Tt.validatePhone,le=Tt.validateTelephone,ce=Tt.validateIDCard,fe=Tt.validateEmail,se=Tt.validateAmount,de=Tt.validatePostCode,pe=Tt.validateUrl,me=Tt.validatePassword,ge=Tt.validateDate,ve=Tt.validateTime,ye=Tt.validateIPv4,he=Tt.REGEX,be=Tt.getWeek,Se=Tt.getWeekRange,we=Tt.formatDate,
|
|
47
|
+
Ee=Tt.getDaysDiff,Te=Tt.isToday,De=Tt.getRelativeTime,Ae=Tt.getDaysInMonth,xe=Tt.getTimestamp,ct})()},void("object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["super-toolkit"]=t():this["super-toolkit"]=t());var t;
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "super-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "一个轻量级的
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "一个轻量级的javaScript超级工具库",
|
|
5
5
|
"main": "lib/super-toolkit.min.js",
|
|
6
|
+
"module": "index.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"build": "webpack --config webpack.config.js"
|
|
8
|
+
"build": "webpack --config webpack.config.js",
|
|
9
|
+
"build:analyze": "webpack --config webpack.config.js --profile --json > stats.json"
|
|
8
10
|
},
|
|
9
11
|
"types": "index.d.ts",
|
|
10
12
|
"keywords": [],
|
|
11
13
|
"author": "yanxiufei",
|
|
12
14
|
"license": "ISC",
|
|
15
|
+
"sideEffects": false,
|
|
13
16
|
"devDependencies": {
|
|
14
17
|
"@babel/core": "^7.22.11",
|
|
15
18
|
"@babel/preset-env": "^7.22.10",
|
package/src/array.ts
CHANGED
|
@@ -1,74 +1,99 @@
|
|
|
1
1
|
/** 数组去重 */
|
|
2
|
-
export function unique<T
|
|
2
|
+
export function unique<T extends Record<string, any>[] | Array<any>>(oldArr: T, key?: string): T {
|
|
3
|
+
// 创建数组副本
|
|
4
|
+
const arr = [...oldArr]
|
|
5
|
+
|
|
3
6
|
if (key) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// 使用 Map 去重,时间复杂度 O(n)
|
|
8
|
+
const seen = new Map()
|
|
9
|
+
return arr.filter(item => {
|
|
10
|
+
const value = item[key]
|
|
11
|
+
if (seen.has(value)) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
seen.set(value, true)
|
|
15
|
+
return true
|
|
16
|
+
}) as T
|
|
14
17
|
} else {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
// 使用 Set 去重,时间复杂度 O(n)
|
|
19
|
+
if (Array.isArray(arr[0])) {
|
|
20
|
+
// 处理数组元素为数组的情况
|
|
21
|
+
const seen = new Set()
|
|
22
|
+
return arr.filter(item => {
|
|
23
|
+
const str = JSON.stringify(item)
|
|
24
|
+
if (seen.has(str)) {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
seen.add(str)
|
|
28
|
+
return true
|
|
29
|
+
}) as T
|
|
30
|
+
} else {
|
|
31
|
+
// 处理基本类型和对象
|
|
32
|
+
return Array.from(new Set(arr)) as T
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
}
|
|
36
|
+
|
|
27
37
|
/** 数组排序,从小到大 */
|
|
28
|
-
export function minSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key
|
|
38
|
+
export function minSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key?: string): T {
|
|
39
|
+
// 创建数组副本,避免修改原数组
|
|
40
|
+
const list = [...arr]
|
|
41
|
+
|
|
29
42
|
if (key) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
comparison = 1;
|
|
38
|
-
} else if (bandA < bandB) {
|
|
39
|
-
comparison = -1;
|
|
43
|
+
list.sort((a, b) => {
|
|
44
|
+
const valA = (a as Record<string, any>)[key]
|
|
45
|
+
const valB = (b as Record<string, any>)[key]
|
|
46
|
+
|
|
47
|
+
// 实现忽略大小写功能
|
|
48
|
+
if (typeof valA === 'string' && typeof valB === 'string') {
|
|
49
|
+
return valA.localeCompare(valB, undefined, { sensitivity: 'base' })
|
|
40
50
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
|
|
52
|
+
// 其他类型比较
|
|
53
|
+
if (valA > valB) return 1
|
|
54
|
+
if (valA < valB) return -1
|
|
55
|
+
return 0
|
|
56
|
+
})
|
|
45
57
|
} else {
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
list.sort((a, b) => {
|
|
59
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
60
|
+
return a.localeCompare(b, undefined, { sensitivity: 'base' })
|
|
61
|
+
}
|
|
62
|
+
return (a as number) - (b as number)
|
|
63
|
+
})
|
|
48
64
|
}
|
|
65
|
+
|
|
66
|
+
return list as T
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
/** 数组排序,从大到小 */
|
|
52
|
-
export function maxSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key
|
|
70
|
+
export function maxSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key?: string): T {
|
|
71
|
+
// 创建数组副本,避免修改原数组
|
|
72
|
+
const list = [...arr]
|
|
73
|
+
|
|
53
74
|
if (key) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (bandA > bandB) {
|
|
62
|
-
comparison = 1;
|
|
63
|
-
} else if (bandA < bandB) {
|
|
64
|
-
comparison = -1;
|
|
75
|
+
list.sort((a, b) => {
|
|
76
|
+
const valA = (a as Record<string, any>)[key]
|
|
77
|
+
const valB = (b as Record<string, any>)[key]
|
|
78
|
+
|
|
79
|
+
// 实现忽略大小写功能
|
|
80
|
+
if (typeof valA === 'string' && typeof valB === 'string') {
|
|
81
|
+
return valB.localeCompare(valA, undefined, { sensitivity: 'base' })
|
|
65
82
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
|
|
84
|
+
// 其他类型比较
|
|
85
|
+
if (valB > valA) return 1
|
|
86
|
+
if (valB < valA) return -1
|
|
87
|
+
return 0
|
|
88
|
+
})
|
|
70
89
|
} else {
|
|
71
|
-
|
|
72
|
-
|
|
90
|
+
list.sort((a, b) => {
|
|
91
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
92
|
+
return b.localeCompare(a, undefined, { sensitivity: 'base' })
|
|
93
|
+
}
|
|
94
|
+
return (b as number) - (a as number)
|
|
95
|
+
})
|
|
73
96
|
}
|
|
97
|
+
|
|
98
|
+
return list as T
|
|
74
99
|
}
|