super-toolkit 1.0.2 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/reg.ts CHANGED
@@ -1,40 +1,164 @@
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
- }
1
+ /** 正则表达式常量 */
2
+ const REGEX = {
3
+ // 整数
4
+ INT: /^-?\d+$/,
5
+ // 正整数
6
+ POSITIVE_INT: /^[1-9]\d*$/,
7
+ // 负整数
8
+ NEGATIVE_INT: /^-[1-9]\d*$/,
9
+ // 手机号
10
+ PHONE: /^(86)?1[3-9]\d{9}$/,
11
+ // 固定电话
12
+ TELEPHONE: /^(\d{3}-?\d{7,8}|\d{4}-?\d{7,8})$/,
13
+ // 身份证号
14
+ 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)$/,
15
+ // 邮箱地址
16
+ EMAIL: /^[\w.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
17
+ // 金额(保留两位小数)
18
+ AMOUNT: /^[0-9]+(\.[0-9]{1,2})?$/,
19
+ // 邮政编码
20
+ POST_CODE: /^[1-9]\d{5}$/,
21
+ // URL
22
+ URL: /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/,
23
+ // 密码强度(至少8位,包含字母和数字)
24
+ PASSWORD: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,
25
+ // 日期格式 (YYYY-MM-DD)
26
+ DATE: /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,
27
+ // 时间格式 (HH:MM:SS)
28
+ TIME: /^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/,
29
+ // IPv4地址
30
+ 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]?)$/
31
+ };
32
+
33
+ /**
34
+ * 验证整数
35
+ * @param value 要验证的值
36
+ * @returns 是否为整数
37
+ */
38
+ export function validateInt(value: string | number): boolean {
39
+ const strValue = String(value);
40
+ return REGEX.INT.test(strValue);
41
+ }
42
+
43
+ /**
44
+ * 验证正整数
45
+ * @param value 要验证的值
46
+ * @returns 是否为正整数
47
+ */
48
+ export function validatePositiveInt(value: string | number): boolean {
49
+ const strValue = String(value);
50
+ return REGEX.POSITIVE_INT.test(strValue);
51
+ }
52
+
53
+ /**
54
+ * 验证负整数
55
+ * @param value 要验证的值
56
+ * @returns 是否为负整数
57
+ */
58
+ export function validateNegativeInt(value: string | number): boolean {
59
+ const strValue = String(value);
60
+ return REGEX.NEGATIVE_INT.test(strValue);
61
+ }
62
+
63
+ /**
64
+ * 验证手机号
65
+ * @param value 要验证的值
66
+ * @returns 是否为有效手机号
67
+ */
68
+ export function validatePhone(value: string): boolean {
69
+ return REGEX.PHONE.test(value);
70
+ }
71
+
72
+ /**
73
+ * 验证固定电话
74
+ * @param value 要验证的值
75
+ * @returns 是否为有效固定电话
76
+ */
77
+ export function validateTelephone(value: string): boolean {
78
+ return REGEX.TELEPHONE.test(value);
79
+ }
80
+
81
+ /**
82
+ * 验证身份证号
83
+ * @param value 要验证的值
84
+ * @returns 是否为有效身份证号
85
+ */
86
+ export function validateIDCard(value: string): boolean {
87
+ return REGEX.ID_CARD.test(value);
88
+ }
89
+
90
+ /**
91
+ * 验证邮箱地址
92
+ * @param value 要验证的值
93
+ * @returns 是否为有效邮箱地址
94
+ */
95
+ export function validateEmail(value: string): boolean {
96
+ return REGEX.EMAIL.test(value);
97
+ }
98
+
99
+ /**
100
+ * 验证金额(保留两位小数)
101
+ * @param value 要验证的值
102
+ * @returns 是否为有效金额
103
+ */
104
+ export function validateAmount(value: string | number): boolean {
105
+ const strValue = String(value);
106
+ return REGEX.AMOUNT.test(strValue);
107
+ }
108
+
109
+ /**
110
+ * 验证邮政编码
111
+ * @param value 要验证的值
112
+ * @returns 是否为有效邮政编码
113
+ */
114
+ export function validatePostCode(value: string): boolean {
115
+ return REGEX.POST_CODE.test(value);
116
+ }
117
+
118
+ /**
119
+ * 验证URL
120
+ * @param value 要验证的值
121
+ * @returns 是否为有效URL
122
+ */
123
+ export function validateUrl(value: string): boolean {
124
+ return REGEX.URL.test(value);
125
+ }
126
+
127
+ /**
128
+ * 验证密码强度(至少8位,包含字母和数字)
129
+ * @param value 要验证的值
130
+ * @returns 是否为有效密码
131
+ */
132
+ export function validatePassword(value: string): boolean {
133
+ return REGEX.PASSWORD.test(value);
134
+ }
135
+
136
+ /**
137
+ * 验证日期格式 (YYYY-MM-DD)
138
+ * @param value 要验证的值
139
+ * @returns 是否为有效日期格式
140
+ */
141
+ export function validateDate(value: string): boolean {
142
+ return REGEX.DATE.test(value);
143
+ }
144
+
145
+ /**
146
+ * 验证时间格式 (HH:MM:SS)
147
+ * @param value 要验证的值
148
+ * @returns 是否为有效时间格式
149
+ */
150
+ export function validateTime(value: string): boolean {
151
+ return REGEX.TIME.test(value);
152
+ }
153
+
154
+ /**
155
+ * 验证IPv4地址
156
+ * @param value 要验证的值
157
+ * @returns 是否为有效IPv4地址
158
+ */
159
+ export function validateIPv4(value: string): boolean {
160
+ return REGEX.IPV4.test(value);
161
+ }
162
+
163
+ // 导出正则表达式常量
164
+ export { REGEX };
package/src/time.ts CHANGED
@@ -1,94 +1,179 @@
1
- /** 获取当前日期为周几 */
1
+ /**
2
+ * 获取当前日期为周几
3
+ * @param date 日期对象或日期字符串
4
+ * @returns 星期几的中文名称
5
+ */
2
6
  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;
