@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 CHANGED
@@ -1,707 +1,867 @@
1
- "use strict";
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
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
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
- // index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- addFn: () => addFn,
34
- computeGoodsNumFn: () => computeGoodsNumFn,
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
- // src/date.ts
139
- var import_dayjs = __toESM(require("dayjs"), 1);
34
+ //#region src/date.ts
35
+ /**
36
+ * 校验日期是否与指定日期相同或晚于指定日期
37
+ * @param date 日期
38
+ * @param day 指定日期
39
+ * @returns 是否相同或晚于指定日期
40
+ */
140
41
  function isSameOrAfterDay(date, day) {
141
- return (0, import_dayjs.default)(date).isSame((0, import_dayjs.default)(day), "day") || (0, import_dayjs.default)(date).isAfter((0, import_dayjs.default)(day), "day");
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
- return (0, import_dayjs.default)(date).isSame((0, import_dayjs.default)(day), "day") || (0, import_dayjs.default)(date).isBefore((0, import_dayjs.default)(day), "day");
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
- // src/math.ts
148
- var import_mathjs = require("mathjs");
149
-
150
- // src/is.ts
151
- var import_lodash_es = require("lodash-es");
152
- var getTag = (value) => {
153
- return Object.prototype.toString.call(value);
54
+ //#endregion
55
+ //#region src/is.ts
56
+ /**
57
+ * 获取值的类型标签
58
+ */
59
+ const getTag = (value) => {
60
+ return Object.prototype.toString.call(value);
154
61
  };
155
- var isArray = import_lodash_es.isArray;
156
- var isArrayBuffer = import_lodash_es.isArrayBuffer;
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
- return getTag(value) === "[object AsyncFunction]" || typeof value === "function" && value.constructor.name === "AsyncFunction";
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
- return typeof value === "bigint" || getTag(value) === "[object BigInt]";
80
+ return typeof value === "bigint" || getTag(value) === "[object BigInt]";
162
81
  }
82
+ /**
83
+ * 检查是否为 Blob 对象(浏览器环境)
84
+ */
163
85
  function isBlob(value) {
164
- return typeof Blob !== "undefined" && value instanceof Blob;
165
- }
166
- var isBoolean = import_lodash_es.isBoolean;
167
- var isArrayLike = import_lodash_es.isArrayLike;
168
- var isArrayLikeObject = import_lodash_es.isArrayLikeObject;
169
- var isArguments = import_lodash_es.isArguments;
170
- var isDate = import_lodash_es.isDate;
171
- var isElement = import_lodash_es.isElement;
172
- var isEmpty = import_lodash_es.isEmpty;
173
- var isEqual = import_lodash_es.isEqual;
174
- var isError = import_lodash_es.isError;
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
- return typeof File !== "undefined" && value instanceof File;
128
+ return typeof File !== "undefined" && value instanceof File;
177
129
  }
130
+ /**
131
+ * 检查是否为 FormData 对象(浏览器环境)
132
+ */
178
133
  function isFormData(value) {
179
- return typeof FormData !== "undefined" && value instanceof FormData;
180
- }
181
- var isFunction = import_lodash_es.isFunction;
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
- return getTag(value) === "[object GeneratorFunction]" || typeof value === "function" && value.constructor.name === "GeneratorFunction";
184
- }
185
- var isInteger = import_lodash_es.isInteger;
186
- var isFinite = import_lodash_es.isFinite;
187
- var isLength = import_lodash_es.isLength;
188
- var isMap = import_lodash_es.isMap;
189
- var isNaN = import_lodash_es.isNaN;
190
- var isNil = import_lodash_es.isNil;
191
- var isNull = import_lodash_es.isNull;
192
- var isNumber = import_lodash_es.isNumber;
193
- var isObject = import_lodash_es.isObject;
194
- var isObjectLike = import_lodash_es.isObjectLike;
195
- var isPlainObject = import_lodash_es.isPlainObject;
196
- var isMatch = import_lodash_es.isMatch;
197
- var isNative = import_lodash_es.isNative;
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
- return typeof window !== "undefined" && typeof document !== "undefined";
202
+ return typeof window !== "undefined" && typeof document !== "undefined";
200
203
  }
204
+ /**
205
+ * 检查是否为 Promise
206
+ */
201
207
  function isPromise(value) {
202
- return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
203
- }
204
- var isRegExp = import_lodash_es.isRegExp;
205
- var isSafeInteger = import_lodash_es.isSafeInteger;
206
- var isSet = import_lodash_es.isSet;
207
- var isString = import_lodash_es.isString;
208
- var isSymbol = import_lodash_es.isSymbol;
209
- var isTypedArray = import_lodash_es.isTypedArray;
210
- var isUndefined = import_lodash_es.isUndefined;
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
- return typeof URL !== "undefined" && value instanceof URL;
242
+ return typeof URL !== "undefined" && value instanceof URL;
213
243
  }
