super-toolkit 1.0.4 → 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 +17 -0
- package/index.d.ts +5 -1
- package/index.ts +63 -32
- package/lib/super-toolkit.min.js +47 -1
- package/package.json +5 -2
- package/src/array.ts +81 -56
- package/src/data.ts +160 -35
- 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 +157 -15
- package/src/reg.ts +164 -40
- package/src/time.ts +170 -85
- package/tsconfig.json +15 -8
- package/webpack.config.js +76 -4
package/.babelrc
CHANGED
package/README.md
CHANGED
|
@@ -67,6 +67,23 @@ npm i super-toolkit -S
|
|
|
67
67
|
* @return:{Array}
|
|
68
68
|
*/
|
|
69
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}
|
|
85
|
+
*/
|
|
86
|
+
```
|
|
70
87
|
##### getElementContent
|
|
71
88
|
```js
|
|
72
89
|
/**
|
package/index.d.ts
CHANGED
|
@@ -14,7 +14,11 @@ declare module "super-toolkit" {
|
|
|
14
14
|
export const isEmpty: (value: string | number | any[] | Record<string, any> | null | undefined) => boolean
|
|
15
15
|
/** 数据分组筛选 */
|
|
16
16
|
export const group: <T extends Record<string, any>[] = any[]>(array: T, keys: string[]) => {group: string;data: T;}[]
|
|
17
|
-
|
|
17
|
+
/** 判断两个参数的数据是否一样 */
|
|
18
|
+
const isSame: (sourceData: any, compareData: any) => boolean
|
|
19
|
+
/** 返回参数的数据类型 */
|
|
20
|
+
const getDataType: (data: any) => string
|
|
21
|
+
|
|
18
22
|
/** 获取指定节点内容 */
|
|
19
23
|
export const getElementContent: (msg: string, el: string) => string | null
|
|
20
24
|
|
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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'
|
|
@@ -8,64 +8,95 @@ import * as random from './src/random'
|
|
|
8
8
|
import * as reg from './src/reg'
|
|
9
9
|
import * as time from './src/time'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
const {getElementContent}=elelemt
|
|
14
|
-
const {onDebounce,onThrottle}=event
|
|
15
|
-
const { getApplication,fileToBase64,base64ToBlob,blobToFile,base64ToFile } = file
|
|
16
|
-
const { getLocalStorage, setLocalStorage } = localStorage
|
|
17
|
-
const {getRandomColor,getRandomString} = random
|
|
18
|
-
const {validateInt,validateRightInt,validateLeftInt,validatePhone,validateIDCard,validateEmail,validateAmount,validatePostCode}=reg
|
|
19
|
-
const { getDate, getMonday, getWeek } = time
|
|
20
|
-
const superToolkit = {
|
|
11
|
+
// 导出所有模块
|
|
12
|
+
export const superToolkit = {
|
|
21
13
|
...array,
|
|
22
14
|
...data,
|
|
23
|
-
...
|
|
15
|
+
...element,
|
|
24
16
|
...event,
|
|
25
17
|
...file,
|
|
26
18
|
...localStorage,
|
|
27
19
|
...random,
|
|
28
20
|
...reg,
|
|
29
21
|
...time,
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
superToolkit as default,
|
|
22
|
+
}
|
|
33
23
|
|
|
24
|
+
// 导出默认对象
|
|
25
|
+
export default superToolkit
|
|
26
|
+
|
|
27
|
+
// 单独导出常用函数
|
|
28
|
+
export const {
|
|
29
|
+
// array
|
|
34
30
|
unique,
|
|
35
31
|
minSort,
|
|
36
32
|
maxSort,
|
|
37
|
-
|
|
33
|
+
|
|
34
|
+
// data
|
|
38
35
|
deepClone,
|
|
39
36
|
isEmpty,
|
|
40
37
|
group,
|
|
41
|
-
|
|
38
|
+
isSame,
|
|
39
|
+
getDataType,
|
|
40
|
+
|
|
41
|
+
// element
|
|
42
42
|
getElementContent,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
getElementText,
|
|
44
|
+
getAllElements,
|
|
45
|
+
|
|
46
|
+
// event
|
|
47
|
+
debounce,
|
|
48
|
+
throttle,
|
|
49
|
+
|
|
50
|
+
// file
|
|
48
51
|
fileToBase64,
|
|
49
52
|
base64ToBlob,
|
|
50
53
|
blobToFile,
|
|
51
54
|
base64ToFile,
|
|
52
|
-
|
|
55
|
+
getApplication,
|
|
56
|
+
downloadFile,
|
|
57
|
+
getFileFromUrl,
|
|
58
|
+
|
|
59
|
+
// localStorage
|
|
53
60
|
getLocalStorage,
|
|
54
61
|
setLocalStorage,
|
|
55
|
-
|
|
62
|
+
removeLocalStorage,
|
|
63
|
+
clearLocalStorage,
|
|
64
|
+
getLocalStorageKeys,
|
|
65
|
+
createNamespacedStorage,
|
|
66
|
+
|
|
67
|
+
// random
|
|
56
68
|
getRandomColor,
|
|
57
69
|
getRandomString,
|
|
58
|
-
|
|
70
|
+
getRandomInt,
|
|
71
|
+
getRandomFloat,
|
|
72
|
+
getRandomElement,
|
|
73
|
+
shuffleArray,
|
|
74
|
+
generateRandomId,
|
|
75
|
+
|
|
76
|
+
// reg
|
|
59
77
|
validateInt,
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
validatePositiveInt,
|
|
79
|
+
validateNegativeInt,
|
|
62
80
|
validatePhone,
|
|
81
|
+
validateTelephone,
|
|
63
82
|
validateIDCard,
|
|
64
83
|
validateEmail,
|
|
65
84
|
validateAmount,
|
|
66
85
|
validatePostCode,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["super-toolkit"]=n():t["super-toolkit"]=n()}(this,(function(){return function(){"use strict";var t={d:function(n,e){for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{base64ToBlob:function(){return et},base64ToFile:function(){return ot},blobToFile:function(){return rt},deepClone:function(){return Z},default:function(){return wt},fileToBase64:function(){return nt},getApplication:function(){return tt},getDate:function(){return vt},getElementContent:function(){return K},getLocalStorage:function(){return it},getMonday:function(){return bt},getRandomColor:function(){return ct},getRandomString:function(){return ut},getWeek:function(){return ht},group:function(){return G},isEmpty:function(){return X},maxSort:function(){return W},minSort:function(){return q},onDebounce:function(){return Q},onThrottle:function(){return V},setLocalStorage:function(){return at},unique:function(){return U},validateAmount:function(){return mt},validateEmail:function(){return yt},validateIDCard:function(){return dt},validateInt:function(){return pt},validateLeftInt:function(){return ft},validatePhone:function(){return st},validatePostCode:function(){return gt},validateRightInt:function(){return lt}});var e={};t.r(e),t.d(e,{maxSort:function(){return d},minSort:function(){return s},unique:function(){return f}});var r={};t.r(r),t.d(r,{deepClone:function(){return m},group:function(){return v},isEmpty:function(){return g}});var o={};t.r(o),t.d(o,{getElementContent:function(){return b}});var i={};t.r(i),t.d(i,{onDebounce:function(){return h},onThrottle:function(){return w}});var a={};t.r(a),t.d(a,{base64ToBlob:function(){return x},base64ToFile:function(){return M},blobToFile:function(){return D},fileToBase64:function(){return S},getApplication:function(){return j}});var c={};t.r(c),t.d(c,{getLocalStorage:function(){return O},setLocalStorage:function(){return k}});var u={};t.r(u),t.d(u,{getRandomColor:function(){return P},getRandomString:function(){return T}});var p={};t.r(p),t.d(p,{validateAmount:function(){return R},validateEmail:function(){return F},validateIDCard:function(){return I},validateInt:function(){return E},validateLeftInt:function(){return A},validatePhone:function(){return C},validatePostCode:function(){return H},validateRightInt:function(){return Y}});var l={};function f(t,n){if(n){for(var e=JSON.parse(JSON.stringify(t)),r=0;r<e.length;r++)for(var o=r+1;o<e.length;o++)e[r][n]==e[o][n]&&(e.splice(o,1),o--);return e}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 s(t,n){if(n){var e=t;return e.sort((function(t,e){var r=t[n],o=e[n],i=0;return r>o?i=1:r<o&&(i=-1),i})),e}return t.sort((function(t,n){return t-n}))}function d(t,n){if(n){var e=t;return e.sort((function(t,e){var r=t[n],o=e[n],i=0;return r>o?i=1:r<o&&(i=-1),-1*i})),e}return t.sort((function(t,n){return n-t}))}function y(t){return y="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},y(t)}function m(t){if(Array.isArray(t)){for(var n=[],e=0;e<t.length;e++)n[e]=m(t[e]);return n}if("object"===y(t)&&null!==t){var r={};for(var o in t)r[o]=m(t[o]);return r}return t}function g(t){return""===t||null==t||"object"===y(t)&&(Array.isArray(t)?0===t.length:0===Object.keys(t).length)}function v(t,n){var e=[];return t.forEach((function(t){var r=e.map((function(t){return t.group})),o=n.map((function(n){return t[n]}));if(o.includes(void 0))throw Error("传入的keys有误");r.includes(o.join(","))?e.forEach((function(n){n.group==t.age&&n.data.push(t)})):e.push({group:o.join(","),data:[t]})})),e}function b(t,n){var e=new RegExp("<"+n+"[\\s\\S]*<\\/"+n+">");console.log(e);var r=e.exec(t);return null!=r&&r.length?r[0]:null}function h(t,n){var e=null;return function(){var r=this;clearTimeout(e),e=setTimeout((function(){t.apply(r,arguments)}),n)}}function w(t,n){var e,r=new Date;return function(){var o=this,i=new Date;clearTimeout(e),i-r>=n?(t.apply(o,arguments),r=i):e=setTimeout((function(){t.apply(o,arguments)}),n)}}function S(t){return new Promise((function(n,e){var r=new FileReader;r.readAsDataURL(t),r.onload=function(t){var e;n(null===(e=t.target)||void 0===e?void 0:e.result)}}))}function x(t){for(var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",e=t.split(","),r=e[0].match(/:(.*?);/)[1],o=atob(e[1]),i=o.length,a=new Uint8Array(i);i--;)a[i]=o.charCodeAt(i);return new Blob([a],{type:n||r})}function D(t,n,e){return new File([t],n,{type:e})}function M(t,n){for(var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=t.split(","),o=r[0].match(/:(.*?);/)[1],i=atob(r[1]),a=i.length,c=new Uint8Array(a);a--;)c[a]=i.charCodeAt(a);return new File([c],n,{type:e||o})}function j(t){var n=t.split(".").pop(),e=[{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==n}));return(null==e?void 0:e.type)||null}t.r(l),t.d(l,{getDate:function(){return $},getMonday:function(){return N},getWeek:function(){return L}});var O=function(t){if(!window)throw new Error("非web环境禁止使用localStorage");if(!t)throw new Error("key的值不能为空");var n=localStorage.getItem(t);return n?JSON.parse(n):null},k=function(t,n){if(!window)throw new Error("非web环境禁止使用localStorage");if(!t||!n)throw new Error("key or value的值不能为空");var e=JSON.stringify(n);localStorage.setItem(t,e)};function P(){for(var t="#",n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],e=0;e<6;e++){t+=n[Math.floor(16*Math.random())]}return t}var T=function(t){for(var n="",e=0;e<t;e++)n+=String(Math.floor(10*Math.random()));return n};function E(t){return/^-?[1-9]\d*|0$/.test(t)}function Y(t){return/^[1-9]\d*$/.test(t)}function A(t){return/^-[1-9]\d*$/.test(t)}function C(t){return/^(86)?1[3-9]\d{9}$/.test(t)}function I(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 F(t){return/^[\w.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(t)}function R(t){return/^[0-9]+(.[0-9]{1,2})?$/.test(t)}function H(t){return/[1-9]\d{5}(?!\d)/.test(t)}function L(t){var n="";switch(new Date(t).getDay()){case 0:n="周日";break;case 1:n="周一";break;case 2:n="周二";break;case 3:n="周三";break;case 4:n="周四";break;case 5:n="周五";break;case 6:n="周六"}return n}function N(t,n){if(!t)throw new Error("getMonday的type参数必传");var e=new Date,r=e.getTime(),o=e.getDay(),i=864e5,a=6048e5*(n||0),c=0;"s"==t&&(c=r-(o-1)*i+a),"e"==t&&(c=r+(7-o)*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 $(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=new Date(t).getTime()+864e5*e,o=new Date(r),i=o.getFullYear(),a=o.getMonth()+1<10?"0"+(o.getMonth()+1):o.getMonth()+1,c=o.getDate()<10?"0"+o.getDate():o.getDate(),u=o.getHours()<10?"0"+o.getHours():o.getHours(),p=o.getMinutes()<10?"0"+o.getMinutes():o.getMinutes(),l=o.getSeconds()<10?"0"+o.getSeconds():o.getSeconds(),f="";switch(n){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 J(t){return J="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},J(t)}function B(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),e.push.apply(e,r)}return e}function z(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{};n%2?B(Object(e),!0).forEach((function(n){_(t,n,e[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):B(Object(e)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}))}return t}function _(t,n,e){return(n=function(t){var n=function(t,n){if("object"!==J(t)||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,n||"default");if("object"!==J(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"===J(n)?n:String(n)}(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var U=f,q=s,W=d,Z=m,X=g,G=v,K=b,Q=h,V=w,tt=j,nt=S,et=x,rt=D,ot=M,it=O,at=k,ct=P,ut=T,pt=E,lt=Y,ft=A,st=C,dt=I,yt=F,mt=R,gt=H,vt=$,bt=N,ht=L,wt=z(z(z(z(z(z(z(z(z({},e),r),o),i),a),c),u),p),l);return n}()}));
|
|
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.
|
|
3
|
+
"version": "1.0.5",
|
|
4
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
|
}
|