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