244
+ /**
245
+ * 检查是否为 URLSearchParams 对象(浏览器环境)
246
+ */
214
247
  function isURLSearchParams(value) {
215
- return typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams;
216
- }
217
- var isWeakMap = import_lodash_es.isWeakMap;
218
- var isWeakSet = import_lodash_es.isWeakSet;
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
- return isBrowser() && value === window;
262
+ return isBrowser() && value === window;
221
263
  }
264
+ /**
265
+ * 检查是否为 Document 对象(浏览器环境)
266
+ */
222
267
  function isDocument(value) {
223
- return isBrowser() && value === document;
268
+ return isBrowser() && value === document;
224
269
  }
270
+ /**
271
+ * 检查是否为 Event 对象(浏览器环境)
272
+ */
225
273
  function isEvent(value) {
226
- return isBrowser() && value instanceof Event;
274
+ return isBrowser() && value instanceof Event;
227
275
  }
276
+ /**
277
+ * 检查是否为 Primitive 类型
278
+ */
228
279
  function isPrimitive(value) {
229
- return isString(value) || isNumber(value) || isBoolean(value) || isSymbol(value) || isBigInt(value) || isNull(value) || isUndefined(value);
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
- return value != null && typeof value[Symbol.iterator] === "function";
286
+ return value != null && typeof value[Symbol.iterator] === "function";
233
287
  }
288
+ /**
289
+ * 检查是否为 AsyncIterable 对象
290
+ */
234
291
  function isAsyncIterable(value) {
235
- return value != null && typeof value[Symbol.asyncIterator] === "function";
292
+ return value != null && typeof value[Symbol.asyncIterator] === "function";
236
293
  }
294
+ /**
295
+ * 检查是否为 Iterator 对象
296
+ */
237
297
  function isIterator(value) {
238
- return value != null && typeof value.next === "function";
298
+ return value != null && typeof value.next === "function";
239
299
  }
300
+ /**
301
+ * 检查是否为 Array Iterator
302
+ */
240
303
  function isArrayIterator(value) {
241
- return getTag(value) === "[object Array Iterator]";
304
+ return getTag(value) === "[object Array Iterator]";
242
305
  }
306
+ /**
307
+ * 检查是否为 Map Iterator
308
+ */
243
309
  function isMapIterator(value) {
244
- return getTag(value) === "[object Map Iterator]";
310
+ return getTag(value) === "[object Map Iterator]";
245
311
  }
312
+ /**
313
+ * 检查是否为 Set Iterator
314
+ */
246
315
  function isSetIterator(value) {
247
- return getTag(value) === "[object Set Iterator]";
316
+ return getTag(value) === "[object Set Iterator]";
248
317
  }
318
+ /**
319
+ * 检查是否为 String Iterator
320
+ */
249
321
  function isStringIterator(value) {
250
- return getTag(value) === "[object String Iterator]";
322
+ return getTag(value) === "[object String Iterator]";
251
323
  }
