@antsoo-lib/utils 0.1.1 → 0.2.0
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/dist/index.cjs +749 -589
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -13
- package/dist/index.d.ts +25 -13
- package/dist/index.js +627 -495
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,604 +1,736 @@
|
|
|
1
|
-
// src/date.ts
|
|
2
1
|
import dayjs from "dayjs";
|
|
2
|
+
import { add, bignumber, divide, multiply, subtract } from "mathjs";
|
|
3
|
+
import { isArguments as isArguments$1, isArray as isArray$1, isArrayBuffer as isArrayBuffer$1, isArrayLike as isArrayLike$1, isArrayLikeObject as isArrayLikeObject$1, isBoolean as isBoolean$1, isDate as isDate$1, isElement as isElement$1, isEmpty as isEmpty$1, isEqual as isEqual$1, isError as isError$1, isFinite as isFinite$1, isFunction as isFunction$1, isInteger as isInteger$1, isLength as isLength$1, isMap as isMap$1, isMatch as isMatch$1, isNaN as isNaN$1, isNative as isNative$1, isNil as isNil$1, isNull as isNull$1, isNumber as isNumber$1, isObject as isObject$1, isObjectLike as isObjectLike$1, isPlainObject as isPlainObject$1, isRegExp as isRegExp$1, isSafeInteger as isSafeInteger$1, isSet as isSet$1, isString as isString$1, isSymbol as isSymbol$1, isTypedArray as isTypedArray$1, isUndefined as isUndefined$1, isWeakMap as isWeakMap$1, isWeakSet as isWeakSet$1 } from "lodash-es";
|
|
4
|
+
|
|
5
|
+
//#region src/date.ts
|
|
6
|
+
/**
|
|
7
|
+
* 校验日期是否与指定日期相同或晚于指定日期
|
|
8
|
+
* @param date 日期
|
|
9
|
+
* @param day 指定日期
|
|
10
|
+
* @returns 是否相同或晚于指定日期
|
|
11
|
+
*/
|
|
3
12
|
function isSameOrAfterDay(date, day) {
|
|
4
|
-
|
|
5
|
-
}
|
|
13
|
+
return dayjs(date).isSame(dayjs(day), "day") || dayjs(date).isAfter(dayjs(day), "day");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 校验日期是否与指定日期相同或早于指定日期
|
|
17
|
+
* @param date 日期
|
|
18
|
+
* @param day 指定日期
|
|
19
|
+
* @returns 是否相同或早于指定日期
|
|
20
|
+
*/
|
|
6
21
|
function isSameOrBeforeDay(date, day) {
|
|
7
|
-
|
|
22
|
+
return dayjs(date).isSame(dayjs(day), "day") || dayjs(date).isBefore(dayjs(day), "day");
|
|
8
23
|
}
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
isArrayBuffer as _isArrayBuffer,
|
|
18
|
-
isArrayLike as _isArrayLike,
|
|
19
|
-
isArrayLikeObject as _isArrayLikeObject,
|
|
20
|
-
isBoolean as _isBoolean,
|
|
21
|
-
isDate as _isDate,
|
|
22
|
-
isElement as _isElement,
|
|
23
|
-
isEqual as _isEqual,
|
|
24
|
-
isError as _isError,
|
|
25
|
-
isFinite as _isFinite,
|
|
26
|
-
isInteger as _isInteger,
|
|
27
|
-
isLength as _isLength,
|
|
28
|
-
isMap as _isMap,
|
|
29
|
-
isMatch as _isMatch,
|
|
30
|
-
isNative as _isNative,
|
|
31
|
-
isNull as _isNull,
|
|
32
|
-
isObjectLike as _isObjectLike,
|
|
33
|
-
isPlainObject as _isPlainObject,
|
|
34
|
-
isRegExp as _isRegExp,
|
|
35
|
-
isSafeInteger as _isSafeInteger,
|
|
36
|
-
isSet as _isSet,
|
|
37
|
-
isSymbol as _isSymbol,
|
|
38
|
-
isTypedArray as _isTypedArray,
|
|
39
|
-
isWeakMap as _isWeakMap,
|
|
40
|
-
isWeakSet as _isWeakSet,
|
|
41
|
-
isEmpty as lodashIsEmpty,
|
|
42
|
-
isFunction as lodashIsFunction,
|
|
43
|
-
isNaN as lodashIsNaN,
|
|
44
|
-
isNil as lodashIsNil,
|
|
45
|
-
isNumber as lodashIsNumber,
|
|
46
|
-
isObject as lodashIsObject,
|
|
47
|
-
isString as lodashIsString,
|
|
48
|
-
isUndefined as lodashIsUndefined
|
|
49
|
-
} from "lodash-es";
|
|
50
|
-
var getTag = (value) => {
|
|
51
|
-
return Object.prototype.toString.call(value);
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/is.ts
|
|
27
|
+
/**
|
|
28
|
+
* 获取值的类型标签
|
|
29
|
+
*/
|
|
30
|
+
const getTag = (value) => {
|
|
31
|
+
return Object.prototype.toString.call(value);
|
|
52
32
|
};
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
/**
|
|
34
|
+
* 检查是否为数组 - 使用 lodash-es 的实现
|
|
35
|
+
*/
|
|
36
|
+
const isArray = isArray$1;
|
|
37
|
+
/**
|
|
38
|
+
* 检查是否为 ArrayBuffer
|
|
39
|
+
*/
|
|
40
|
+
const isArrayBuffer = isArrayBuffer$1;
|
|
41
|
+
/**
|
|
42
|
+
* 检查是否为 AsyncFunction
|
|
43
|
+
*/
|
|
55
44
|
function isAsyncFunction(value) {
|
|
56
|
-
|
|
45
|
+
return getTag(value) === "[object AsyncFunction]" || typeof value === "function" && value.constructor.name === "AsyncFunction";
|
|
57
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* 检查是否为 BigInt
|
|
49
|
+
*/
|
|
58
50
|
function isBigInt(value) {
|
|
59
|
-
|
|
51
|
+
return typeof value === "bigint" || getTag(value) === "[object BigInt]";
|
|
60
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* 检查是否为 Blob 对象(浏览器环境)
|
|
55
|
+
*/
|
|
61
56
|
function isBlob(value) {
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 检查是否为布尔值 - 使用 lodash-es 的实现
|
|
61
|
+
*/
|
|
62
|
+
const isBoolean = isBoolean$1;
|
|
63
|
+
/**
|
|
64
|
+
* 检查是否为类数组
|
|
65
|
+
*/
|
|
66
|
+
const isArrayLike = isArrayLike$1;
|
|
67
|
+
/**
|
|
68
|
+
* 检查是否为类数组对象
|
|
69
|
+
*/
|
|
70
|
+
const isArrayLikeObject = isArrayLikeObject$1;
|
|
71
|
+
/**
|
|
72
|
+
* 检查是否为类数组参数
|
|
73
|
+
*/
|
|
74
|
+
const isArguments = isArguments$1;
|
|
75
|
+
/**
|
|
76
|
+
* 检查是否为 Date 对象 - 使用 lodash-es 的实现
|
|
77
|
+
*/
|
|
78
|
+
const isDate = isDate$1;
|
|
79
|
+
/**
|
|
80
|
+
* 检查是否为 DOM 元素 - 使用 lodash-es 的实现
|
|
81
|
+
*/
|
|
82
|
+
const isElement = isElement$1;
|
|
83
|
+
/**
|
|
84
|
+
* 检查是否为空值 - 使用 lodash-es 的实现
|
|
85
|
+
*/
|
|
86
|
+
const isEmpty = isEmpty$1;
|
|
87
|
+
/**
|
|
88
|
+
* 检查是否严格相等 - 使用 lodash-es 的实现
|
|
89
|
+
*/
|
|
90
|
+
const isEqual = isEqual$1;
|
|
91
|
+
/**
|
|
92
|
+
* 检查是否为 Error 对象 - 使用 lodash-es 的实现
|
|
93
|
+
*/
|
|
94
|
+
const isError = isError$1;
|
|
95
|
+
/**
|
|
96
|
+
* 检查是否为 File 对象(浏览器环境)
|
|
97
|
+
*/
|
|
73
98
|
function isFile(value) {
|
|
74
|
-
|
|
99
|
+
return typeof File !== "undefined" && value instanceof File;
|
|
75
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 检查是否为 FormData 对象(浏览器环境)
|
|
103
|
+
*/
|
|
76
104
|
function isFormData(value) {
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
105
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 检查是否为函数 - 使用 lodash-es 的实现
|
|
109
|
+
*/
|
|
110
|
+
const isFunction = isFunction$1;
|
|
111
|
+
/**
|
|
112
|
+
* 检查是否为 GeneratorFunction
|
|
113
|
+
*/
|
|
80
114
|
function isGeneratorFunction(value) {
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
return getTag(value) === "[object GeneratorFunction]" || typeof value === "function" && value.constructor.name === "GeneratorFunction";
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 检查是否为整数 - 使用 lodash-es 的实现
|
|
119
|
+
*/
|
|
120
|
+
const isInteger = isInteger$1;
|
|
121
|
+
/**
|
|
122
|
+
* 检查是否为有限数 - 使用 lodash-es 的实现
|
|
123
|
+
*/
|
|
124
|
+
const isFinite = isFinite$1;
|
|
125
|
+
/**
|
|
126
|
+
* 检查是否为有效长度 - 使用 lodash-es 的实现
|
|
127
|
+
*/
|
|
128
|
+
const isLength = isLength$1;
|
|
129
|
+
/**
|
|
130
|
+
* 检查是否为 Map - 使用 lodash-es 的实现
|
|
131
|
+
*/
|
|
132
|
+
const isMap = isMap$1;
|
|
133
|
+
/**
|
|
134
|
+
* 检查是否为 NaN - 使用 lodash-es 的实现
|
|
135
|
+
*/
|
|
136
|
+
const isNaN = isNaN$1;
|
|
137
|
+
/**
|
|
138
|
+
* 检查是否为 null 或 undefined - 使用 lodash-es 的实现
|
|
139
|
+
*/
|
|
140
|
+
const isNil = isNil$1;
|
|
141
|
+
/**
|
|
142
|
+
* 检查是否为 null - 使用 lodash-es 的实现
|
|
143
|
+
*/
|
|
144
|
+
const isNull = isNull$1;
|
|
145
|
+
/**
|
|
146
|
+
* 检查是否为数字 - 使用 lodash-es 的实现
|
|
147
|
+
*/
|
|
148
|
+
const isNumber = isNumber$1;
|
|
149
|
+
/**
|
|
150
|
+
* 检查是否为对象 - 使用 lodash-es 的实现
|
|
151
|
+
*/
|
|
152
|
+
const isObject = isObject$1;
|
|
153
|
+
/**
|
|
154
|
+
* 检查是否为类对象 - 使用 lodash-es 的实现
|
|
155
|
+
*/
|
|
156
|
+
const isObjectLike = isObjectLike$1;
|
|
157
|
+
/**
|
|
158
|
+
* 检查是否为普通对象 - 使用 lodash-es 的实现
|
|
159
|
+
*/
|
|
160
|
+
const isPlainObject = isPlainObject$1;
|
|
161
|
+
/**
|
|
162
|
+
* 检查是否匹配对象 - 使用 lodash-es 的实现
|
|
163
|
+
*/
|
|
164
|
+
const isMatch = isMatch$1;
|
|
165
|
+
/**
|
|
166
|
+
* 检查是否为原生函数 - 使用 lodash-es 的实现
|
|
167
|
+
*/
|
|
168
|
+
const isNative = isNative$1;
|
|
169
|
+
/**
|
|
170
|
+
* 检查是否为浏览器环境
|
|
171
|
+
*/
|
|
96
172
|
function isBrowser() {
|
|
97
|
-
|
|
173
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
98
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* 检查是否为 Promise
|
|
177
|
+
*/
|
|
99
178
|
function isPromise(value) {
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
179
|
+
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 检查是否为 RegExp - 使用 lodash-es 的实现
|
|
183
|
+
*/
|
|
184
|
+
const isRegExp = isRegExp$1;
|
|
185
|
+
/**
|
|
186
|
+
* 检查是否为安全整数 - 使用 lodash-es 的实现
|
|
187
|
+
*/
|
|
188
|
+
const isSafeInteger = isSafeInteger$1;
|
|
189
|
+
/**
|
|
190
|
+
* 检查是否为 Set - 使用 lodash-es 的实现
|
|
191
|
+
*/
|
|
192
|
+
const isSet = isSet$1;
|
|
193
|
+
/**
|
|
194
|
+
* 检查是否为字符串 - 使用 lodash-es 的实现
|
|
195
|
+
*/
|
|
196
|
+
const isString = isString$1;
|
|
197
|
+
/**
|
|
198
|
+
* 检查是否为 Symbol - 使用 lodash-es 的实现
|
|
199
|
+
*/
|
|
200
|
+
const isSymbol = isSymbol$1;
|
|
201
|
+
/**
|
|
202
|
+
* 检查是否为 TypedArray - 使用 lodash-es 的实现
|
|
203
|
+
*/
|
|
204
|
+
const isTypedArray = isTypedArray$1;
|
|
205
|
+
/**
|
|
206
|
+
* 检查是否为 undefined - 使用 lodash-es 的实现
|
|
207
|
+
*/
|
|
208
|
+
const isUndefined = isUndefined$1;
|
|
209
|
+
/**
|
|
210
|
+
* 检查是否为 URL 对象(浏览器环境)
|
|
211
|
+
*/
|
|
109
212
|
function isURL(value) {
|
|
110
|
-
|
|
213
|
+
return typeof URL !== "undefined" && value instanceof URL;
|
|
111
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 检查是否为 URLSearchParams 对象(浏览器环境)
|
|
217
|
+
*/
|
|
112
218
|
function isURLSearchParams(value) {
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
219
|
+
return typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 检查是否为 WeakMap - 使用 lodash-es 的实现
|
|
223
|
+
*/
|
|
224
|
+
const isWeakMap = isWeakMap$1;
|
|
225
|
+
/**
|
|
226
|
+
* 检查是否为 WeakSet - 使用 lodash-es 的实现
|
|
227
|
+
*/
|
|
228
|
+
const isWeakSet = isWeakSet$1;
|
|
229
|
+
/**
|
|
230
|
+
* 检查是否为 Window 对象(浏览器环境)
|
|
231
|
+
*/
|
|
117
232
|
function isWindow(value) {
|
|
118
|
-
|
|
233
|
+
return isBrowser() && value === window;
|
|
119
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* 检查是否为 Document 对象(浏览器环境)
|
|
237
|
+
*/
|
|
120
238
|
function isDocument(value) {
|
|
121
|
-
|
|
239
|
+
return isBrowser() && value === document;
|
|
122
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* 检查是否为 Event 对象(浏览器环境)
|
|
243
|
+
*/
|
|
123
244
|
function isEvent(value) {
|
|
124
|
-
|
|
245
|
+
return isBrowser() && value instanceof Event;
|
|
125
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* 检查是否为 Primitive 类型
|
|
249
|
+
*/
|
|
126
250
|
function isPrimitive(value) {
|
|
127
|
-
|
|
251
|
+
return isString(value) || isNumber(value) || isBoolean(value) || isSymbol(value) || isBigInt(value) || isNull(value) || isUndefined(value);
|
|
128
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* 检查是否为 Iterable 对象
|
|
255
|
+
*/
|
|
129
256
|
function isIterable(value) {
|
|
130
|
-
|
|
257
|
+
return value != null && typeof value[Symbol.iterator] === "function";
|
|
131
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* 检查是否为 AsyncIterable 对象
|
|
261
|
+
*/
|
|
132
262
|
function isAsyncIterable(value) {
|
|
133
|
-
|
|
263
|
+
return value != null && typeof value[Symbol.asyncIterator] === "function";
|
|
134
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* 检查是否为 Iterator 对象
|
|
267
|
+
*/
|
|
135
268
|
function isIterator(value) {
|
|
136
|
-
|
|
269
|
+
return value != null && typeof value.next === "function";
|
|
137
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* 检查是否为 Array Iterator
|
|
273
|
+
*/
|
|
138
274
|
function isArrayIterator(value) {
|
|
139
|
-
|
|
275
|
+
return getTag(value) === "[object Array Iterator]";
|
|
140
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* 检查是否为 Map Iterator
|
|
279
|
+
*/
|
|
141
280
|
function isMapIterator(value) {
|
|
142
|
-
|
|
281
|
+
return getTag(value) === "[object Map Iterator]";
|
|
143
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* 检查是否为 Set Iterator
|
|
285
|
+
*/
|
|
144
286
|
function isSetIterator(value) {
|
|
145
|
-
|
|
287
|
+
return getTag(value) === "[object Set Iterator]";
|
|
146
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* 检查是否为 String Iterator
|
|
291
|
+
*/
|
|
147
292
|
function isStringIterator(value) {
|
|
148
|
-
|
|
293
|
+
return getTag(value) === "[object String Iterator]";
|
|
149
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* 检查是否为可序列化的 JSON 值
|
|
297
|
+
*/
|
|
150
298
|
function isJSONSerializable(value) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
299
|
+
if (isPrimitive(value)) return !isUndefined(value);
|
|
300
|
+
if (isArray(value)) return value.every(isJSONSerializable);
|
|
301
|
+
if (isPlainObject(value)) return Object.values(value).every(isJSONSerializable);
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 检查是否为有效的数组索引
|
|
306
|
+
*/
|
|
162
307
|
function isArrayIndex(value) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const num = Number(value);
|
|
167
|
-
return isInteger(num) && num >= 0 && num < Number.MAX_SAFE_INTEGER && String(num) === String(value);
|
|
308
|
+
if (!isNumber(value) && !isString(value)) return false;
|
|
309
|
+
const num = Number(value);
|
|
310
|
+
return isInteger(num) && num >= 0 && num < Number.MAX_SAFE_INTEGER && String(num) === String(value);
|
|
168
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* 检查是否为有效的 Email 地址
|
|
314
|
+
*/
|
|
169
315
|
function isEmail(value) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return emailRegex.test(value);
|
|
316
|
+
if (!isString(value)) return false;
|
|
317
|
+
return /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(value);
|
|
173
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* 检查是否为有效的 URL 字符串
|
|
321
|
+
*/
|
|
174
322
|
function isURLString(value) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
323
|
+
if (!isString(value)) return false;
|
|
324
|
+
try {
|
|
325
|
+
new URL(value);
|
|
326
|
+
return true;
|
|
327
|
+
} catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* 检查是否为有效的手机号码(中国)
|
|
333
|
+
*/
|
|
183
334
|
function isChinesePhone(value) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return phoneRegex.test(value);
|
|
335
|
+
if (!isString(value)) return false;
|
|
336
|
+
return /^1[3-9]\d{9}$/.test(value);
|
|
187
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* 检查是否为有效的身份证号码(中国)
|
|
340
|
+
*/
|
|
188
341
|
function isChineseIDCard(value) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
342
|
+
if (!isString(value)) return false;
|
|
343
|
+
if (!/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[0-9X]$/i.test(value)) return false;
|
|
344
|
+
const weights = [
|
|
345
|
+
7,
|
|
346
|
+
9,
|
|
347
|
+
10,
|
|
348
|
+
5,
|
|
349
|
+
8,
|
|
350
|
+
4,
|
|
351
|
+
2,
|
|
352
|
+
1,
|
|
353
|
+
6,
|
|
354
|
+
3,
|
|
355
|
+
7,
|
|
356
|
+
9,
|
|
357
|
+
10,
|
|
358
|
+
5,
|
|
359
|
+
8,
|
|
360
|
+
4,
|
|
361
|
+
2
|
|
362
|
+
];
|
|
363
|
+
const checkCodes = [
|
|
364
|
+
"1",
|
|
365
|
+
"0",
|
|
366
|
+
"X",
|
|
367
|
+
"9",
|
|
368
|
+
"8",
|
|
369
|
+
"7",
|
|
370
|
+
"6",
|
|
371
|
+
"5",
|
|
372
|
+
"4",
|
|
373
|
+
"3",
|
|
374
|
+
"2"
|
|
375
|
+
];
|
|
376
|
+
let sum = 0;
|
|
377
|
+
for (let i = 0; i < 17; i++) sum += Number.parseInt(value[i]) * weights[i];
|
|
378
|
+
return checkCodes[sum % 11] === value[17].toUpperCase();
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* 检查是否为有效的邮政编码(中国)
|
|
382
|
+
*/
|
|
201
383
|
function isChinesePostalCode(value) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return postalCodeRegex.test(value);
|
|
384
|
+
if (!isString(value)) return false;
|
|
385
|
+
return /^[1-9]\d{5}$/.test(value);
|
|
205
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* 检查是否为有效的 JSON 字符串
|
|
389
|
+
*/
|
|
206
390
|
function isJSONString(value) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
391
|
+
if (!isString(value)) return false;
|
|
392
|
+
try {
|
|
393
|
+
JSON.parse(value);
|
|
394
|
+
return true;
|
|
395
|
+
} catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* 检查是否为 Base64 字符串
|
|
401
|
+
*/
|
|
215
402
|
function isBase64(value) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return base64Regex.test(value);
|
|
403
|
+
if (!isString(value)) return false;
|
|
404
|
+
return /^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$/i.test(value);
|
|
219
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* 检查是否为 Hex 颜色值
|
|
408
|
+
*/
|
|
220
409
|
function isHexColor(value) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return hexColorRegex.test(value);
|
|
410
|
+
if (!isString(value)) return false;
|
|
411
|
+
return /^#?[a-f0-9]{6}$|^#?[a-f0-9]{3}$/i.test(value);
|
|
224
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* 检查是否为 RGB 颜色值
|
|
415
|
+
*/
|
|
225
416
|
function isRGBColor(value) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return rgbColorRegex.test(value);
|
|
417
|
+
if (!isString(value)) return false;
|
|
418
|
+
return /^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$/.test(value);
|
|
229
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* 检查是否为 HSL 颜色值
|
|
422
|
+
*/
|
|
230
423
|
function isHSLColor(value) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return hslColorRegex.test(value);
|
|
424
|
+
if (!isString(value)) return false;
|
|
425
|
+
return /^hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\)$/.test(value);
|
|
234
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* 检查是否为有效的日期字符串
|
|
429
|
+
*/
|
|
235
430
|
function isDateString(value) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return !isNaN(date.getTime());
|
|
431
|
+
if (!isString(value)) return false;
|
|
432
|
+
return !isNaN(new Date(value).getTime());
|
|
239
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* 检查是否为有效的时间字符串
|
|
436
|
+
*/
|
|
240
437
|
function isTimeString(value) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return timeRegex.test(value);
|
|
438
|
+
if (!isString(value)) return false;
|
|
439
|
+
return /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(value);
|
|
244
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* 检查是否为有效的日期时间字符串
|
|
443
|
+
*/
|
|
245
444
|
function isDateTimeString(value) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return dateTimeRegex.test(value) && !isNaN(new Date(value).getTime());
|
|
445
|
+
if (!isString(value)) return false;
|
|
446
|
+
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$/.test(value) && !isNaN(new Date(value).getTime());
|
|
249
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* 检查是否为有效的时区
|
|
450
|
+
*/
|
|
250
451
|
function isTimezone(value) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
452
|
+
if (!isString(value)) return false;
|
|
453
|
+
try {
|
|
454
|
+
Intl.DateTimeFormat(void 0, { timeZone: value });
|
|
455
|
+
return true;
|
|
456
|
+
} catch {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* 检查是否为有效的正则表达式字符串
|
|
462
|
+
*/
|
|
259
463
|
function isRegExpString(value) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
464
|
+
if (!isString(value)) return false;
|
|
465
|
+
try {
|
|
466
|
+
new RegExp(value);
|
|
467
|
+
return true;
|
|
468
|
+
} catch {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* 检查是否为有效的 XML 字符串
|
|
474
|
+
*/
|
|
268
475
|
function isXMLString(value) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
476
|
+
if (!isString(value)) return false;
|
|
477
|
+
try {
|
|
478
|
+
if (isBrowser()) return new DOMParser().parseFromString(value, "application/xml").getElementsByTagName("parsererror").length === 0;
|
|
479
|
+
return false;
|
|
480
|
+
} catch {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* 检查是否为有效的 HTML 字符串
|
|
486
|
+
*/
|
|
281
487
|
function isHTMLString(value) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return false;
|
|
290
|
-
} catch {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
488
|
+
if (!isString(value)) return false;
|
|
489
|
+
try {
|
|
490
|
+
if (isBrowser()) return new DOMParser().parseFromString(value, "text/html").body.children.length > 0;
|
|
491
|
+
return false;
|
|
492
|
+
} catch {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
293
495
|
}
|
|
294
496
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/math.ts
|
|
499
|
+
const computeTaxAmountFn = (weight, price) => {
|
|
500
|
+
if (!isFinite(price) || !isFinite(weight)) return 0;
|
|
501
|
+
const weightBig = bignumber(weight);
|
|
502
|
+
const priceBig = bignumber(price);
|
|
503
|
+
return Number(multiply(weightBig, priceBig));
|
|
302
504
|
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return value;
|
|
505
|
+
const computeTaxAmount2Fn = (weight, price) => {
|
|
506
|
+
if (!isFinite(price) || !isFinite(weight)) return 0;
|
|
507
|
+
const weightBig = bignumber(weight);
|
|
508
|
+
const priceBig = bignumber(price);
|
|
509
|
+
return Number(multiply(weightBig, priceBig));
|
|
309
510
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return value;
|
|
511
|
+
const computePriceFn = (taxAmount, weight) => {
|
|
512
|
+
if (!isFinite(taxAmount) || !isFinite(weight) || weight <= 0) return 0;
|
|
513
|
+
const taxAmountBig = bignumber(taxAmount);
|
|
514
|
+
const weightBig = bignumber(weight);
|
|
515
|
+
return Number(divide(taxAmountBig, weightBig));
|
|
316
516
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return value;
|
|
517
|
+
const computeWeightFn = (taxAmount, price) => {
|
|
518
|
+
if (!isFinite(taxAmount) || !isFinite(price) || price <= 0) return 0;
|
|
519
|
+
const taxAmountBig = bignumber(taxAmount);
|
|
520
|
+
const priceBig = bignumber(price);
|
|
521
|
+
return Number(divide(taxAmountBig, priceBig));
|
|
323
522
|
};
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return value;
|
|
523
|
+
const computePrice2Fn = (noTaxPrice, taxRate) => {
|
|
524
|
+
if (!isFinite(noTaxPrice) || !isFinite(taxRate)) return 0;
|
|
525
|
+
const noTaxPriceBig = bignumber(noTaxPrice);
|
|
526
|
+
const taxRateBig = divide(taxRate, 100);
|
|
527
|
+
return Number(multiply(noTaxPriceBig, add(1, taxRateBig)));
|
|
330
528
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return value;
|
|
529
|
+
const computeNoTaxPriceFn = (price, taxRate) => {
|
|
530
|
+
if (!isFinite(price) || !isFinite(taxRate)) return 0;
|
|
531
|
+
const priceBig = bignumber(price);
|
|
532
|
+
const taxRateBig = divide(taxRate, 100);
|
|
533
|
+
return Number(divide(priceBig, add(1, taxRateBig)));
|
|
337
534
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return value;
|
|
535
|
+
const computeTaxRateFn = (price, noTaxPrice) => {
|
|
536
|
+
if (!isFinite(price) || !isFinite(noTaxPrice)) return 0;
|
|
537
|
+
const priceBig = bignumber(price);
|
|
538
|
+
const noTaxPriceBig = bignumber(noTaxPrice);
|
|
539
|
+
return Number(subtract(divide(priceBig, noTaxPriceBig), 1));
|
|
344
540
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return value;
|
|
541
|
+
const computeNoTaxPrice2Fn = (noTaxAmount, weight) => {
|
|
542
|
+
if (!isFinite(noTaxAmount) || !isFinite(weight) || weight <= 0) return 0;
|
|
543
|
+
const noTaxAmountBig = bignumber(noTaxAmount);
|
|
544
|
+
const weightBig = bignumber(weight);
|
|
545
|
+
return Number(divide(noTaxAmountBig, weightBig));
|
|
351
546
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
return value;
|
|
547
|
+
const computeNoTaxAmountFn = (weight, noTaxPrice) => {
|
|
548
|
+
if (!isFinite(noTaxPrice) || !isFinite(weight)) return 0;
|
|
549
|
+
const weightBig = bignumber(weight);
|
|
550
|
+
const noTaxPriceBig = bignumber(noTaxPrice);
|
|
551
|
+
return Number(multiply(weightBig, noTaxPriceBig));
|
|
358
552
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return value;
|
|
553
|
+
const computeNoTaxAmount2Fn = (taxAmount, taxRate) => {
|
|
554
|
+
if (!isFinite(taxAmount) || !isFinite(taxRate)) return 0;
|
|
555
|
+
const taxAmountBig = bignumber(taxAmount);
|
|
556
|
+
const taxRateBig = divide(taxRate, 100);
|
|
557
|
+
return Number(divide(taxAmountBig, add(1, taxRateBig)));
|
|
365
558
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return value;
|
|
559
|
+
const computeTaxFn = (taxAmount, noTaxAmount) => {
|
|
560
|
+
const taxAmountBig = bignumber(taxAmount || 0);
|
|
561
|
+
const noTaxAmountBig = bignumber(noTaxAmount || 0);
|
|
562
|
+
return Number(subtract(taxAmountBig, noTaxAmountBig));
|
|
371
563
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return value;
|
|
564
|
+
const computeGoodsNumFn = (weight, weight1) => {
|
|
565
|
+
if (!isFinite(weight1) || !isFinite(weight) || weight1 <= 0) return 0;
|
|
566
|
+
const weightBig = bignumber(weight);
|
|
567
|
+
const weight1Big = bignumber(weight1);
|
|
568
|
+
return Number(divide(weightBig, weight1Big));
|
|
378
569
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return value;
|
|
570
|
+
const computeGoodsWeightFn = (num, weight1) => {
|
|
571
|
+
if (!isFinite(weight1) || !isFinite(num) || weight1 <= 0) return 0;
|
|
572
|
+
const numBig = bignumber(num);
|
|
573
|
+
const weight1Big = bignumber(weight1);
|
|
574
|
+
return Number(multiply(numBig, weight1Big));
|
|
385
575
|
};
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
576
|
+
const addFn = (a, b) => {
|
|
577
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
578
|
+
const aBig = bignumber(a);
|
|
579
|
+
const bBig = bignumber(b);
|
|
580
|
+
return Number(add(aBig, bBig));
|
|
391
581
|
};
|
|
582
|
+
/**
|
|
583
|
+
* 合计
|
|
584
|
+
* @param arr 数组
|
|
585
|
+
* @param key 键名
|
|
586
|
+
* @returns 合计值
|
|
587
|
+
*/
|
|
392
588
|
function sumBy(arr, key) {
|
|
393
|
-
|
|
589
|
+
return arr.reduce((acc, cur) => addFn(acc, Number(cur[key])), 0);
|
|
394
590
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
591
|
+
const subtractFn = (a, b) => {
|
|
592
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
593
|
+
const aBig = bignumber(a);
|
|
594
|
+
const bBig = bignumber(b);
|
|
595
|
+
return Number(subtract(aBig, bBig));
|
|
400
596
|
};
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
597
|
+
const multiplyFn = (a, b) => {
|
|
598
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
599
|
+
const aBig = bignumber(a);
|
|
600
|
+
const bBig = bignumber(b);
|
|
601
|
+
return Number(multiply(aBig, bBig));
|
|
406
602
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
603
|
+
const divideFn = (a, b) => {
|
|
604
|
+
if (!isFinite(a) || !isFinite(b) || b === 0) return 0;
|
|
605
|
+
const aBig = bignumber(a);
|
|
606
|
+
const bBig = bignumber(b);
|
|
607
|
+
return Number(divide(aBig, bBig));
|
|
412
608
|
};
|
|
413
609
|
|
|
414
|
-
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/format.ts
|
|
612
|
+
/**
|
|
613
|
+
* 格式化数字
|
|
614
|
+
* @param number 输入的数字
|
|
615
|
+
* @param decimals 保留小数位数
|
|
616
|
+
* @param thousands_sep 千分位分隔符
|
|
617
|
+
* @returns 格式化后的字符串
|
|
618
|
+
*/
|
|
415
619
|
function formatNumber(number, decimals = 2, thousands_sep = ",") {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
620
|
+
if (number === null || number === void 0 || number === "") return "";
|
|
621
|
+
let num = Number.parseFloat(String(number));
|
|
622
|
+
if (Number.isNaN(num)) return "";
|
|
623
|
+
num = Math.round(num * 10 ** decimals) / 10 ** decimals;
|
|
624
|
+
const parts = num.toFixed(decimals).split(".");
|
|
625
|
+
if (thousands_sep) {
|
|
626
|
+
const re = /(-?\d+)(\d{3})/;
|
|
627
|
+
while (re.test(parts[0])) parts[0] = parts[0].replace(re, `$1${thousands_sep}$2`);
|
|
628
|
+
}
|
|
629
|
+
return parts.join(".");
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 格式化数字
|
|
633
|
+
* @param number 输入的数字
|
|
634
|
+
*/
|
|
430
635
|
function toThousands(number) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
636
|
+
if (number === null || number === void 0 || number === "") return "";
|
|
637
|
+
const n = Number(number);
|
|
638
|
+
if (Number.isNaN(n)) return "";
|
|
639
|
+
return n.toLocaleString("en-US");
|
|
435
640
|
}
|
|
436
641
|
|
|
437
|
-
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/cookie.ts
|
|
644
|
+
/**
|
|
645
|
+
* 设置 Cookie
|
|
646
|
+
* @param name Cookie 名称
|
|
647
|
+
* @param value Cookie 值
|
|
648
|
+
* @param days 过期天数,默认 7 天
|
|
649
|
+
* @param path 路径,默认 '/'
|
|
650
|
+
* @param domain 域名
|
|
651
|
+
* @param secure 是否仅在 HTTPS 下传输
|
|
652
|
+
*/
|
|
438
653
|
function setCookie(name, value, days = 1, path = "/", domain, secure = false) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
654
|
+
let expires = "";
|
|
655
|
+
if (days) {
|
|
656
|
+
const date = /* @__PURE__ */ new Date();
|
|
657
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
658
|
+
expires = `; expires=${date.toUTCString()}`;
|
|
659
|
+
}
|
|
660
|
+
let cookieString = `${name}=${encodeURIComponent(value)}${expires}; path=${path}`;
|
|
661
|
+
if (domain) cookieString += `; domain=${domain}`;
|
|
662
|
+
if (secure) cookieString += "; secure";
|
|
663
|
+
cookieString += "; SameSite=Lax";
|
|
664
|
+
document.cookie = cookieString;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* 获取 Cookie
|
|
668
|
+
* @param name Cookie 名称
|
|
669
|
+
* @returns Cookie 值,如果不存在则返回 null
|
|
670
|
+
*/
|
|
455
671
|
function getCookie(name) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
672
|
+
const nameEQ = `${name}=`;
|
|
673
|
+
const ca = document.cookie.split(";");
|
|
674
|
+
for (let i = 0; i < ca.length; i++) {
|
|
675
|
+
let c = ca[i];
|
|
676
|
+
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
677
|
+
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
|
678
|
+
}
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* 删除 Cookie
|
|
683
|
+
* @param name Cookie 名称
|
|
684
|
+
* @param path 路径,默认 '/'
|
|
685
|
+
* @param domain 域名
|
|
686
|
+
*/
|
|
469
687
|
function removeCookie(name, path = "/", domain) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
688
|
+
let cookieString = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`;
|
|
689
|
+
if (domain) cookieString += `; domain=${domain}`;
|
|
690
|
+
document.cookie = cookieString;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* 检查 Cookie 是否存在
|
|
694
|
+
* @param name Cookie 名称
|
|
695
|
+
* @returns 是否存在
|
|
696
|
+
*/
|
|
476
697
|
function hasCookie(name) {
|
|
477
|
-
|
|
698
|
+
return getCookie(name) !== null;
|
|
478
699
|
}
|
|
479
700
|
|
|
480
|
-
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/function.ts
|
|
703
|
+
/**
|
|
704
|
+
* 生成唯一标识(时间戳 + 随机数)
|
|
705
|
+
* @param prefix 前缀
|
|
706
|
+
* @returns 唯一标识
|
|
707
|
+
*/
|
|
481
708
|
function generateUniqueId(prefix) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
709
|
+
const timestamp = Date.now().toString(36);
|
|
710
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
711
|
+
return `${prefix || ""}${timestamp}_${random}`;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* 空函数
|
|
715
|
+
*/
|
|
716
|
+
const noop = () => {};
|
|
486
717
|
|
|
487
|
-
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region src/env.ts
|
|
720
|
+
/**
|
|
721
|
+
* 环境变量
|
|
722
|
+
* @param appEnv 环境变量 import.meta.env.APP_ENV
|
|
723
|
+
* @returns 环境变量对象
|
|
724
|
+
*/
|
|
488
725
|
function env(appEnv) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
export {
|
|
501
|
-
addFn,
|
|
502
|
-
computeGoodsNumFn,
|
|
503
|
-
computeGoodsWeightFn,
|
|
504
|
-
computeNoTaxAmount2Fn,
|
|
505
|
-
computeNoTaxAmountFn,
|
|
506
|
-
computeNoTaxPrice2Fn,
|
|
507
|
-
computeNoTaxPriceFn,
|
|
508
|
-
computePrice2Fn,
|
|
509
|
-
computePriceFn,
|
|
510
|
-
computeTaxAmount2Fn,
|
|
511
|
-
computeTaxAmountFn,
|
|
512
|
-
computeTaxFn,
|
|
513
|
-
computeTaxRateFn,
|
|
514
|
-
computeWeightFn,
|
|
515
|
-
divideFn,
|
|
516
|
-
env,
|
|
517
|
-
formatNumber,
|
|
518
|
-
generateUniqueId,
|
|
519
|
-
getCookie,
|
|
520
|
-
hasCookie,
|
|
521
|
-
isArguments,
|
|
522
|
-
isArray,
|
|
523
|
-
isArrayBuffer,
|
|
524
|
-
isArrayIndex,
|
|
525
|
-
isArrayIterator,
|
|
526
|
-
isArrayLike,
|
|
527
|
-
isArrayLikeObject,
|
|
528
|
-
isAsyncFunction,
|
|
529
|
-
isAsyncIterable,
|
|
530
|
-
isBase64,
|
|
531
|
-
isBigInt,
|
|
532
|
-
isBlob,
|
|
533
|
-
isBoolean,
|
|
534
|
-
isBrowser,
|
|
535
|
-
isChineseIDCard,
|
|
536
|
-
isChinesePhone,
|
|
537
|
-
isChinesePostalCode,
|
|
538
|
-
isDate,
|
|
539
|
-
isDateString,
|
|
540
|
-
isDateTimeString,
|
|
541
|
-
isDocument,
|
|
542
|
-
isElement,
|
|
543
|
-
isEmail,
|
|
544
|
-
isEmpty,
|
|
545
|
-
isEqual,
|
|
546
|
-
isError,
|
|
547
|
-
isEvent,
|
|
548
|
-
isFile,
|
|
549
|
-
isFinite,
|
|
550
|
-
isFormData,
|
|
551
|
-
isFunction,
|
|
552
|
-
isGeneratorFunction,
|
|
553
|
-
isHSLColor,
|
|
554
|
-
isHTMLString,
|
|
555
|
-
isHexColor,
|
|
556
|
-
isInteger,
|
|
557
|
-
isIterable,
|
|
558
|
-
isIterator,
|
|
559
|
-
isJSONSerializable,
|
|
560
|
-
isJSONString,
|
|
561
|
-
isLength,
|
|
562
|
-
isMap,
|
|
563
|
-
isMapIterator,
|
|
564
|
-
isMatch,
|
|
565
|
-
isNaN,
|
|
566
|
-
isNative,
|
|
567
|
-
isNil,
|
|
568
|
-
isNull,
|
|
569
|
-
isNumber,
|
|
570
|
-
isObject,
|
|
571
|
-
isObjectLike,
|
|
572
|
-
isPlainObject,
|
|
573
|
-
isPrimitive,
|
|
574
|
-
isPromise,
|
|
575
|
-
isRGBColor,
|
|
576
|
-
isRegExp,
|
|
577
|
-
isRegExpString,
|
|
578
|
-
isSafeInteger,
|
|
579
|
-
isSameOrAfterDay,
|
|
580
|
-
isSameOrBeforeDay,
|
|
581
|
-
isSet,
|
|
582
|
-
isSetIterator,
|
|
583
|
-
isString,
|
|
584
|
-
isStringIterator,
|
|
585
|
-
isSymbol,
|
|
586
|
-
isTimeString,
|
|
587
|
-
isTimezone,
|
|
588
|
-
isTypedArray,
|
|
589
|
-
isURL,
|
|
590
|
-
isURLSearchParams,
|
|
591
|
-
isURLString,
|
|
592
|
-
isUndefined,
|
|
593
|
-
isWeakMap,
|
|
594
|
-
isWeakSet,
|
|
595
|
-
isWindow,
|
|
596
|
-
isXMLString,
|
|
597
|
-
multiplyFn,
|
|
598
|
-
removeCookie,
|
|
599
|
-
setCookie,
|
|
600
|
-
subtractFn,
|
|
601
|
-
sumBy,
|
|
602
|
-
toThousands
|
|
603
|
-
};
|
|
726
|
+
return {
|
|
727
|
+
isDev: appEnv === "development",
|
|
728
|
+
isTest: appEnv === "test",
|
|
729
|
+
isPre: appEnv === "pre-release",
|
|
730
|
+
isProd: appEnv === "production"
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
//#endregion
|
|
735
|
+
export { addFn, computeGoodsNumFn, computeGoodsWeightFn, computeNoTaxAmount2Fn, computeNoTaxAmountFn, computeNoTaxPrice2Fn, computeNoTaxPriceFn, computePrice2Fn, computePriceFn, computeTaxAmount2Fn, computeTaxAmountFn, computeTaxFn, computeTaxRateFn, computeWeightFn, divideFn, env, formatNumber, generateUniqueId, getCookie, hasCookie, isArguments, isArray, isArrayBuffer, isArrayIndex, isArrayIterator, isArrayLike, isArrayLikeObject, isAsyncFunction, isAsyncIterable, isBase64, isBigInt, isBlob, isBoolean, isBrowser, isChineseIDCard, isChinesePhone, isChinesePostalCode, isDate, isDateString, isDateTimeString, isDocument, isElement, isEmail, isEmpty, isEqual, isError, isEvent, isFile, isFinite, isFormData, isFunction, isGeneratorFunction, isHSLColor, isHTMLString, isHexColor, isInteger, isIterable, isIterator, isJSONSerializable, isJSONString, isLength, isMap, isMapIterator, isMatch, isNaN, isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrimitive, isPromise, isRGBColor, isRegExp, isRegExpString, isSafeInteger, isSameOrAfterDay, isSameOrBeforeDay, isSet, isSetIterator, isString, isStringIterator, isSymbol, isTimeString, isTimezone, isTypedArray, isURL, isURLSearchParams, isURLString, isUndefined, isWeakMap, isWeakSet, isWindow, isXMLString, multiplyFn, noop, removeCookie, setCookie, subtractFn, sumBy, toThousands };
|
|
604
736
|
//# sourceMappingURL=index.js.map
|