7
+ // 参数验证
8
+ if (!date) {
9
+ throw new Error('Date parameter is required');
27
10
  }
28
- return week;
11
+
12
+ const weekNames = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
13
+ const day = new Date(date).getDay();
14
+ return weekNames[day];
29
15
  }
30
- /** 获取周数的开始和结束日,getMonday("s", 0)代表本周的起始日*/
31
- export function getMonday(type: 's' | 'e', start?: number) {
16
+
17
+ /**
18
+ * 获取周数的开始和结束日
19
+ * @param type 's' 表示开始日,'e' 表示结束日
20
+ * @param weekOffset 周偏移量,0 代表本周,1 代表下周,-1 代表上周
21
+ * @returns 格式化的日期字符串 (YYYY-MM-DD)
22
+ */
23
+ export function getWeekRange(type: 's' | 'e', weekOffset: number = 0): string {
32
24
  if (!type) {
33
- throw new Error('getMonday的type参数必传')
25
+ throw new Error('Type parameter is required');
26
+ }
27
+
28
+ const now = new Date();
29
+ const nowTime = now.getTime();
30
+ const day = now.getDay();
31
+ const oneDay = 24 * 60 * 60 * 1000;
32
+ const weekOffsetMs = oneDay * 7 * weekOffset;
33
+
34
+ let stamp: number;
35
+ if (type === 's') {
36
+ // 本周一 (day=0 时表示周日,需要特殊处理)
37
+ const mondayOffset = day === 0 ? -6 : 1 - day;
38
+ stamp = nowTime + mondayOffset * oneDay + weekOffsetMs;
39
+ } else {
40
+ // 本周日
41
+ const sundayOffset = day === 0 ? 0 : 7 - day;
42
+ stamp = nowTime + sundayOffset * oneDay + weekOffsetMs;
34
43
  }
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;
44
+
45
+ const date = new Date(stamp);
46
+ const y = date.getFullYear();
47
+ const m = String(date.getMonth() + 1);
48
+ const d = String(date.getDate());
49
+
50
+ // 手动补零
51
+ const paddedMonth = ('0' + m).slice(-2);
52
+ const paddedDay = ('0' + d).slice(-2);
53
+
54
+ return `${y}-${paddedMonth}-${paddedDay}`;
55
55
  }
56
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}`;
57
+ /**
58
+ * 日期格式化
59
+ * @param date 日期对象或日期字符串
60
+ * @param format 格式化模板
61
+ * @param dayOffset 天数偏移量
62
+ * @returns 格式化后的日期字符串
63
+ */
64
+ export function formatDate(
65
+ date: Date | string | number,
66
+ format: string = 'YYYY-MM-DD',
67
+ dayOffset: number = 0
68
+ ): string {
69
+ // 参数验证
70
+ if (!date) {
71
+ return '';
92
72
  }
93
- return content;
73
+
74
+ // 计算偏移后的时间
75
+ const timestamp = new Date(date).getTime() + dayOffset * 24 * 60 * 60 * 1000;
76
+ const time = new Date(timestamp);
77
+
78
+ // 提取日期组件
79
+ const year = time.getFullYear();
80
+ const month = String(time.getMonth() + 1);
81
+ const day = String(time.getDate());
82
+ const hours = String(time.getHours());
83
+ const minutes = String(time.getMinutes());
84
+ const seconds = String(time.getSeconds());
85
+
86
+ // 手动补零
87
+ const paddedMonth = ('0' + month).slice(-2);
88
+ const paddedDay = ('0' + day).slice(-2);
89
+ const paddedHours = ('0' + hours).slice(-2);
90
+ const paddedMinutes = ('0' + minutes).slice(-2);
91
+ const paddedSeconds = ('0' + seconds).slice(-2);
92
+
93
+ // 替换格式化模板
94
+ return format
95
+ .replace('YYYY', String(year))
96
+ .replace('MM', paddedMonth)
97
+ .replace('DD', paddedDay)
98
+ .replace('HH', paddedHours)
99
+ .replace('mm', paddedMinutes)
100
+ .replace('ss', paddedSeconds);
101
+ }
102
+
103
+ /**
104
+ * 获取两个日期之间的天数差
105
+ * @param date1 第一个日期
106
+ * @param date2 第二个日期
107
+ * @returns 天数差
108
+ */
109
+ export function getDaysDiff(date1: Date | string | number, date2: Date | string | number): number {
110
+ const time1 = new Date(date1).getTime();
111
+ const time2 = new Date(date2).getTime();
112
+ const diff = Math.abs(time1 - time2);
113
+ return Math.floor(diff / (24 * 60 * 60 * 1000));
114
+ }
115
+
116
+ /**
117
+ * 判断是否是今天
118
+ * @param date 要判断的日期
119
+ * @returns 是否是今天
120
+ */
121
+ export function isToday(date: Date | string | number): boolean {
122
+ const today = new Date();
123
+ const target = new Date(date);
124
+ return (
125
+ today.getFullYear() === target.getFullYear() &&
126
+ today.getMonth() === target.getMonth() &&
127
+ today.getDate() === target.getDate()
128
+ );
129
+ }
130
+
131
+ /**
132
+ * 获取相对时间描述
133
+ * @param date 日期对象或日期字符串
134
+ * @returns 相对时间描述
135
+ */
136
+ export function getRelativeTime(date: Date | string | number): string {
137
+ const now = new Date();
138
+ const target = new Date(date);
139
+ const diff = now.getTime() - target.getTime();
140
+
141
+ const minutes = Math.floor(diff / (60 * 1000));
142
+ const hours = Math.floor(diff / (60 * 60 * 1000));
143
+ const days = Math.floor(diff / (24 * 60 * 60 * 1000));
144
+
145
+ if (minutes < 1) {
146
+ return '刚刚';
147
+ } else if (minutes < 60) {
148
+ return `${minutes}分钟前`;
149
+ } else if (hours < 24) {
150
+ return `${hours}小时前`;
151
+ } else if (days < 7) {
152
+ return `${days}天前`;
153
+ } else if (days < 30) {
154
+ return `${Math.floor(days / 7)}周前`;
155
+ } else if (days < 365) {
156
+ return `${Math.floor(days / 30)}个月前`;
157
+ } else {
158
+ return `${Math.floor(days / 365)}年前`;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * 获取当月的天数
164
+ * @param year 年份
165
+ * @param month 月份 (1-12)
166
+ * @returns 当月的天数
167
+ */
168
+ export function getDaysInMonth(year: number, month: number): number {
169
+ return new Date(year, month, 0).getDate();
170
+ }
171
+
172
+ /**
173
+ * 获取当前时间戳
174
+ * @param isMilliseconds 是否返回毫秒级时间戳
175
+ * @returns 时间戳
176
+ */
177
+ export function getTimestamp(isMilliseconds: boolean = true): number {
178
+ return isMilliseconds ? Date.now() : Math.floor(Date.now() / 1000);
94
179
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
4
5
  /* Projects */
5
6
  // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
6
7
  // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
@@ -8,8 +9,9 @@
8
9
  // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
9
10
  // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
10
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
11
13
  /* Language and Environment */
12
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
13
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
15
17
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -21,8 +23,9 @@
21
23
  // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
22
24
  // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
23
25
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
24
27
  /* Modules */
25
- "module": "ESNext", /* Specify what module code is generated. */
28
+ "module": "commonjs", /* Specify what module code is generated. */
26
29
  // "rootDir": "./", /* Specify the root folder within your source files. */
27
30
  // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
28
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -39,10 +42,12 @@
39
42
  // "resolveJsonModule": true, /* Enable importing .json files. */
40
43
  // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
41
44
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
42
46
  /* JavaScript Support */
43
47
  // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
44
48
  // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
45
49
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
46
51
  /* Emit */
47
52
  // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48
53
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
@@ -67,15 +72,17 @@
67
72
  // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
73
  // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69
74
  // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
70
76
  /* Interop Constraints */
71
77
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
72
78
  // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
73
79
  // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
80
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
81
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
82
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83
+
77
84
  /* Type Checking */
78
- "strict": true, /* Enable all strict type-checking options. */
85
+ "strict": true, /* Enable all strict type-checking options. */
79
86
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
80
87
  // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
81
88
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
@@ -94,9 +101,9 @@
94
101
  // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
95
102
  // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
96
103
  // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104
+
97
105
  /* Completeness */
98
106
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
100
- "declaration": true
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
101
108
  }
102
- }
109
+ }
package/webpack.config.js CHANGED
@@ -16,7 +16,7 @@ module.exports = {
16
16
  rules: [
17
17
  {
18
18
  test: /\.(js|ts)$/,
19
- exclude: /(node_modules|bower_components)/, // 屏蔽不需要处理的文件(文件夹)(可选)
19
+ exclude: /(node_modules|bower_components)/,
20
20
  use: ["babel-loader"],
21
21
  }
22
22
  ]
@@ -24,7 +24,6 @@ module.exports = {
24
24
  plugins: [
25
25
  new CleanWebpackPlugin()
26
26
  ],
27
- // 解析
28
27
  resolve: {
29
28
  extensions: [".ts", ".js", ".json"],
30
29
  alias: {
@@ -34,7 +33,80 @@ module.exports = {
34
33
  optimization: {
35
34
  minimize: true,
36
35
  minimizer: [
37
- new TerserPlugin(),
38
- ]
36
+ new TerserPlugin({
37
+ terserOptions: {
38
+ compress: {
39
+ drop_console: true,
40
+ drop_debugger: true,
41
+ dead_code: true,
42
+ passes: 3,
43
+ pure_funcs: ['console.log', 'console.debug', 'console.warn', 'console.error'],
44
+ reduce_vars: true,
45
+ unsafe: true,
46
+ unsafe_comps: true,
47
+ unsafe_math: true,
48
+ unsafe_symbols: true,
49
+ unsafe_methods: true,
50
+ unsafe_proto: true,
51
+ unsafe_regexp: true,
52
+ unsafe_undefined: true,
53
+ keep_fargs: false,
54
+ keep_infinity: false,
55
+ module: true,
56
+ toplevel: true,
57
+ booleans: true,
58
+ comparisons: true,
59
+ conditionals: true,
60
+ directives: true,
61
+ evaluate: true,
62
+ expression: true,
63
+ hoist_funs: true,
64
+ hoist_props: true,
65
+ hoist_vars: true,
66
+ if_return: true,
67
+ join_vars: true,
68
+ loops: true,
69
+ negate_iife: true,
70
+ properties: true,
71
+ reduce_funcs: true,
72
+ sequences: true,
73
+ side_effects: true,
74
+ switches: true,
75
+ typeofs: true,
76
+ unsafe_arrows: true,
77
+ unsafe_Function: true
78
+ },
79
+ mangle: {
80
+ toplevel: true,
81
+ eval: true,
82
+ keep_fnames: false,
83
+ keep_classnames: false,
84
+ reserved: []
85
+ },
86
+ output: {
87
+ comments: false,
88
+ beautify: false,
89
+ ascii_only: true,
90
+ inline_script: true,
91
+ max_line_len: 500,
92
+ wrap_iife: true,
93
+ preamble: ""
94
+ },
95
+ parse: {
96
+ bare_returns: true,
97
+ html5_comments: false,
98
+ shebang: false
99
+ },
100
+ toplevel: true,
101
+ keep_classnames: false,
102
+ keep_fnames: false
103
+ },
104
+ extractComments: false,
105
+ parallel: true
106
+ }),
107
+ ],
108
+ usedExports: true,
109
+ sideEffects: false,
110
+ concatenateModules: true
39
111
  }
40
112
  };
package/test.html DELETED
@@ -1,20 +0,0 @@
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>