@antsoo-lib/utils 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +438 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +319 -1
- package/dist/index.d.ts +319 -1
- package/dist/index.js +381 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -45,11 +45,87 @@ __export(index_exports, {
|
|
|
45
45
|
computeTaxRateFn: () => computeTaxRateFn,
|
|
46
46
|
computeWeightFn: () => computeWeightFn,
|
|
47
47
|
divideFn: () => divideFn,
|
|
48
|
+
env: () => env,
|
|
48
49
|
formatNumber: () => formatNumber,
|
|
50
|
+
generateUniqueId: () => generateUniqueId,
|
|
49
51
|
getCookie: () => getCookie,
|
|
50
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,
|
|
51
111
|
isSameOrAfterDay: () => isSameOrAfterDay,
|
|
52
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,
|
|
53
129
|
multiplyFn: () => multiplyFn,
|
|
54
130
|
removeCookie: () => removeCookie,
|
|
55
131
|
setCookie: () => setCookie,
|
|
@@ -69,73 +145,321 @@ function isSameOrBeforeDay(date, day) {
|
|
|
69
145
|
}
|
|
70
146
|
|
|
71
147
|
// src/math.ts
|
|
72
|
-
var import_lodash_es = require("lodash-es");
|
|
73
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);
|
|
154
|
+
};
|
|
155
|
+
var isArray = import_lodash_es.isArray;
|
|
156
|
+
var isArrayBuffer = import_lodash_es.isArrayBuffer;
|
|
157
|
+
function isAsyncFunction(value) {
|
|
158
|
+
return getTag(value) === "[object AsyncFunction]" || typeof value === "function" && value.constructor.name === "AsyncFunction";
|
|
159
|
+
}
|
|
160
|
+
function isBigInt(value) {
|
|
161
|
+
return typeof value === "bigint" || getTag(value) === "[object BigInt]";
|
|
162
|
+
}
|
|
163
|
+
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;
|
|
175
|
+
function isFile(value) {
|
|
176
|
+
return typeof File !== "undefined" && value instanceof File;
|
|
177
|
+
}
|
|
178
|
+
function isFormData(value) {
|
|
179
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
180
|
+
}
|
|
181
|
+
var isFunction = import_lodash_es.isFunction;
|
|
182
|
+
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;
|
|
198
|
+
function isBrowser() {
|
|
199
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
200
|
+
}
|
|
201
|
+
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;
|
|
211
|
+
function isURL(value) {
|
|
212
|
+
return typeof URL !== "undefined" && value instanceof URL;
|
|
213
|
+
}
|
|
214
|
+
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;
|
|
219
|
+
function isWindow(value) {
|
|
220
|
+
return isBrowser() && value === window;
|
|
221
|
+
}
|
|
222
|
+
function isDocument(value) {
|
|
223
|
+
return isBrowser() && value === document;
|
|
224
|
+
}
|
|
225
|
+
function isEvent(value) {
|
|
226
|
+
return isBrowser() && value instanceof Event;
|
|
227
|
+
}
|
|
228
|
+
function isPrimitive(value) {
|
|
229
|
+
return isString(value) || isNumber(value) || isBoolean(value) || isSymbol(value) || isBigInt(value) || isNull(value) || isUndefined(value);
|
|
230
|
+
}
|
|
231
|
+
function isIterable(value) {
|
|
232
|
+
return value != null && typeof value[Symbol.iterator] === "function";
|
|
233
|
+
}
|
|
234
|
+
function isAsyncIterable(value) {
|
|
235
|
+
return value != null && typeof value[Symbol.asyncIterator] === "function";
|
|
236
|
+
}
|
|
237
|
+
function isIterator(value) {
|
|
238
|
+
return value != null && typeof value.next === "function";
|
|
239
|
+
}
|
|
240
|
+
function isArrayIterator(value) {
|
|
241
|
+
return getTag(value) === "[object Array Iterator]";
|
|
242
|
+
}
|
|
243
|
+
function isMapIterator(value) {
|
|
244
|
+
return getTag(value) === "[object Map Iterator]";
|
|
245
|
+
}
|
|
246
|
+
function isSetIterator(value) {
|
|
247
|
+
return getTag(value) === "[object Set Iterator]";
|
|
248
|
+
}
|
|
249
|
+
function isStringIterator(value) {
|
|
250
|
+
return getTag(value) === "[object String Iterator]";
|
|
251
|
+
}
|
|
252
|
+
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
|
+
}
|
|
264
|
+
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);
|
|
270
|
+
}
|
|
271
|
+
function isEmail(value) {
|
|
272
|
+
if (!isString(value)) return false;
|
|
273
|
+
const emailRegex = /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/;
|
|
274
|
+
return emailRegex.test(value);
|
|
275
|
+
}
|
|
276
|
+
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
|
+
}
|
|
285
|
+
function isChinesePhone(value) {
|
|
286
|
+
if (!isString(value)) return false;
|
|
287
|
+
const phoneRegex = /^1[3-9]\d{9}$/;
|
|
288
|
+
return phoneRegex.test(value);
|
|
289
|
+
}
|
|
290
|
+
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
|
+
}
|
|
303
|
+
function isChinesePostalCode(value) {
|
|
304
|
+
if (!isString(value)) return false;
|
|
305
|
+
const postalCodeRegex = /^[1-9]\d{5}$/;
|
|
306
|
+
return postalCodeRegex.test(value);
|
|
307
|
+
}
|
|
308
|
+
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
|
+
}
|
|
317
|
+
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);
|
|
321
|
+
}
|
|
322
|
+
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);
|
|
326
|
+
}
|
|
327
|
+
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);
|
|
331
|
+
}
|
|
332
|
+
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);
|
|
336
|
+
}
|
|
337
|
+
function isDateString(value) {
|
|
338
|
+
if (!isString(value)) return false;
|
|
339
|
+
const date = new Date(value);
|
|
340
|
+
return !isNaN(date.getTime());
|
|
341
|
+
}
|
|
342
|
+
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);
|
|
346
|
+
}
|
|
347
|
+
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());
|
|
351
|
+
}
|
|
352
|
+
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
|
+
}
|
|
361
|
+
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
|
+
}
|
|
370
|
+
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
|
+
}
|
|
383
|
+
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
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/math.ts
|
|
74
398
|
var computeTaxAmountFn = (weight, price) => {
|
|
75
|
-
if (!
|
|
399
|
+
if (!isFinite(price) || !isFinite(weight)) return 0;
|
|
76
400
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
77
401
|
const priceBig = (0, import_mathjs.bignumber)(price);
|
|
78
402
|
const value = Number((0, import_mathjs.multiply)(weightBig, priceBig));
|
|
79
403
|
return value;
|
|
80
404
|
};
|
|
81
405
|
var computeTaxAmount2Fn = (weight, price) => {
|
|
82
|
-
if (!
|
|
406
|
+
if (!isFinite(price) || !isFinite(weight)) return 0;
|
|
83
407
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
84
408
|
const priceBig = (0, import_mathjs.bignumber)(price);
|
|
85
409
|
const value = Number((0, import_mathjs.multiply)(weightBig, priceBig));
|
|
86
410
|
return value;
|
|
87
411
|
};
|
|
88
412
|
var computePriceFn = (taxAmount, weight) => {
|
|
89
|
-
if (!
|
|
413
|
+
if (!isFinite(taxAmount) || !isFinite(weight) || weight <= 0) return 0;
|
|
90
414
|
const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
|
|
91
415
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
92
416
|
const value = Number((0, import_mathjs.divide)(taxAmountBig, weightBig));
|
|
93
417
|
return value;
|
|
94
418
|
};
|
|
95
419
|
var computeWeightFn = (taxAmount, price) => {
|
|
96
|
-
if (!
|
|
420
|
+
if (!isFinite(taxAmount) || !isFinite(price) || price <= 0) return 0;
|
|
97
421
|
const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
|
|
98
422
|
const priceBig = (0, import_mathjs.bignumber)(price);
|
|
99
423
|
const value = Number((0, import_mathjs.divide)(taxAmountBig, priceBig));
|
|
100
424
|
return value;
|
|
101
425
|
};
|
|
102
426
|
var computePrice2Fn = (noTaxPrice, taxRate) => {
|
|
103
|
-
if (!
|
|
427
|
+
if (!isFinite(noTaxPrice) || !isFinite(taxRate)) return 0;
|
|
104
428
|
const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
|
|
105
429
|
const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
|
|
106
430
|
const value = Number((0, import_mathjs.multiply)(noTaxPriceBig, (0, import_mathjs.add)(1, taxRateBig)));
|
|
107
431
|
return value;
|
|
108
432
|
};
|
|
109
433
|
var computeNoTaxPriceFn = (price, taxRate) => {
|
|
110
|
-
if (!
|
|
434
|
+
if (!isFinite(price) || !isFinite(taxRate)) return 0;
|
|
111
435
|
const priceBig = (0, import_mathjs.bignumber)(price);
|
|
112
436
|
const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
|
|
113
437
|
const value = Number((0, import_mathjs.divide)(priceBig, (0, import_mathjs.add)(1, taxRateBig)));
|
|
114
438
|
return value;
|
|
115
439
|
};
|
|
116
440
|
var computeTaxRateFn = (price, noTaxPrice) => {
|
|
117
|
-
if (!
|
|
441
|
+
if (!isFinite(price) || !isFinite(noTaxPrice)) return 0;
|
|
118
442
|
const priceBig = (0, import_mathjs.bignumber)(price);
|
|
119
443
|
const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
|
|
120
444
|
const value = Number((0, import_mathjs.subtract)((0, import_mathjs.divide)(priceBig, noTaxPriceBig), 1));
|
|
121
445
|
return value;
|
|
122
446
|
};
|
|
123
447
|
var computeNoTaxPrice2Fn = (noTaxAmount, weight) => {
|
|
124
|
-
if (!
|
|
448
|
+
if (!isFinite(noTaxAmount) || !isFinite(weight) || weight <= 0) return 0;
|
|
125
449
|
const noTaxAmountBig = (0, import_mathjs.bignumber)(noTaxAmount);
|
|
126
450
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
127
451
|
const value = Number((0, import_mathjs.divide)(noTaxAmountBig, weightBig));
|
|
128
452
|
return value;
|
|
129
453
|
};
|
|
130
454
|
var computeNoTaxAmountFn = (weight, noTaxPrice) => {
|
|
131
|
-
if (!
|
|
455
|
+
if (!isFinite(noTaxPrice) || !isFinite(weight)) return 0;
|
|
132
456
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
133
457
|
const noTaxPriceBig = (0, import_mathjs.bignumber)(noTaxPrice);
|
|
134
458
|
const value = Number((0, import_mathjs.multiply)(weightBig, noTaxPriceBig));
|
|
135
459
|
return value;
|
|
136
460
|
};
|
|
137
461
|
var computeNoTaxAmount2Fn = (taxAmount, taxRate) => {
|
|
138
|
-
if (!
|
|
462
|
+
if (!isFinite(taxAmount) || !isFinite(taxRate)) return 0;
|
|
139
463
|
const taxAmountBig = (0, import_mathjs.bignumber)(taxAmount);
|
|
140
464
|
const taxRateBig = (0, import_mathjs.divide)(taxRate, 100);
|
|
141
465
|
const value = Number((0, import_mathjs.divide)(taxAmountBig, (0, import_mathjs.add)(1, taxRateBig)));
|
|
@@ -148,21 +472,21 @@ var computeTaxFn = (taxAmount, noTaxAmount) => {
|
|
|
148
472
|
return value;
|
|
149
473
|
};
|
|
150
474
|
var computeGoodsNumFn = (weight, weight1) => {
|
|
151
|
-
if (!
|
|
475
|
+
if (!isFinite(weight1) || !isFinite(weight) || weight1 <= 0) return 0;
|
|
152
476
|
const weightBig = (0, import_mathjs.bignumber)(weight);
|
|
153
477
|
const weight1Big = (0, import_mathjs.bignumber)(weight1);
|
|
154
478
|
const value = Number((0, import_mathjs.divide)(weightBig, weight1Big));
|
|
155
479
|
return value;
|
|
156
480
|
};
|
|
157
481
|
var computeGoodsWeightFn = (num, weight1) => {
|
|
158
|
-
if (!
|
|
482
|
+
if (!isFinite(weight1) || !isFinite(num) || weight1 <= 0) return 0;
|
|
159
483
|
const numBig = (0, import_mathjs.bignumber)(num);
|
|
160
484
|
const weight1Big = (0, import_mathjs.bignumber)(weight1);
|
|
161
485
|
const value = Number((0, import_mathjs.multiply)(numBig, weight1Big));
|
|
162
486
|
return value;
|
|
163
487
|
};
|
|
164
488
|
var addFn = (a, b) => {
|
|
165
|
-
if (!
|
|
489
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
166
490
|
const aBig = (0, import_mathjs.bignumber)(a);
|
|
167
491
|
const bBig = (0, import_mathjs.bignumber)(b);
|
|
168
492
|
return Number((0, import_mathjs.add)(aBig, bBig));
|
|
@@ -171,19 +495,19 @@ function sumBy(arr, key) {
|
|
|
171
495
|
return arr.reduce((acc, cur) => addFn(acc, Number(cur[key])), 0);
|
|
172
496
|
}
|
|
173
497
|
var subtractFn = (a, b) => {
|
|
174
|
-
if (!
|
|
498
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
175
499
|
const aBig = (0, import_mathjs.bignumber)(a);
|
|
176
500
|
const bBig = (0, import_mathjs.bignumber)(b);
|
|
177
501
|
return Number((0, import_mathjs.subtract)(aBig, bBig));
|
|
178
502
|
};
|
|
179
503
|
var multiplyFn = (a, b) => {
|
|
180
|
-
if (!
|
|
504
|
+
if (!isFinite(a) || !isFinite(b)) return 0;
|
|
181
505
|
const aBig = (0, import_mathjs.bignumber)(a);
|
|
182
506
|
const bBig = (0, import_mathjs.bignumber)(b);
|
|
183
507
|
return Number((0, import_mathjs.multiply)(aBig, bBig));
|
|
184
508
|
};
|
|
185
509
|
var divideFn = (a, b) => {
|
|
186
|
-
if (!
|
|
510
|
+
if (!isFinite(a) || !isFinite(b) || b === 0) return 0;
|
|
187
511
|
const aBig = (0, import_mathjs.bignumber)(a);
|
|
188
512
|
const bBig = (0, import_mathjs.bignumber)(b);
|
|
189
513
|
return Number((0, import_mathjs.divide)(aBig, bBig));
|
|
@@ -254,6 +578,27 @@ function removeCookie(name, path = "/", domain) {
|
|
|
254
578
|
function hasCookie(name) {
|
|
255
579
|
return getCookie(name) !== null;
|
|
256
580
|
}
|
|
581
|
+
|
|
582
|
+
// src/function.ts
|
|
583
|
+
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
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/env.ts
|
|
590
|
+
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
|
+
}
|
|
257
602
|
// Annotate the CommonJS export names for ESM import in node:
|
|
258
603
|
0 && (module.exports = {
|
|
259
604
|
addFn,
|
|
@@ -271,11 +616,87 @@ function hasCookie(name) {
|
|
|
271
616
|
computeTaxRateFn,
|
|
272
617
|
computeWeightFn,
|
|
273
618
|
divideFn,
|
|
619
|
+
env,
|
|
274
620
|
formatNumber,
|
|
621
|
+
generateUniqueId,
|
|
275
622
|
getCookie,
|
|
276
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,
|
|
277
682
|
isSameOrAfterDay,
|
|
278
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,
|
|
279
700
|
multiplyFn,
|
|
280
701
|
removeCookie,
|
|
281
702
|
setCookie,
|