324
+ /**
325
+ * 检查是否为可序列化的 JSON 值
326
+ */
252
327
  function isJSONSerializable(value) {
253
- if (isPrimitive(value)) {
254
- return !isUndefined(value);
255
- }
256
- if (isArray(value)) {
257
- return value.every(isJSONSerializable);
258
- }
259
- if (isPlainObject(value)) {
260
- return Object.values(value).every(isJSONSerializable);
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
- if (!isNumber(value) && !isString(value)) {
266
- return false;
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
- if (!isString(value)) return false;
273
- const emailRegex = /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/;
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
- if (!isString(value)) return false;
278
- try {
279
- const _ = new URL(value);
280
- return true;
281
- } catch {
282
- return false;
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
- if (!isString(value)) return false;
287
- const phoneRegex = /^1[3-9]\d{9}$/;
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
- if (!isString(value)) return false;
292
- const idCardRegex = /^[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;
293
- if (!idCardRegex.test(value)) return false;
294
- const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
295
- const checkCodes = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
296
- let sum = 0;
297
- for (let i = 0; i < 17; i++) {
298
- sum += Number.parseInt(value[i]) * weights[i];
299
- }
300
- const checkCode = checkCodes[sum % 11];
301
- return checkCode === value[17].toUpperCase();
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
- if (!isString(value)) return false;
305
- const postalCodeRegex = /^[1-9]\d{5}$/;
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
- if (!isString(value)) return false;
310
- try {
311
- JSON.parse(value);
312
- return true;
313
- } catch {
314
- return false;
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
- if (!isString(value)) return false;
319
- const base64Regex = /^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$/i;
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
- if (!isString(value)) return false;
324
- const hexColorRegex = /^#?[a-f0-9]{6}$|^#?[a-f0-9]{3}$/i;
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
- if (!isString(value)) return false;
329
- const rgbColorRegex = /^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$/;
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
- if (!isString(value)) return false;
334
- const hslColorRegex = /^hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\)$/;
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
- if (!isString(value)) return false;
339
- const date = new Date(value);
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
- if (!isString(value)) return false;
344
- const timeRegex = /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/;
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
- if (!isString(value)) return false;
349
- const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$/;
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
- if (!isString(value)) return false;
354
- try {
355
- Intl.DateTimeFormat(void 0, { timeZone: value });
356
- return true;
357
- } catch {
358
- return false;
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
- if (!isString(value)) return false;
363
- try {
364
- const _ = new RegExp(value);
365
- return true;
366
- } catch {
367
- return false;
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
- if (!isString(value)) return false;
372
- try {
373
- if (isBrowser()) {
374
- const parser = new DOMParser();
375
- const xmlDoc = parser.parseFromString(value, "application/xml");
376
- return xmlDoc.getElementsByTagName("parsererror").length === 0;
377
- }
378
- return false;
379
- } catch {
380
- return false;
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
- if (!isString(value)) return false;
385
- try {
386
- if (isBrowser()) {
387
- const parser = new DOMParser();
388
- const htmlDoc = parser.parseFromString(value, "text/html");
389
- return htmlDoc.body.children.length > 0;
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
- // src/math.ts
398
- var computeTaxAmountFn = (weight, price) => {
399
- if (!isFinite(price) || !isFinite(weight)) return 0;
400
- const weightBig = (0, import_mathjs.bignumber)(weight);
401
- const priceBig = (0, import_mathjs.bignumber)(price);
402
- const value = Number((0, import_mathjs.multiply)(weightBig, priceBig));
403
- return value;
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
- var computeTaxAmount2Fn = (weight, price) => {
406
- if (!isFinite(price) || !isFinite(weight)) return 0;
407
- const weightBig = (0, import_mathjs.bignumber)(weight);
408
- const priceBig = (0, import_mathjs.bignumber)(price);
409
- const value = Number((0, import_mathjs.multiply)(weightBig, priceBig));
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
- var computePriceFn = (taxAmount, weight) => {
413
- if (!isFinite(taxAmount) || !isFinite(weight) || weight <= 0) return 0;
414
- const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
415
- const weightBig = (0, import_mathjs.bignumber)(weight);
416
- const value = Number((0, import_mathjs.divide)(taxAmountBig, weightBig));
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
- var computeWeightFn = (taxAmount, price) => {
420
- if (!isFinite(taxAmount) || !isFinite(price) || price <= 0) return 0;
421
- const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
422
- const priceBig = (0, import_mathjs.bignumber)(price);
423
- const value = Number((0, import_mathjs.divide)(taxAmountBig, priceBig));
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
- var computePrice2Fn = (noTaxPrice, taxRate) => {
427
- if (!isFinite(noTaxPrice) || !isFinite(taxRate)) return 0;
428
- const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
429
- const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
430
- const value = Number((0, import_mathjs.multiply)(noTaxPriceBig, (0, import_mathjs.add)(1, taxRateBig)));
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
- var computeNoTaxPriceFn = (price, taxRate) => {
434
- if (!isFinite(price) || !isFinite(taxRate)) return 0;
435
- const priceBig = (0, import_mathjs.bignumber)(price);
436
- const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
437
- const value = Number((0, import_mathjs.divide)(priceBig, (0, import_mathjs.add)(1, taxRateBig)));
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
- var computeTaxRateFn = (price, noTaxPrice) => {
441
- if (!isFinite(price) || !isFinite(noTaxPrice)) return 0;
442
- const priceBig = (0, import_mathjs.bignumber)(price);
443
- const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
444
- const value = Number((0, import_mathjs.subtract)((0, import_mathjs.divide)(priceBig, noTaxPriceBig), 1));
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
- var computeNoTaxPrice2Fn = (noTaxAmount, weight) => {
448
- if (!isFinite(noTaxAmount) || !isFinite(weight) || weight <= 0) return 0;
449
- const noTaxAmountBig = (0, import_mathjs.bignumber)(noTaxAmount);
450
- const weightBig = (0, import_mathjs.bignumber)(weight);
451
- const value = Number((0, import_mathjs.divide)(noTaxAmountBig, weightBig));
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
- var computeNoTaxAmountFn = (weight, noTaxPrice) => {
455
- if (!isFinite(noTaxPrice) || !isFinite(weight)) return 0;
456
- const weightBig = (0, import_mathjs.bignumber)(weight);
457
- const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
458
- const value = Number((0, import_mathjs.multiply)(weightBig, noTaxPriceBig));
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
- var computeNoTaxAmount2Fn = (taxAmount, taxRate) => {
462
- if (!isFinite(taxAmount) || !isFinite(taxRate)) return 0;
463
- const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
464
- const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
465
- const value = Number((0, import_mathjs.divide)(taxAmountBig, (0, import_mathjs.add)(1, taxRateBig)));
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
- var computeTaxFn = (taxAmount, noTaxAmount) => {
469
- const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount || 0);
470
- const noTaxAmountBig = (0, import_mathjs.bignumber)(noTaxAmount || 0);
471
- const value = Number((0, import_mathjs.subtract)(taxAmountBig, noTaxAmountBig));
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
- var computeGoodsNumFn = (weight, weight1) => {
475
- if (!isFinite(weight1) || !isFinite(weight) || weight1 <= 0) return 0;
476
- const weightBig = (0, import_mathjs.bignumber)(weight);
477
- const weight1Big = (0, import_mathjs.bignumber)(weight1);
478
- const value = Number((0, import_mathjs.divide)(weightBig, weight1Big));
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
- var computeGoodsWeightFn = (num, weight1) => {
482
- if (!isFinite(weight1) || !isFinite(num) || weight1 <= 0) return 0;
483
- const numBig = (0, import_mathjs.bignumber)(num);
484
- const weight1Big = (0, import_mathjs.bignumber)(weight1);
485
- const value = Number((0, import_mathjs.multiply)(numBig, weight1Big));
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
- var addFn = (a, b) => {
489
- if (!isFinite(a) || !isFinite(b)) return 0;
490
- const aBig = (0, import_mathjs.bignumber)(a);
491
- const bBig = (0, import_mathjs.bignumber)(b);
492
- return Number((0, import_mathjs.add)(aBig, bBig));
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
- return arr.reduce((acc, cur) => addFn(acc, Number(cur[key])), 0);
618
+ return arr.reduce((acc, cur) => addFn(acc, Number(cur[key])), 0);
496
619
  }
497
- var subtractFn = (a, b) => {
498
- if (!isFinite(a) || !isFinite(b)) return 0;
499
- const aBig = (0, import_mathjs.bignumber)(a);
500
- const bBig = (0, import_mathjs.bignumber)(b);
501
- return Number((0, import_mathjs.subtract)(aBig, bBig));
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
- var multiplyFn = (a, b) => {
504
- if (!isFinite(a) || !isFinite(b)) return 0;
505
- const aBig = (0, import_mathjs.bignumber)(a);
506
- const bBig = (0, import_mathjs.bignumber)(b);
507
- return Number((0, import_mathjs.multiply)(aBig, bBig));
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
- var divideFn = (a, b) => {
510
- if (!isFinite(a) || !isFinite(b) || b === 0) return 0;
511
- const aBig = (0, import_mathjs.bignumber)(a);
512
- const bBig = (0, import_mathjs.bignumber)(b);
513
- return Number((0, import_mathjs.divide)(aBig, bBig));
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
- // src/format.ts
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
- if (number === null || number === void 0 || number === "") return "";
519
- let num = Number.parseFloat(String(number));
520
- if (Number.isNaN(num)) return "";
521
- num = Math.round(num * 10 ** decimals) / 10 ** decimals;
522
- const numStr = num.toFixed(decimals);
523
- const parts = numStr.split(".");
524
- if (thousands_sep) {
525
- const re = /(-?\d+)(\d{3})/;
526
- while (re.test(parts[0])) {
527
- parts[0] = parts[0].replace(re, `$1${thousands_sep}$2`);
528
- }
529
- }
530
- return parts.join(".");
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
- if (number === null || number === void 0 || number === "") return "";
534
- const n = Number(number);
535
- if (Number.isNaN(n)) return "";
536
- return n.toLocaleString("en-US");
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
- // src/cookie.ts
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
- let expires = "";
542
- if (days) {
543
- const date = /* @__PURE__ */ new Date();
544
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
545
- expires = `; expires=${date.toUTCString()}`;
546
- }
547
- let cookieString = `${name}=${encodeURIComponent(value)}${expires}; path=${path}`;
548
- if (domain) {
549
- cookieString += `; domain=${domain}`;
550
- }
551
- if (secure) {
552
- cookieString += "; secure";
553
- }
554
- cookieString += "; SameSite=Lax";
555
- document.cookie = cookieString;
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
- const nameEQ = `${name}=`;
559
- const ca = document.cookie.split(";");
560
- for (let i = 0; i < ca.length; i++) {
561
- let c = ca[i];
562
- while (c.charAt(0) === " ") {
563
- c = c.substring(1, c.length);
564
- }
565
- if (c.indexOf(nameEQ) === 0) {
566
- return decodeURIComponent(c.substring(nameEQ.length, c.length));
567
- }
568
- }
569
- return null;
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
- let cookieString = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`;
573
- if (domain) {
574
- cookieString += `; domain=${domain}`;
575
- }
576
- document.cookie = cookieString;
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
- return getCookie(name) !== null;
727
+ return getCookie(name) !== null;
580
728
  }
581
729
 
582
- // src/function.ts
730
+ //#endregion
731
+ //#region src/function.ts
732
+ /**
733
+ * 生成唯一标识(时间戳 + 随机数)
734
+ * @param prefix 前缀
735
+ * @returns 唯一标识
736
+ */
583
737
  function generateUniqueId(prefix) {
584
- const timestamp = Date.now().toString(36);
585
- const random = Math.random().toString(36).substring(2, 8);
586
- return `${prefix || ""}${timestamp}_${random}`;
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
- // src/env.ts
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
- const isDev = appEnv === "development";
592
- const isTest = appEnv === "test";
593
- const isPre = appEnv === "pre-release";
594
- const isProd = appEnv === "production";
595
- return {
596
- isDev,
597
- isTest,
598
- isPre,
599
- isProd
600
- };
601
- }
602
- // Annotate the CommonJS export names for ESM import in node:
603
- 0 && (module.exports = {
604
- addFn,
605
- computeGoodsNumFn,
606
- computeGoodsWeightFn,
607
- computeNoTaxAmount2Fn,
608
- computeNoTaxAmountFn,
609
- computeNoTaxPrice2Fn,
610
- computeNoTaxPriceFn,
611
- computePrice2Fn,
612
- computePriceFn,
613
- computeTaxAmount2Fn,
614
- computeTaxAmountFn,
615
- computeTaxFn,
616
- computeTaxRateFn,
617
- computeWeightFn,
618
- divideFn,
619
- env,
620
- formatNumber,
621
- generateUniqueId,
622
- getCookie,
623
- hasCookie,
624
- isArguments,
625
- isArray,
626
- isArrayBuffer,
627
- isArrayIndex,
628
- isArrayIterator,
629
- isArrayLike,
630
- isArrayLikeObject,
631
- isAsyncFunction,
632
- isAsyncIterable,
633
- isBase64,
634
- isBigInt,
635
- isBlob,
636
- isBoolean,
637
- isBrowser,
638
- isChineseIDCard,
639
- isChinesePhone,
640
- isChinesePostalCode,
641
- isDate,
642
- isDateString,
643
- isDateTimeString,
644
- isDocument,
645
- isElement,
646
- isEmail,
647
- isEmpty,
648
- isEqual,
649
- isError,
650
- isEvent,
651
- isFile,
652
- isFinite,
653
- isFormData,
654
- isFunction,
655
- isGeneratorFunction,
656
- isHSLColor,
657
- isHTMLString,
658
- isHexColor,
659
- isInteger,
660
- isIterable,
661
- isIterator,
662
- isJSONSerializable,
663
- isJSONString,
664
- isLength,
665
- isMap,
666
- isMapIterator,
667
- isMatch,
668
- isNaN,
669
- isNative,
670
- isNil,
671
- isNull,
672
- isNumber,
673
- isObject,
674
- isObjectLike,
675
- isPlainObject,
676
- isPrimitive,
677
- isPromise,
678
- isRGBColor,
679
- isRegExp,
680
- isRegExpString,
681
- isSafeInteger,
682
- isSameOrAfterDay,
683
- isSameOrBeforeDay,
684
- isSet,
685
- isSetIterator,
686
- isString,
687
- isStringIterator,
688
- isSymbol,
689
- isTimeString,
690
- isTimezone,
691
- isTypedArray,
692
- isURL,
693
- isURLSearchParams,
694
- isURLString,
695
- isUndefined,
696
- isWeakMap,
697
- isWeakSet,
698
- isWindow,
699
- isXMLString,
700
- multiplyFn,
701
- removeCookie,
702
- setCookie,
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