super-toolkit 1.0.0 → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 15779735060
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # super-toolkit
2
+
3
+ #### 介绍
4
+ 一个轻量级的javaScript超级工具库,代码仓库地址:[https://gitee.com/yanxiufei/super-toolkit](https://gitee.com/yanxiufei/super-toolkit)
5
+
6
+ #### 浏览器支持
7
+ |Chrome|Firefox|Safari|Opera|Edge|IE|
8
+ |------|-------|------|-----|----|--|
9
+ |Latest ✔|Latest ✔|Latest ✔|Latest ✔|Latest ✔|8 ✔|
10
+
11
+ #### 安装教程
12
+
13
+ ```js
14
+ // npm引入
15
+ npm i super-toolkit -S
16
+ // 标签引入
17
+ <script src="lib/super-toolkit.min.js"></script>
18
+ ```
19
+
20
+ #### 开始使用
21
+
22
+ 1. 默认导入:import superToolkit from 'super-toolkit'
23
+ 2. 按需导入:import {xxxx} from 'super-toolkit'
24
+
25
+ #### 使用说明
26
+
27
+ ##### unique
28
+ ```js
29
+ /**
30
+ * @desc:数组去重
31
+ * @param:{Array} arr
32
+ * @param:{?String} key
33
+ * @return:{Array}
34
+ */
35
+ ```
36
+ ##### minSort or maxSort
37
+ ```js
38
+ /**
39
+ * @desc:数组升序 or 降序排序(传入对象数组需要传key)
40
+ * @param:{Array<Record<string, any>> | Array<string|number>} arr
41
+ * @param:{String} key
42
+ * @return:{Array}
43
+ */
44
+ ```
45
+ ##### getRandomSixNum
46
+ ```js
47
+ /**
48
+ * @desc:获取指定长度的随机数
49
+ * @param:{Number} size
50
+ * @return:{String}
51
+ */
52
+ ```
53
+ ##### deepClone
54
+ ```js
55
+ /**
56
+ * @desc:深克隆
57
+ * @param:{Any} value
58
+ * @return:{Any} newValue
59
+ */
60
+ ```
61
+ ##### getElementContent
62
+ ```js
63
+ /**
64
+ * @desc:获取指定节点内容
65
+ * @param:{String} msg
66
+ * @param:{String} el
67
+ * @return:{String} content
68
+ */
69
+ ```
70
+ ##### debounce or throttle
71
+ ```js
72
+ /**
73
+ * @desc:防抖 or 节流函数
74
+ * @param:{Function} fn
75
+ * @param:{Number} wait
76
+ */
77
+ ```
78
+ ##### getApplication
79
+ ```js
80
+ /**
81
+ * @desc:根据url获取指定的application类型
82
+ * @param:{String} url
83
+ * @return:{String | Null}
84
+ */
85
+ ```
86
+ ##### fileToBase64
87
+ ```js
88
+ /**
89
+ * @desc:file转base64
90
+ * @param:{File | Blob} file
91
+ * @return:{Promise<String>}
92
+ */
93
+ ```
94
+ ##### base64ToBlob
95
+ ```js
96
+ /**
97
+ * @desc:base64转blob
98
+ * @param:{String} base64
99
+ * @param:{String} application
100
+ * @return:{Blob}
101
+ */
102
+ ```
103
+ ##### blobToFile
104
+ ```js
105
+ /**
106
+ * @desc:blob转file
107
+ * @param:{Blob} blob
108
+ * @param:{String} fileName
109
+ * @param:{String} application
110
+ * @return:{File}
111
+ */
112
+ ```
113
+ ##### base64ToFile
114
+ ```js
115
+ /**
116
+ * @desc:base64转File
117
+ * @param:{String} base64
118
+ * @param:{String} fileName
119
+ * @param:{String} application
120
+ * @return:{File}
121
+ */
122
+ ```
123
+ ##### getLocalStorage
124
+ ```js
125
+ /**
126
+ * @desc:获取浏览器localStorage的数据
127
+ * @param:{String} key
128
+ * @return:{Any | Null}
129
+ */
130
+ ```
131
+ ##### setLocalStorage
132
+ ```js
133
+ /**
134
+ * @desc:设置浏览器localStorage的数据
135
+ * @param:{String} key
136
+ * @param:{Any} value
137
+ * @return:{void}
138
+ */
139
+ ```
140
+ ##### validate
141
+ ```js
142
+ /**
143
+ * @desc:验证正负整数、身份证、手机号、邮箱地址、金额、邮编等
144
+ * @param:{String} value
145
+ * @return:{Boolean}
146
+ */
147
+ ```
148
+
149
+ ##### getDate
150
+ ```js
151
+ /**
152
+ * @desc:获取指定格式的时间
153
+ * @param:{Date | String} date
154
+ * @param:{'YYYY/MM/DD HH:MM:SS' | 'YYYY-MM-DD HH:MM:SS' | 'YYYY/MM/DD' | 'YYYY-MM-DD' | 'MM/DD' | 'MM-DD' | 'MM' | 'DD'} format
155
+ * @param:{Number} day
156
+ * @return:{String}
157
+ */
158
+ ```
159
+ ##### getMonday
160
+ ```js
161
+ /**
162
+ * @desc:获取单月月指定周数的开始时间与结束时间
163
+ * @param:{"s" | "e"} type
164
+ * @param:{Number} start
165
+ * @return:{String}
166
+ */
167
+ ```
168
+ ##### getWeek
169
+ ```js
170
+ /**
171
+ * @desc:获取时间对应的星期几
172
+ * @param:{Date | String} date
173
+ * @return:{String}
174
+ */
175
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,125 @@
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'
3
+ interface SuperToolkit{
4
+ /** 数组去重 */
5
+ unique:<T>(oldArr: Record<string, any>[], key?: string) => T,
6
+ /** 数组升序排序 */
7
+ minSort:<T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T,
8
+ /** 数组降序排序 */
9
+ maxSort:<T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T,
10
+
11
+ /** 获取指定长度的随机数 */
12
+ getRandomSixNum:(size: number) => string,
13
+ /** 深克隆 */
14
+ deepClone:<T>(val: T) => T,
15
+
16
+ /** 获取指定节点内容 */
17
+ getElementContent:(msg: string, el: string) => string | null,
18
+
19
+ /** 防抖 */
20
+ debounce:(fn: Function, wait: number) => never,
21
+ /** 节流 */
22
+ throttle:(fn: Function, wait: number) => (this: Window) => never,
23
+
24
+ /** 根据url获取指定的application类型 */
25
+ getApplication:(url: string) => string | null,
26
+ /** file转base64 */
27
+ fileToBase64: (file: File | Blob) => Promise<string>,
28
+ /** base64转blob */
29
+ base64ToBlob:(dataURL: string, mimeType?: string) => Blob,
30
+ /** blob转File */
31
+ blobToFile: (blob: Blob, fileName: string, mimeType: string) => File,
32
+ /** base64转file */
33
+ base64ToFile:(dataURL: string, fileName: string, mimeType?: string) => File,
34
+
35
+ /** 获取浏览器localStorage的数据 */
36
+ getLocalStorage:<T>(key: string) => T | null,
37
+ /** 设置浏览器localStorage的数据 */
38
+ setLocalStorage:<T = any>(key: string, value: T) => never,
39
+
40
+ /** 验证整数 */
41
+ validateInt:(value: string) => boolean,
42
+ /** 验证正整数 */
43
+ validateRightInt:(value: string) => boolean,
44
+ /** 验证负整数 */
45
+ alidateLeftInt:(value: string) => boolean,
46
+ /** 验证手机号 */
47
+ validatePhone:(value: string) => boolean,
48
+ /** 验证整数 */
49
+ validateIDCard:(value: string) => boolean,
50
+ /** 验证邮箱地址 */
51
+ validateEmail:(value: string) => boolean,
52
+ /** 验证金额 */
53
+ validateAmount:(value: string) => boolean,
54
+ /** 验证邮政编码 */
55
+ validatePostCode:(value: string) => boolean,
56
+
57
+ /** 获取指定格式的时间 */
58
+ getDate:(date: string | Date, format: Format, day?: number) => string,
59
+ /** 获取当月指定周数的开始时间与结束时间 */
60
+ getMonday:(type: "s" | "e", start?: number | undefined) => string,
61
+ /** 获取时间对应的星期几 */
62
+ getWeek:(date: string | Date) => string
63
+ }
64
+ declare const superToolkit:SuperToolkit
65
+ declare module "superToolkit" {
66
+ /** 数组去重 */
67
+ export const unique:<T>(oldArr: Record<string, any>[], key?: string) => T
68
+ /** 数组升序排序 */
69
+ export const minSort:<T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T
70
+ /** 数组降序排序 */
71
+ export const maxSort:<T extends Record<string, any>[] | (string | number)[]>(arr: T, key: string) => T
72
+
73
+ /** 获取指定长度的随机数 */
74
+ export const getRandomSixNum:(size: number) => string
75
+ /** 深克隆 */
76
+ export const deepClone:<T>(val: T) => T
77
+
78
+ /** 获取指定节点内容 */
79
+ export const getElementContent:(msg: string, el: string) => string | null
80
+
81
+ /** 防抖 */
82
+ export const debounce:(fn: Function, wait: number) => (this: Window) => void
83
+ /** 节流 */
84
+ export const throttle:(fn: Function, wait: number) => (this: Window) => void
85
+
86
+ /** 根据url获取指定的application类型 */
87
+ export const getApplication:(url: string) => string | null
88
+ /** file转base64 */
89
+ export const fileToBase64: (file: File | Blob) => Promise<string>
90
+ /** base64转blob */
91
+ export const base64ToBlob:(dataURL: string, mimeType?: string) => Blob
92
+ /** blob转File */
93
+ export const blobToFile: (blob: Blob, fileName: string, mimeType: string) => File
94
+ /** base64转file */
95
+ export const base64ToFile:(dataURL: string, fileName: string, mimeType?: string) => File
96
+
97
+ /** 获取浏览器localStorage的数据 */
98
+ export const getLocalStorage:<T>(key: string) => T | null
99
+ /** 设置浏览器localStorage的数据 */
100
+ export const setLocalStorage:<T = any>(key: string, value: T) => void
101
+
102
+ /** 验证整数 */
103
+ export const validateInt:(value: string) => boolean
104
+ /** 验证正整数 */
105
+ export const validateRightInt:(value: string) => boolean
106
+ /** 验证负整数 */
107
+ export const validateLeftInt:(value: string) => boolean
108
+ /** 验证手机号 */
109
+ export const validatePhone:(value: string) => boolean
110
+ /** 验证整数 */
111
+ export const validateIDCard:(value: string) => boolean
112
+ /** 验证邮箱地址 */
113
+ export const validateEmail:(value: string) => boolean
114
+ /** 验证金额 */
115
+ export const validateAmount:(value: string) => boolean
116
+ /** 验证邮政编码 */
117
+ export const validatePostCode:(value: string) => boolean
118
+
119
+ /** 获取指定格式的时间 */
120
+ export const getDate:(date: string | Date, format: Format, day?: number) => string
121
+ /** 获取当月指定周数的开始时间与结束时间 */
122
+ export const getMonday:(type: "s" | "e", start?: number | undefined) => string
123
+ /** 获取时间对应的星期几 */
124
+ export const getWeek:(date: string | Date) => string
125
+ }
package/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ import * as array from './src/array'
2
+ import * as data from './src/data'
3
+ import * as elelemt from './src/element'
4
+ import * as event from './src/event'
5
+ import * as file from './src/file'
6
+ import * as localStorage from './src/localStorage'
7
+ import * as reg from './src/reg'
8
+ import * as time from './src/time'
9
+
10
+
11
+ const {unique,minSort,maxSort}=array
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 = {
20
+ ...array,
21
+ ...data,
22
+ ...elelemt,
23
+ ...event,
24
+ ...file,
25
+ ...localStorage,
26
+ ...time,
27
+ ...reg
28
+ }
29
+ export {
30
+ superToolkit as default,
31
+
32
+ unique,
33
+ minSort,
34
+ maxSort,
35
+
36
+ getRandomSixNum,
37
+ deepClone,
38
+
39
+ getElementContent,
40
+
41
+ debounce,
42
+ throttle,
43
+
44
+ getApplication,
45
+ fileToBase64,
46
+ base64ToBlob,
47
+ blobToFile,
48
+ base64ToFile,
49
+
50
+ getLocalStorage,
51
+ setLocalStorage,
52
+
53
+ validateInt,
54
+ validateRightInt,
55
+ validateLeftInt,
56
+ validatePhone,
57
+ validateIDCard,
58
+ validateEmail,
59
+ validateAmount,
60
+ validatePostCode,
61
+
62
+ getDate,
63
+ getMonday,
64
+ getWeek
65
+ }
@@ -0,0 +1 @@
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}()}));
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
- {
2
- "name": "super-toolkit",
3
- "version": "1.0.0",
4
- "description": "一个轻量级的js工具库",
5
- "main": "lib/index.js",
6
- "scripts": {
7
- "build": "webpack --config webpack.config.js"
8
- },
9
- "types": "src/index.d.ts",
10
- "keywords": [],
11
- "author": "yanxiufei",
12
- "license": "ISC",
13
- "devDependencies": {
14
- "@babel/core": "^7.22.11",
15
- "@babel/preset-env": "^7.22.10",
16
- "@babel/preset-typescript": "^7.22.11",
17
- "babel-loader": "^9.1.3",
18
- "clean-webpack-plugin": "^4.0.0",
19
- "typescript": "^5.2.2",
20
- "webpack": "^5.88.2",
21
- "webpack-cli": "^5.1.4"
22
- },
23
- "browserslist": [
24
- "defaults",
25
- "not ie < 8",
26
- "last 3 versions",
27
- "> 0.2%",
28
- "iOS 7",
29
- "last 3 iOS versions"
30
- ]
31
- }
1
+ {
2
+ "name": "super-toolkit",
3
+ "version": "1.0.1",
4
+ "description": "一个轻量级的javascript工具库",
5
+ "main": "lib/super-toolkit.min.js",
6
+ "scripts": {
7
+ "build": "webpack --config webpack.config.js"
8
+ },
9
+ "types": "index.d.ts",
10
+ "keywords": [],
11
+ "author": "yanxiufei",
12
+ "license": "ISC",
13
+ "devDependencies": {
14
+ "@babel/core": "^7.22.11",
15
+ "@babel/preset-env": "^7.22.10",
16
+ "@babel/preset-typescript": "^7.22.11",
17
+ "babel-loader": "^9.1.3",
18
+ "clean-webpack-plugin": "^4.0.0",
19
+ "terser-webpack-plugin": "^5.3.9",
20
+ "typescript": "^5.2.2",
21
+ "webpack": "^5.88.2",
22
+ "webpack-cli": "^5.1.4"
23
+ },
24
+ "browserslist": [
25
+ "defaults",
26
+ "not ie < 8",
27
+ "last 3 versions",
28
+ "> 0.2%",
29
+ "iOS 7",
30
+ "last 3 iOS versions"
31
+ ]
32
+ }
package/src/array.ts ADDED
@@ -0,0 +1,74 @@
1
+ /** 数组去重 */
2
+ export function unique<T>(oldArr: Record<string, any>[], key?: string):T {
3
+ if (key) {
4
+ let arr = JSON.parse(JSON.stringify(oldArr));
5
+ for (let i = 0; i < arr.length; i++) {
6
+ for (let j = i + 1; j < arr.length; j++) {
7
+ if (arr[i][key] == arr[j][key]) {
8
+ arr.splice(j, 1);
9
+ j--;
10
+ };
11
+ };
12
+ };
13
+ return arr;
14
+ } else {
15
+ let arr = JSON.parse(JSON.stringify(oldArr));
16
+ for (let i = 0; i < arr.length; i++) {
17
+ for (let j = i + 1; j < arr.length; j++) {
18
+ if (arr[i] == arr[j]) {
19
+ arr.splice(j, 1);
20
+ j--;
21
+ };
22
+ };
23
+ };
24
+ return arr;
25
+ }
26
+ }
27
+ /** 数组排序,从小到大 */
28
+ export function minSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key: string) :T {
29
+ if (key) {
30
+ let list = arr as Record<string, any>[];
31
+ function compare(a: Record<string, any>, b: Record<string, any>) {
32
+ // 使用 toUpperCase() 忽略字符大小写
33
+ const bandA = a[key]
34
+ const bandB = b[key]
35
+ let comparison = 0;
36
+ if (bandA > bandB) {
37
+ comparison = 1;
38
+ } else if (bandA < bandB) {
39
+ comparison = -1;
40
+ }
41
+ return comparison;
42
+ }
43
+ list.sort(compare);
44
+ return list as T
45
+ } else {
46
+ let list = arr as Array<number>;
47
+ return list.sort((a, b) => a - b) as T
48
+ }
49
+ }
50
+
51
+ /** 数组排序,从大到小 */
52
+ export function maxSort<T extends Record<string, any>[] | Array<number | string>>(arr: T, key: string):T {
53
+ if (key) {
54
+ let list = arr as Record<string, any>[];
55
+ function compare2(a: Record<string, any>, b: Record<string, any>) {
56
+ // 使用 toUpperCase() 忽略字符大小写
57
+ const bandA = a[key]
58
+ const bandB = b[key]
59
+
60
+ let comparison = 0;
61
+ if (bandA > bandB) {
62
+ comparison = 1;
63
+ } else if (bandA < bandB) {
64
+ comparison = -1;
65
+ }
66
+ return comparison * -1;
67
+ }
68
+ list.sort(compare2);
69
+ return list as T
70
+ } else {
71
+ let list = arr as Array<number>;
72
+ return list.sort((a, b) => b - a) as T
73
+ }
74
+ }
package/src/data.ts ADDED
@@ -0,0 +1,25 @@
1
+ export const getRandomSixNum = (size: number) => {
2
+ let RandomSixStr = ''
3
+ for (let i = 0; i < size; i++) {
4
+ RandomSixStr += String(Math.floor(Math.random() * 10))
5
+ }
6
+ return RandomSixStr
7
+ }
8
+ /** 深拷贝 */
9
+ export function deepClone<T>(val: T):T {
10
+ if (Array.isArray(val)) {
11
+ let arr = [];
12
+ for (let i = 0; i < val.length; i++) {
13
+ arr[i] = deepClone(val[i])
14
+ }
15
+ return arr as T
16
+ }
17
+ if (typeof val === 'object' && val !== null) {
18
+ let obj: Record<string, unknown> = {};
19
+ for (let key in val) {
20
+ obj[key] = deepClone<unknown>(val[key])
21
+ }
22
+ return obj as T
23
+ }
24
+ return val
25
+ }
package/src/element.ts ADDED
@@ -0,0 +1,7 @@
1
+ /** 获取指定元素中的所有内容 */
2
+ export function getElementContent(msg: string, el: string) {
3
+ let elReg = new RegExp("<" + el + "[\\s\\S]*<\\/" + el + ">");
4
+ console.log(elReg);
5
+ let newEl = elReg.exec(msg);
6
+ return newEl?.length ? newEl[0] : null
7
+ }
package/src/event.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**防抖方法,其中形参fn为要执行的方法,wait则代表时间间隔,v2使用方法:methods:debounce(()=>{},500),v3使用方法:const methods=debounce(()=>{},500)*/
2
+ export function debounce(fn: Function, wait: number) {
3
+ var timer: any = null;
4
+ return function (this: Window) {
5
+ var _that = this;
6
+ clearTimeout(timer as undefined)
7
+ timer = timer as typeof setTimeout;
8
+ timer = setTimeout(function () {
9
+ fn.apply(_that, arguments) //更改this指向,使this指向它的调用层
10
+ }, wait)
11
+ }
12
+ }
13
+
14
+ /**节流方法,其中形参fn为要执行的方法,wait则代表时间间隔,v2使用方法:methods:throttle(()=>{},500),v3使用方法:const methods=throttle(()=>{},500)*/
15
+ export function throttle(fn: Function, wait: number) {
16
+ var timeout: any, startTime = new Date() as any;
17
+ return function (this: Window) {
18
+ var _that = this;
19
+ var curTime = new Date() as any;
20
+ clearTimeout(timeout);
21
+ // 如果达到了规定的触发时间间隔,触发 handler
22
+ if (curTime - startTime >= wait) {
23
+ fn.apply(_that, arguments);//更改this指向,使this指向它的调用层
24
+ startTime = curTime;
25
+ // 没达到触发间隔,重新设定定时器
26
+ } else {
27
+ timeout = setTimeout(function () {
28
+ fn.apply(_that, arguments);//更改this指向,使this指向它的调用层
29
+ }, wait);
30
+ }
31
+ };
32
+ }
package/src/file.ts ADDED
@@ -0,0 +1,108 @@
1
+
2
+ /* file转base64 */
3
+ export function fileToBase64(file: File | Blob): Promise<string> {
4
+ return new Promise<string>((resolve, reject) => {
5
+ const reader = new FileReader();
6
+ reader.readAsDataURL(file); //发起异步请求
7
+ reader.onload = function (readRes) {
8
+ resolve(readRes.target?.result as string)
9
+ };
10
+ })
11
+ }
12
+
13
+ /* base64转blob */
14
+ export function base64ToBlob(dataURL: string, mimeType = "") {
15
+ let arr: any = dataURL.split(','),
16
+ defaultMimeType = arr[0].match(/:(.*?);/)[1],
17
+ bStr = atob(arr[1]),
18
+ n = bStr.length,
19
+ u8arr = new Uint8Array(n)
20
+ while (n--) {
21
+ u8arr[n] = bStr.charCodeAt(n)
22
+ }
23
+ return new Blob([u8arr], { type: mimeType || defaultMimeType })
24
+ }
25
+
26
+ /* blob转file */
27
+ export function blobToFile(blob: Blob, fileName: string, mimeType: string) {
28
+ return new File([blob], fileName, { type: mimeType })
29
+ }
30
+
31
+ /* base64转file */
32
+ export function base64ToFile(dataURL: string, fileName: string, mimeType = "") {
33
+ let arr: any = dataURL.split(','),
34
+ defaultMimeType = arr[0].match(/:(.*?);/)[1],
35
+ bStr = atob(arr[1]),
36
+ n = bStr.length,
37
+ u8arr = new Uint8Array(n)
38
+ while (n--) {
39
+ u8arr[n] = bStr.charCodeAt(n)
40
+ }
41
+ return new File([u8arr], fileName, { type: mimeType || defaultMimeType })
42
+ }
43
+
44
+ /** 获取指定url文件的application */
45
+ export function getApplication(url: string) {
46
+ let applications = [
47
+ { type: "doc", application: "application/msword" },
48
+ {
49
+ type: "docx",
50
+ application:
51
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
52
+ },
53
+ { type: "dot", application: "application/msword" },
54
+ {
55
+ type: "dotx",
56
+ application:
57
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template"
58
+ },
59
+ { type: "xls", application: "application/vnd.ms-excel" },
60
+ {
61
+ type: "xlsx",
62
+ application:
63
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
64
+ },
65
+ { type: "ppt", application: "application/vnd.ms-powerpoint" },
66
+ {
67
+ type: "pptx",
68
+ application:
69
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation"
70
+ },
71
+ { type: "pdf", application: "application/pdf" },
72
+ { type: "txt", application: "text/plain" },
73
+ { type: "gif", application: "image/gif" },
74
+ { type: "jpeg", application: "image/jpeg" },
75
+ { type: "jpg", application: "image/jpeg" },
76
+ { type: "png", application: "image/png" },
77
+ { type: "css", application: "text/css" },
78
+ { type: "html", application: "text/html" },
79
+ { type: "htm", application: "text/html" },
80
+ { type: "xsl", application: "text/xml" },
81
+ { type: "xml", application: "text/xml" },
82
+ { type: "mpeg", application: "video/mpeg" },
83
+ { type: "mpg", application: "video/mpeg" },
84
+ { type: "avi", application: "video/x-msvideo" },
85
+ { type: "movie", application: "video/x-sgi-movie" },
86
+ { type: "bin", application: "application/octet-stream" },
87
+ { type: "exe", application: "application/octet-stream" },
88
+ { type: "so", application: "application/octet-stream" },
89
+ { type: "dll", application: "application/octet-stream" },
90
+ { type: "ai", application: "application/postscript" },
91
+ { type: "dir", application: "application/x-director" },
92
+ { type: "js", application: "application/x-javascript" },
93
+ { type: "swf", application: "application/x-shockwave-flash" },
94
+ { type: "xhtml", application: "application/xhtml+xml" },
95
+ { type: "xht", application: "application/xhtml+xml" },
96
+ { type: "zip", application: "application/zip" },
97
+ { type: "mid", application: "audio/midi" },
98
+ { type: "midi", application: "audio/midi" },
99
+ { type: "mp3", application: "audio/mpeg" },
100
+ { type: "rm", application: "audio/x-pn-realaudio" },
101
+ { type: "rpm", application: "audio/x-pn-realaudio-plugin" },
102
+ { type: "wav", application: "audio/x-wav" },
103
+ { type: "bmp", application: "image/bmp" }
104
+ ];
105
+ let type = url.split('.').pop();
106
+ const row = applications.find(t => t.type == type)
107
+ return row?.type || null
108
+ }
package/src/reg.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** 验证整数 */
2
+ export function validateInt(value:string){
3
+ const reg=/^-?[1-9]\d*|0$/
4
+ return reg.test(value)
5
+ }
6
+ /** 验证正整数 */
7
+ export function validateRightInt(value:string){
8
+ const reg=/^[1-9]\d*$/
9
+ return reg.test(value)
10
+ }
11
+ /** 验证负整数 */
12
+ export function validateLeftInt(value:string){
13
+ const reg=/^-[1-9]\d*$/
14
+ return reg.test(value)
15
+ }
16
+ /** 验证手机号 */
17
+ export function validatePhone(value:string){
18
+ const reg=/^(86)?1[3-9]\d{9}$/
19
+ return reg.test(value)
20
+ }
21
+ /** 验证身份证号 */
22
+ export function validateIDCard(value:string){
23
+ const reg=/^[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)$/
24
+ return reg.test(value)
25
+ }
26
+ /** 验证邮箱地址 */
27
+ export function validateEmail(value:string){
28
+ const reg=/^[\w.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
29
+ return reg.test(value)
30
+ }
31
+ /** 验证金额(保留两位小数) */
32
+ export function validateAmount(value:string){
33
+ const reg=/^[0-9]+(.[0-9]{1,2})?$/
34
+ return reg.test(value)
35
+ }
36
+ /** 验证邮政编码 */
37
+ export function validatePostCode(value:string){
38
+ const reg=/[1-9]\d{5}(?!\d)/
39
+ return reg.test(value)
40
+ }
package/src/time.ts ADDED
@@ -0,0 +1,94 @@
1
+ /** 获取当前日期为周几 */
2
+ export function getWeek(date: string | Date): string {
3
+ let week = '';
4
+ let day = new Date(date).getDay();
5
+ switch (day) {
6
+ case 0:
7
+ week = "周日";
8
+ break;
9
+ case 1:
10
+ week = "周一";
11
+ break;
12
+ case 2:
13
+ week = "周二";
14
+ break;
15
+ case 3:
16
+ week = "周三";
17
+ break;
18
+ case 4:
19
+ week = "周四";
20
+ break;
21
+ case 5:
22
+ week = "周五";
23
+ break;
24
+ case 6:
25
+ week = "周六";
26
+ break;
27
+ }
28
+ return week;
29
+ }
30
+ /** 获取周数的开始和结束日,getMonday("s", 0)代表本周的起始日*/
31
+ export function getMonday(type: 's' | 'e', start?: number) {
32
+ if (!type) {
33
+ throw new Error('getMonday的type参数必传')
34
+ }
35
+ let now = new Date();
36
+ let nowTime = now.getTime();
37
+ let day = now.getDay();
38
+ let longTime = 24 * 60 * 60 * 1000;
39
+ let n = longTime * 7 * (start || 0);
40
+ let stamp: number = 0;
41
+ if (type == "s") {
42
+ stamp = nowTime - (day - 1) * longTime + n;
43
+ };
44
+ if (type == "e") {
45
+ stamp = nowTime + (7 - day) * longTime + n;
46
+ };
47
+ let date = new Date(stamp);
48
+ let y = date.getFullYear();
49
+ let m = date.getMonth() + 1;
50
+ let d = date.getDate();
51
+ m = (m < 10 ? "0" + m : m) as number;
52
+ d = (d < 10 ? "0" + d : d) as number;
53
+ let str = y + "-" + m + "-" + d;
54
+ return str;
55
+ }
56
+
57
+ 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'
58
+ /** 获取指定的日期*/
59
+ export function getDate(date: Date | string, format: Format, day = 0) {
60
+ let currentDate = new Date(date).getTime() + (1000 * 36 * 2400 * day);
61
+ const time = new Date(currentDate);
62
+ let y = time.getFullYear();
63
+ let m = time.getMonth() + 1 < 10 ? "0" + (time.getMonth() + 1) : time.getMonth() + 1;
64
+ let d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
65
+ let h = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
66
+ let mm = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
67
+ let s = time.getSeconds() < 10 ? "0" + time.getSeconds() : time.getSeconds();
68
+ let content = '';
69
+ switch (format) {
70
+ case 'YYYY/MM/DD HH:MM:SS':
71
+ content = `${y}/${m}/${d} ${h}:${mm}:${s}`;
72
+ break
73
+ case 'YYYY-MM-DD HH:MM:SS':
74
+ content = `${y}-${m}-${d} ${h}:${mm}:${s}`;
75
+ break
76
+ case 'YYYY/MM/DD':
77
+ content = `${y}/${m}/${d}`;
78
+ break
79
+ case 'YYYY-MM-DD':
80
+ content = `${y}-${m}-${d}`;
81
+ break
82
+ case 'MM/DD':
83
+ content = `${m}/${d}`;
84
+ break
85
+ case 'MM-DD':
86
+ content = `${m}-${d}`;
87
+ break
88
+ case 'MM':
89
+ content = `${mm}`;
90
+ case 'DD':
91
+ content = `${d}`;
92
+ }
93
+ return content;
94
+ }
package/test.html ADDED
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <title>Document</title>
9
+ </head>
10
+
11
+ <body>
12
+ <script src="./lib/super-toolkit.min.js"></script>
13
+ <script>
14
+ const reg=/^[0-9]+(.[0-9]{1,2})?$/
15
+ const str='1asdf'
16
+ console.log(window['super-toolkit'].validatePostCode);
17
+ </script>
18
+ </body>
19
+
20
+ </html>
package/tsconfig.json CHANGED
@@ -97,5 +97,6 @@
97
97
  /* Completeness */
98
98
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
99
  "skipLibCheck": true, /* Skip type checking all .d.ts files. */
100
+ "declaration": true
100
101
  }
101
102
  }
package/webpack.config.js CHANGED
@@ -1,11 +1,13 @@
1
1
  const path = require('path');
2
+ const pkg = require('./package.json')
2
3
  const { CleanWebpackPlugin } = require("clean-webpack-plugin");
4
+ const TerserPlugin = require('terser-webpack-plugin')
3
5
  module.exports = {
4
- entry: './src/index.ts',
6
+ entry: './index.ts',
5
7
  output: {
6
8
  path: path.resolve(__dirname, 'lib'),
7
- filename: 'index.js',
8
- library: 'superToolkit',
9
+ filename: `${pkg.name}.min.js`,
10
+ library: `${pkg.name}`,
9
11
  libraryTarget: 'umd',
10
12
  globalObject: 'this'
11
13
  },
@@ -28,5 +30,11 @@ module.exports = {
28
30
  alias: {
29
31
  "@": path.resolve("src")
30
32
  },
33
+ },
34
+ optimization: {
35
+ minimize: true,
36
+ minimizer: [
37
+ new TerserPlugin(),
38
+ ]
31
39
  }
32
40
  };
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.yanxiufei_tools=e():t.yanxiufei_tools=e()}(this,(function(){return function(){"use strict";var t={d:function(e,o){for(var i in o)t.o(o,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:o[i]})},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,{default:function(){return w},getApplication:function(){return x},getDate:function(){return d},getLocalStorage:function(){return m},getMonday:function(){return v},getWeek:function(){return b},setLocalStorage:function(){return g}});var o={};t.r(o),t.d(o,{getLocalStorage:function(){return a},setLocalStorage:function(){return p}});var i={};t.r(i),t.d(i,{getDate:function(){return r},getMonday:function(){return l},getWeek:function(){return c}});var n={};t.r(n),t.d(n,{getApplication:function(){return u}});var a=function(t){if(!t)throw new Error("key的值不能为空");var e=localStorage.getItem(t);return e?JSON.parse(e):null},p=function(t,e){if(!t||!e)throw new Error("key or value的值不能为空");var o=JSON.stringify(e);localStorage.setItem(t,o)};function r(t,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!t)throw new Error("getDate的date参数必传");var i=new Date(t).getTime()+864e5*o,n=new Date(i),a=n.getFullYear(),p=n.getMonth()+1<10?"0"+(n.getMonth()+1):n.getMonth()+1,r=n.getDate()<10?"0"+n.getDate():n.getDate(),c=n.getHours()<10?"0"+n.getHours():n.getHours(),l=n.getMinutes()<10?"0"+n.getMinutes():n.getMinutes(),u=n.getSeconds()<10?"0"+n.getSeconds():n.getSeconds();return"".concat(a,"-").concat(p,"-").concat(r," ").concat(c,":").concat(l,":").concat(u)}function c(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 l(t,e){if(!t)throw new Error("getMonday的type参数必传");var o=new Date,i=o.getTime(),n=o.getDay(),a=864e5,p=6048e5*(e||0),r=0;"s"==t&&(r=i-(n-1)*a+p),"e"==t&&(r=i+(7-n)*a+p);var c=new Date(r),l=c.getFullYear(),u=c.getMonth()+1,f=c.getDate();return l+"-"+(u=u<10?"0"+u:u)+"-"+(f<10?"0"+f:f)}function u(t){var e=t.split(".").pop(),o=[{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==o?void 0:o.type)||null}function f(t){return f="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},f(t)}function y(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,i)}return o}function s(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?y(Object(o),!0).forEach((function(e){var i,n,a;i=t,n=e,a=o[e],(n=function(t){var e=function(t,e){if("object"!==f(t)||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,"string");if("object"!==f(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===f(e)?e:String(e)}(n))in i?Object.defineProperty(i,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):i[n]=a})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):y(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}var m=a,g=p,d=r,v=l,b=c,x=u,w=s(s({},o),{},{dateModules:i,fileModules:n});return e}()}));
@@ -1,16 +0,0 @@
1
- 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
- /** 获取指定的日期,返回格式YYYY-MM-DD */
3
- export function getDate(date: Date | string, format: Format, day: number = 0) {
4
- if (!date) {
5
- throw new Error('getDate的date参数必传')
6
- }
7
- let currentDate = new Date(date).getTime() + 1000 * 36 * 2400 * day;
8
- var time = new Date(currentDate);
9
- let y = time.getFullYear();
10
- let m = time.getMonth() + 1 < 10 ? "0" + (time.getMonth() + 1) : time.getMonth() + 1;
11
- let d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
12
- let h = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
13
- let mm = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
14
- let s = time.getSeconds() < 10 ? "0" + time.getSeconds() : time.getSeconds();
15
- return `${y}-${m}-${d} ${h}:${mm}:${s}`
16
- }
@@ -1,7 +0,0 @@
1
- import { getDate } from './format'
2
- import { getWeek, getMonday } from './week'
3
- export {
4
- getDate,
5
- getWeek,
6
- getMonday,
7
- }
@@ -1,55 +0,0 @@
1
- /** 获取当前日期为周几 */
2
- export function getWeek(date: string | Date): string {
3
- let week = '';
4
- let day = new Date(date).getDay();
5
- switch (day) {
6
- case 0:
7
- week = "周日";
8
- break;
9
- case 1:
10
- week = "周一";
11
- break;
12
- case 2:
13
- week = "周二";
14
- break;
15
- case 3:
16
- week = "周三";
17
- break;
18
- case 4:
19
- week = "周四";
20
- break;
21
- case 5:
22
- week = "周五";
23
- break;
24
- case 6:
25
- week = "周六";
26
- break;
27
- }
28
- return week;
29
- }
30
- /** 获取周数的开始和结束日,getMonday("s", 0)代表本周的起始日*/
31
- export function getMonday(type: 's' | 'e', start?: number) {
32
- if (!type) {
33
- throw new Error('getMonday的type参数必传')
34
- }
35
- let now = new Date();
36
- let nowTime = now.getTime();
37
- let day = now.getDay();
38
- let longTime = 24 * 60 * 60 * 1000;
39
- let n = longTime * 7 * (start || 0);
40
- let stamp: number = 0;
41
- if (type == "s") {
42
- stamp = nowTime - (day - 1) * longTime + n;
43
- };
44
- if (type == "e") {
45
- stamp = nowTime + (7 - day) * longTime + n;
46
- };
47
- let date = new Date(stamp);
48
- let y = date.getFullYear();
49
- let m = date.getMonth() + 1;
50
- let d = date.getDate();
51
- m = (m < 10 ? "0" + m : m) as number;
52
- d = (d < 10 ? "0" + d : d) as number;
53
- let str = y + "-" + m + "-" + d;
54
- return str;
55
- }
File without changes
@@ -1,65 +0,0 @@
1
- /** 获取指定url文件的application */
2
- export function getApplication(url: string) {
3
- let applications = [
4
- { type: "doc", application: "application/msword" },
5
- {
6
- type: "docx",
7
- application:
8
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
9
- },
10
- { type: "dot", application: "application/msword" },
11
- {
12
- type: "dotx",
13
- application:
14
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template"
15
- },
16
- { type: "xls", application: "application/vnd.ms-excel" },
17
- {
18
- type: "xlsx",
19
- application:
20
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
21
- },
22
- { type: "ppt", application: "application/vnd.ms-powerpoint" },
23
- {
24
- type: "pptx",
25
- application:
26
- "application/vnd.openxmlformats-officedocument.presentationml.presentation"
27
- },
28
- { type: "pdf", application: "application/pdf" },
29
- { type: "txt", application: "text/plain" },
30
- { type: "gif", application: "image/gif" },
31
- { type: "jpeg", application: "image/jpeg" },
32
- { type: "jpg", application: "image/jpeg" },
33
- { type: "png", application: "image/png" },
34
- { type: "css", application: "text/css" },
35
- { type: "html", application: "text/html" },
36
- { type: "htm", application: "text/html" },
37
- { type: "xsl", application: "text/xml" },
38
- { type: "xml", application: "text/xml" },
39
- { type: "mpeg", application: "video/mpeg" },
40
- { type: "mpg", application: "video/mpeg" },
41
- { type: "avi", application: "video/x-msvideo" },
42
- { type: "movie", application: "video/x-sgi-movie" },
43
- { type: "bin", application: "application/octet-stream" },
44
- { type: "exe", application: "application/octet-stream" },
45
- { type: "so", application: "application/octet-stream" },
46
- { type: "dll", application: "application/octet-stream" },
47
- { type: "ai", application: "application/postscript" },
48
- { type: "dir", application: "application/x-director" },
49
- { type: "js", application: "application/x-javascript" },
50
- { type: "swf", application: "application/x-shockwave-flash" },
51
- { type: "xhtml", application: "application/xhtml+xml" },
52
- { type: "xht", application: "application/xhtml+xml" },
53
- { type: "zip", application: "application/zip" },
54
- { type: "mid", application: "audio/midi" },
55
- { type: "midi", application: "audio/midi" },
56
- { type: "mp3", application: "audio/mpeg" },
57
- { type: "rm", application: "audio/x-pn-realaudio" },
58
- { type: "rpm", application: "audio/x-pn-realaudio-plugin" },
59
- { type: "wav", application: "audio/x-wav" },
60
- { type: "bmp", application: "image/bmp" }
61
- ];
62
- let type = url.split('.').pop();
63
- const row = applications.find(t => t.type == type)
64
- return row?.type || null
65
- }
@@ -1,4 +0,0 @@
1
- import { getApplication } from "./application";
2
- export {
3
- getApplication
4
- }
package/src/index.d.ts DELETED
@@ -1,35 +0,0 @@
1
-
2
- type GetLocalStorage = {
3
- <T>(key: string): T | null
4
- }
5
- type SetLocalStorage = {
6
- <T = any>(key: string, value: T): void
7
- }
8
- type GetDate = {
9
- (date: string | Date, day: number | undefined, format: Format): string
10
- }
11
- type GetMonday = {
12
- (type: 's' | 'e', start?: number): string
13
- }
14
- type GetWeek = {
15
- (date: string | Date): string
16
- }
17
- type GetApplication = {
18
- (url: string): string | null
19
- }
20
- declare module "superToolkit" {
21
- const getLocalStorage: GetLocalStorage
22
- const setLocalStorage: SetLocalStorage
23
- const getDate: GetDate
24
- const getMonday: GetMonday
25
- const getWeek: GetWeek
26
- const getApplication: GetApplication
27
- export {
28
- getLocalStorage,
29
- setLocalStorage,
30
- getDate,
31
- getMonday,
32
- getWeek,
33
- getApplication
34
- }
35
- }
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- import * as localStorageModules from './localStorageModules/index'
2
- import * as dateModules from './dateModules/index'
3
- import * as fileModules from './fileModules/index'
4
- const { getLocalStorage, setLocalStorage } = localStorageModules
5
- const { getDate, getMonday, getWeek } = dateModules
6
- const { getApplication } = fileModules
7
- const superToolkit = { ...localStorageModules, dateModules, fileModules }
8
- export {
9
- superToolkit as default,
10
- getLocalStorage,
11
- setLocalStorage,
12
- getDate,
13
- getMonday,
14
- getWeek,
15
- getApplication
16
- }
@@ -1,18 +0,0 @@
1
- export function arrUnique(arr: { [x: string]: any }[], key?: string) {
2
- let returnArr: { [x: string]: any }[] = [];
3
- if (key) {
4
- // 对象数组去重
5
- const obj = {};
6
- returnArr = arr.reduce((cur: any, next: any) => {
7
- obj[next[key]] ? '' : obj[next[key]] = true && cur.push(next);
8
- return cur;
9
- }, []);
10
- return returnArr;
11
- }
12
- // 普通数组去重
13
- returnArr = arr.reduce((cur: any, next: any) => {
14
- !cur.includes(next) && cur.push(next);
15
- return cur;
16
- }, []);
17
- return returnArr;
18
- }