react-util-tools 1.0.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/README.md +254 -0
- package/dist/index.cjs +943 -0
- package/dist/index.d.cts +154 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +852 -0
- package/package.json +50 -0
- package/src/address/README.md +196 -0
- package/src/address/index.ts +41 -0
- package/src/date/README.md +539 -0
- package/src/date/index.ts +330 -0
- package/src/date/utc/README.md +779 -0
- package/src/date/utc/index.ts +374 -0
- package/src/decimal/README.md +425 -0
- package/src/decimal/index.ts +9 -0
- package/src/decimal/utils/README.md +474 -0
- package/src/decimal/utils/index.ts +244 -0
- package/src/device/README.md +441 -0
- package/src/device/index.ts +214 -0
- package/src/format/README.md +335 -0
- package/src/format/index.ts +189 -0
- package/src/index.ts +107 -0
- package/src/throttle/README.md +152 -0
- package/src/throttle/index.ts +83 -0
- package/tsconfig.json +28 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
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
|
+
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;
|
|
19
|
+
};
|
|
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);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Decimal: () => import_decimal.default,
|
|
34
|
+
abs: () => abs,
|
|
35
|
+
add: () => add,
|
|
36
|
+
addDaysToDate: () => addDaysToDate,
|
|
37
|
+
addDaysUTC: () => addDaysUTC,
|
|
38
|
+
addMonthsToDate: () => addMonthsToDate,
|
|
39
|
+
addMonthsUTC: () => addMonthsUTC,
|
|
40
|
+
ceil: () => ceil,
|
|
41
|
+
debounce: () => debounceFn,
|
|
42
|
+
divide: () => divide,
|
|
43
|
+
equals: () => equals,
|
|
44
|
+
floor: () => floor,
|
|
45
|
+
formatDate: () => formatDate,
|
|
46
|
+
formatDateOnly: () => formatDateOnly,
|
|
47
|
+
formatMoney: () => formatMoney,
|
|
48
|
+
formatMoneyToChinese: () => formatMoneyToChinese,
|
|
49
|
+
formatNumber: () => formatNumber,
|
|
50
|
+
formatPercent: () => formatPercent,
|
|
51
|
+
formatRelativeTime: () => formatRelativeTime,
|
|
52
|
+
formatTimeOnly: () => formatTimeOnly,
|
|
53
|
+
formatUTC: () => formatUTC,
|
|
54
|
+
formatUTCDateOnly: () => formatUTCDateOnly,
|
|
55
|
+
formatUTCTimeOnly: () => formatUTCTimeOnly,
|
|
56
|
+
fromUTC: () => fromUTC,
|
|
57
|
+
getAllQueryParams: () => getAllQueryParams,
|
|
58
|
+
getBrowser: () => getBrowser,
|
|
59
|
+
getBrowserEngine: () => getBrowserEngine,
|
|
60
|
+
getBrowserVersion: () => getBrowserVersion,
|
|
61
|
+
getDaysDiff: () => getDaysDiff,
|
|
62
|
+
getDeviceInfo: () => getDeviceInfo,
|
|
63
|
+
getDevicePixelRatio: () => getDevicePixelRatio,
|
|
64
|
+
getDeviceType: () => getDeviceType,
|
|
65
|
+
getEndOfDay: () => getEndOfDay,
|
|
66
|
+
getEndOfMonth: () => getEndOfMonth,
|
|
67
|
+
getEndOfWeek: () => getEndOfWeek,
|
|
68
|
+
getEndOfYear: () => getEndOfYear,
|
|
69
|
+
getHoursDiff: () => getHoursDiff,
|
|
70
|
+
getMinutesDiff: () => getMinutesDiff,
|
|
71
|
+
getOS: () => getOS,
|
|
72
|
+
getQueryParam: () => getQueryParam,
|
|
73
|
+
getQueryParamAll: () => getQueryParamAll,
|
|
74
|
+
getScreenResolution: () => getScreenResolution,
|
|
75
|
+
getStartOfDay: () => getStartOfDay,
|
|
76
|
+
getStartOfMonth: () => getStartOfMonth,
|
|
77
|
+
getStartOfWeek: () => getStartOfWeek,
|
|
78
|
+
getStartOfYear: () => getStartOfYear,
|
|
79
|
+
getTimestamp: () => getTimestamp,
|
|
80
|
+
getTimestampInSeconds: () => getTimestampInSeconds,
|
|
81
|
+
getTimezoneOffset: () => getTimezoneOffset,
|
|
82
|
+
getTimezoneOffsetHours: () => getTimezoneOffsetHours,
|
|
83
|
+
getUTCAllWeeksInYear: () => getUTCAllWeeksInYear,
|
|
84
|
+
getUTCDaysDiff: () => getUTCDaysDiff,
|
|
85
|
+
getUTCEndOfDay: () => getUTCEndOfDay,
|
|
86
|
+
getUTCEndOfMonth: () => getUTCEndOfMonth,
|
|
87
|
+
getUTCHoursDiff: () => getUTCHoursDiff,
|
|
88
|
+
getUTCMinutesDiff: () => getUTCMinutesDiff,
|
|
89
|
+
getUTCNow: () => getUTCNow,
|
|
90
|
+
getUTCStartOfDay: () => getUTCStartOfDay,
|
|
91
|
+
getUTCStartOfMonth: () => getUTCStartOfMonth,
|
|
92
|
+
getUTCTimestamp: () => getUTCTimestamp,
|
|
93
|
+
getUTCTimestampInSeconds: () => getUTCTimestampInSeconds,
|
|
94
|
+
getUTCWeekEnd: () => getUTCWeekEnd,
|
|
95
|
+
getUTCWeekNumber: () => getUTCWeekNumber,
|
|
96
|
+
getUTCWeekStart: () => getUTCWeekStart,
|
|
97
|
+
getUTCWeeksInYear: () => getUTCWeeksInYear,
|
|
98
|
+
getUTCYearEnd: () => getUTCYearEnd,
|
|
99
|
+
getUTCYearEndTimestamp: () => getUTCYearEndTimestamp,
|
|
100
|
+
getUTCYearStart: () => getUTCYearStart,
|
|
101
|
+
getUTCYearStartTimestamp: () => getUTCYearStartTimestamp,
|
|
102
|
+
getViewportSize: () => getViewportSize,
|
|
103
|
+
greaterThan: () => greaterThan,
|
|
104
|
+
greaterThanOrEqual: () => greaterThanOrEqual,
|
|
105
|
+
isAfterDate: () => isAfterDate,
|
|
106
|
+
isAndroid: () => isAndroid,
|
|
107
|
+
isBeforeDate: () => isBeforeDate,
|
|
108
|
+
isDesktop: () => isDesktop,
|
|
109
|
+
isIOS: () => isIOS,
|
|
110
|
+
isMobile: () => isMobile,
|
|
111
|
+
isSameDayDate: () => isSameDayDate,
|
|
112
|
+
isTablet: () => isTablet,
|
|
113
|
+
isTouchDevice: () => isTouchDevice,
|
|
114
|
+
isValidDate: () => isValidDate,
|
|
115
|
+
isWeChat: () => isWeChat,
|
|
116
|
+
lessThan: () => lessThan,
|
|
117
|
+
lessThanOrEqual: () => lessThanOrEqual,
|
|
118
|
+
multiply: () => multiply,
|
|
119
|
+
negate: () => negate,
|
|
120
|
+
parseDate: () => parseDate,
|
|
121
|
+
parseMoney: () => parseMoney,
|
|
122
|
+
round: () => round,
|
|
123
|
+
subDaysFromDate: () => subDaysFromDate,
|
|
124
|
+
subDaysUTC: () => subDaysUTC,
|
|
125
|
+
subMonthsFromDate: () => subMonthsFromDate,
|
|
126
|
+
subMonthsUTC: () => subMonthsUTC,
|
|
127
|
+
subtract: () => subtract,
|
|
128
|
+
throttle: () => throttleFn,
|
|
129
|
+
toISOString: () => toISOString,
|
|
130
|
+
toUTC: () => toUTC
|
|
131
|
+
});
|
|
132
|
+
module.exports = __toCommonJS(index_exports);
|
|
133
|
+
|
|
134
|
+
// src/throttle/index.ts
|
|
135
|
+
function throttleFn(fn, wait = 3e3, options = {}) {
|
|
136
|
+
let timeout = null;
|
|
137
|
+
let lastCallTime = null;
|
|
138
|
+
let lastArgs = null;
|
|
139
|
+
const { leading = true, trailing = true } = options;
|
|
140
|
+
const invoke = (time) => {
|
|
141
|
+
fn(...lastArgs);
|
|
142
|
+
lastCallTime = time;
|
|
143
|
+
lastArgs = null;
|
|
144
|
+
};
|
|
145
|
+
return function(...args) {
|
|
146
|
+
const now = Date.now();
|
|
147
|
+
if (lastCallTime === null && !leading) {
|
|
148
|
+
lastCallTime = now;
|
|
149
|
+
}
|
|
150
|
+
const remaining = wait - (now - (lastCallTime ?? 0));
|
|
151
|
+
lastArgs = args;
|
|
152
|
+
if (remaining <= 0) {
|
|
153
|
+
if (timeout) {
|
|
154
|
+
clearTimeout(timeout);
|
|
155
|
+
timeout = null;
|
|
156
|
+
}
|
|
157
|
+
invoke(now);
|
|
158
|
+
} else if (!timeout && trailing) {
|
|
159
|
+
timeout = setTimeout(() => {
|
|
160
|
+
timeout = null;
|
|
161
|
+
if (trailing && lastArgs) {
|
|
162
|
+
invoke(Date.now());
|
|
163
|
+
}
|
|
164
|
+
}, remaining);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function debounceFn(fn, wait = 500, immediate = false) {
|
|
169
|
+
let timeout = null;
|
|
170
|
+
return function(...args) {
|
|
171
|
+
const callNow = immediate && !timeout;
|
|
172
|
+
if (timeout) {
|
|
173
|
+
clearTimeout(timeout);
|
|
174
|
+
}
|
|
175
|
+
timeout = setTimeout(() => {
|
|
176
|
+
timeout = null;
|
|
177
|
+
if (!immediate) {
|
|
178
|
+
fn(...args);
|
|
179
|
+
}
|
|
180
|
+
}, wait);
|
|
181
|
+
if (callNow) {
|
|
182
|
+
fn(...args);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/address/index.ts
|
|
188
|
+
function getQueryParam(key, url) {
|
|
189
|
+
const searchParams = new URLSearchParams(
|
|
190
|
+
url ? new URL(url).search : window.location.search
|
|
191
|
+
);
|
|
192
|
+
return searchParams.get(key);
|
|
193
|
+
}
|
|
194
|
+
function getAllQueryParams(url) {
|
|
195
|
+
const searchParams = new URLSearchParams(
|
|
196
|
+
url ? new URL(url).search : window.location.search
|
|
197
|
+
);
|
|
198
|
+
const params = {};
|
|
199
|
+
searchParams.forEach((value, key) => {
|
|
200
|
+
params[key] = value;
|
|
201
|
+
});
|
|
202
|
+
return params;
|
|
203
|
+
}
|
|
204
|
+
function getQueryParamAll(key, url) {
|
|
205
|
+
const searchParams = new URLSearchParams(
|
|
206
|
+
url ? new URL(url).search : window.location.search
|
|
207
|
+
);
|
|
208
|
+
return searchParams.getAll(key);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/device/index.ts
|
|
212
|
+
function getUserAgent() {
|
|
213
|
+
return navigator.userAgent.toLowerCase();
|
|
214
|
+
}
|
|
215
|
+
function getOS() {
|
|
216
|
+
const ua = getUserAgent();
|
|
217
|
+
if (ua.includes("win")) return "Windows";
|
|
218
|
+
if (ua.includes("mac")) return "MacOS";
|
|
219
|
+
if (ua.includes("linux")) return "Linux";
|
|
220
|
+
if (ua.includes("android")) return "Android";
|
|
221
|
+
if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) return "iOS";
|
|
222
|
+
return "Unknown";
|
|
223
|
+
}
|
|
224
|
+
function getBrowser() {
|
|
225
|
+
const ua = getUserAgent();
|
|
226
|
+
if (ua.includes("edg")) return "Edge";
|
|
227
|
+
if (ua.includes("chrome")) return "Chrome";
|
|
228
|
+
if (ua.includes("safari") && !ua.includes("chrome")) return "Safari";
|
|
229
|
+
if (ua.includes("firefox")) return "Firefox";
|
|
230
|
+
if (ua.includes("opera") || ua.includes("opr")) return "Opera";
|
|
231
|
+
if (ua.includes("trident") || ua.includes("msie")) return "IE";
|
|
232
|
+
return "Unknown";
|
|
233
|
+
}
|
|
234
|
+
function getBrowserEngine() {
|
|
235
|
+
const ua = getUserAgent();
|
|
236
|
+
if (ua.includes("trident")) return "Trident";
|
|
237
|
+
if (ua.includes("gecko") && !ua.includes("webkit")) return "Gecko";
|
|
238
|
+
if (ua.includes("webkit")) return "WebKit";
|
|
239
|
+
if (ua.includes("presto")) return "Presto";
|
|
240
|
+
return "Unknown";
|
|
241
|
+
}
|
|
242
|
+
function isMobile() {
|
|
243
|
+
const ua = getUserAgent();
|
|
244
|
+
return /mobile|android|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ua);
|
|
245
|
+
}
|
|
246
|
+
function isTablet() {
|
|
247
|
+
const ua = getUserAgent();
|
|
248
|
+
return /ipad|android(?!.*mobile)|tablet/i.test(ua);
|
|
249
|
+
}
|
|
250
|
+
function isDesktop() {
|
|
251
|
+
return !isMobile() && !isTablet();
|
|
252
|
+
}
|
|
253
|
+
function getDeviceType() {
|
|
254
|
+
if (isMobile()) return "mobile";
|
|
255
|
+
if (isTablet()) return "tablet";
|
|
256
|
+
return "desktop";
|
|
257
|
+
}
|
|
258
|
+
function isWeChat() {
|
|
259
|
+
const ua = getUserAgent();
|
|
260
|
+
return /micromessenger/i.test(ua);
|
|
261
|
+
}
|
|
262
|
+
function isIOS() {
|
|
263
|
+
const ua = getUserAgent();
|
|
264
|
+
return /iphone|ipad|ipod/i.test(ua);
|
|
265
|
+
}
|
|
266
|
+
function isAndroid() {
|
|
267
|
+
const ua = getUserAgent();
|
|
268
|
+
return /android/i.test(ua);
|
|
269
|
+
}
|
|
270
|
+
function getBrowserVersion() {
|
|
271
|
+
const ua = navigator.userAgent;
|
|
272
|
+
const browser = getBrowser();
|
|
273
|
+
let match = null;
|
|
274
|
+
switch (browser) {
|
|
275
|
+
case "Chrome":
|
|
276
|
+
match = ua.match(/chrome\/([\d.]+)/i);
|
|
277
|
+
break;
|
|
278
|
+
case "Safari":
|
|
279
|
+
match = ua.match(/version\/([\d.]+)/i);
|
|
280
|
+
break;
|
|
281
|
+
case "Firefox":
|
|
282
|
+
match = ua.match(/firefox\/([\d.]+)/i);
|
|
283
|
+
break;
|
|
284
|
+
case "Edge":
|
|
285
|
+
match = ua.match(/edg\/([\d.]+)/i);
|
|
286
|
+
break;
|
|
287
|
+
case "Opera":
|
|
288
|
+
match = ua.match(/(?:opera|opr)\/([\d.]+)/i);
|
|
289
|
+
break;
|
|
290
|
+
case "IE":
|
|
291
|
+
match = ua.match(/(?:msie |rv:)([\d.]+)/i);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
return match ? match[1] : "Unknown";
|
|
295
|
+
}
|
|
296
|
+
function getDevicePixelRatio() {
|
|
297
|
+
return window.devicePixelRatio || 1;
|
|
298
|
+
}
|
|
299
|
+
function getScreenResolution() {
|
|
300
|
+
return {
|
|
301
|
+
width: window.screen.width,
|
|
302
|
+
height: window.screen.height
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function getViewportSize() {
|
|
306
|
+
return {
|
|
307
|
+
width: window.innerWidth || document.documentElement.clientWidth,
|
|
308
|
+
height: window.innerHeight || document.documentElement.clientHeight
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function isTouchDevice() {
|
|
312
|
+
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
313
|
+
}
|
|
314
|
+
function getDeviceInfo() {
|
|
315
|
+
return {
|
|
316
|
+
os: getOS(),
|
|
317
|
+
browser: getBrowser(),
|
|
318
|
+
browserVersion: getBrowserVersion(),
|
|
319
|
+
browserEngine: getBrowserEngine(),
|
|
320
|
+
deviceType: getDeviceType(),
|
|
321
|
+
isMobile: isMobile(),
|
|
322
|
+
isTablet: isTablet(),
|
|
323
|
+
isDesktop: isDesktop(),
|
|
324
|
+
isIOS: isIOS(),
|
|
325
|
+
isAndroid: isAndroid(),
|
|
326
|
+
isWeChat: isWeChat(),
|
|
327
|
+
isTouchDevice: isTouchDevice(),
|
|
328
|
+
devicePixelRatio: getDevicePixelRatio(),
|
|
329
|
+
screenResolution: getScreenResolution(),
|
|
330
|
+
viewportSize: getViewportSize(),
|
|
331
|
+
userAgent: navigator.userAgent
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/format/index.ts
|
|
336
|
+
function formatMoney(amount, options = {}) {
|
|
337
|
+
const {
|
|
338
|
+
decimals = 2,
|
|
339
|
+
symbol = "\xA5",
|
|
340
|
+
separator = ",",
|
|
341
|
+
decimalPoint = "."
|
|
342
|
+
} = options;
|
|
343
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
344
|
+
if (isNaN(num)) {
|
|
345
|
+
return `${symbol}0${decimalPoint}${"0".repeat(decimals)}`;
|
|
346
|
+
}
|
|
347
|
+
const isNegative = num < 0;
|
|
348
|
+
const absNum = Math.abs(num);
|
|
349
|
+
const fixed = absNum.toFixed(decimals);
|
|
350
|
+
const [integerPart, decimalPart] = fixed.split(".");
|
|
351
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
352
|
+
let result = symbol + formattedInteger;
|
|
353
|
+
if (decimals > 0 && decimalPart) {
|
|
354
|
+
result += decimalPoint + decimalPart;
|
|
355
|
+
}
|
|
356
|
+
return isNegative ? `-${result}` : result;
|
|
357
|
+
}
|
|
358
|
+
function parseMoney(formattedAmount) {
|
|
359
|
+
if (!formattedAmount || typeof formattedAmount !== "string") {
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
362
|
+
const cleaned = formattedAmount.replace(/[^\d.-]/g, "");
|
|
363
|
+
const num = parseFloat(cleaned);
|
|
364
|
+
return isNaN(num) ? 0 : num;
|
|
365
|
+
}
|
|
366
|
+
function formatNumber(amount, decimals = 2) {
|
|
367
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
368
|
+
if (isNaN(num)) {
|
|
369
|
+
return "0." + "0".repeat(decimals);
|
|
370
|
+
}
|
|
371
|
+
const fixed = num.toFixed(decimals);
|
|
372
|
+
const [integerPart, decimalPart] = fixed.split(".");
|
|
373
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
374
|
+
return decimals > 0 && decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
375
|
+
}
|
|
376
|
+
function formatMoneyToChinese(amount) {
|
|
377
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
378
|
+
if (isNaN(num) || num < 0) {
|
|
379
|
+
return "\u96F6\u5143\u6574";
|
|
380
|
+
}
|
|
381
|
+
const digits = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
382
|
+
const units = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
383
|
+
const bigUnits = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
384
|
+
const decimalUnits = ["\u89D2", "\u5206"];
|
|
385
|
+
const [integerPart, decimalPart] = num.toFixed(2).split(".");
|
|
386
|
+
let result = "";
|
|
387
|
+
if (integerPart === "0") {
|
|
388
|
+
result = "\u96F6\u5143";
|
|
389
|
+
} else {
|
|
390
|
+
const integerStr = integerPart;
|
|
391
|
+
const len = integerStr.length;
|
|
392
|
+
let zeroCount = 0;
|
|
393
|
+
for (let i = 0; i < len; i++) {
|
|
394
|
+
const digit = parseInt(integerStr[i]);
|
|
395
|
+
const unitIndex = (len - i - 1) % 4;
|
|
396
|
+
const bigUnitIndex = Math.floor((len - i - 1) / 4);
|
|
397
|
+
if (digit === 0) {
|
|
398
|
+
zeroCount++;
|
|
399
|
+
} else {
|
|
400
|
+
if (zeroCount > 0) {
|
|
401
|
+
result += "\u96F6";
|
|
402
|
+
}
|
|
403
|
+
result += digits[digit] + units[unitIndex];
|
|
404
|
+
zeroCount = 0;
|
|
405
|
+
}
|
|
406
|
+
if (unitIndex === 0 && bigUnitIndex > 0) {
|
|
407
|
+
if (result[result.length - 1] !== bigUnits[bigUnitIndex]) {
|
|
408
|
+
result += bigUnits[bigUnitIndex];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
result += "\u5143";
|
|
413
|
+
}
|
|
414
|
+
if (decimalPart && decimalPart !== "00") {
|
|
415
|
+
const jiao = parseInt(decimalPart[0]);
|
|
416
|
+
const fen = parseInt(decimalPart[1]);
|
|
417
|
+
if (jiao > 0) {
|
|
418
|
+
result += digits[jiao] + decimalUnits[0];
|
|
419
|
+
} else if (fen > 0) {
|
|
420
|
+
result += "\u96F6";
|
|
421
|
+
}
|
|
422
|
+
if (fen > 0) {
|
|
423
|
+
result += digits[fen] + decimalUnits[1];
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
result += "\u6574";
|
|
427
|
+
}
|
|
428
|
+
return result;
|
|
429
|
+
}
|
|
430
|
+
function formatPercent(value, options = {}) {
|
|
431
|
+
const { decimals = 2, multiply: multiply2 = true } = options;
|
|
432
|
+
if (isNaN(value)) {
|
|
433
|
+
return "0%";
|
|
434
|
+
}
|
|
435
|
+
const num = multiply2 ? value * 100 : value;
|
|
436
|
+
return num.toFixed(decimals) + "%";
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/date/index.ts
|
|
440
|
+
var import_date_fns = require("date-fns");
|
|
441
|
+
var import_locale = require("date-fns/locale");
|
|
442
|
+
function formatDate(date, formatStr = "yyyy-MM-dd HH:mm:ss") {
|
|
443
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
444
|
+
return (0, import_date_fns.isValid)(dateObj) ? (0, import_date_fns.format)(dateObj, formatStr) : "";
|
|
445
|
+
}
|
|
446
|
+
function formatDateOnly(date) {
|
|
447
|
+
return formatDate(date, "yyyy-MM-dd");
|
|
448
|
+
}
|
|
449
|
+
function formatTimeOnly(date) {
|
|
450
|
+
return formatDate(date, "HH:mm:ss");
|
|
451
|
+
}
|
|
452
|
+
function formatRelativeTime(date, locale = "zh") {
|
|
453
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
454
|
+
if (!(0, import_date_fns.isValid)(dateObj)) return "";
|
|
455
|
+
return (0, import_date_fns.formatDistanceToNow)(dateObj, {
|
|
456
|
+
addSuffix: true,
|
|
457
|
+
locale: locale === "zh" ? import_locale.zhCN : void 0
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function parseDate(dateStr, formatStr = "yyyy-MM-dd HH:mm:ss") {
|
|
461
|
+
return (0, import_date_fns.parse)(dateStr, formatStr, /* @__PURE__ */ new Date());
|
|
462
|
+
}
|
|
463
|
+
function isValidDate(date) {
|
|
464
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
465
|
+
return (0, import_date_fns.isValid)(dateObj);
|
|
466
|
+
}
|
|
467
|
+
function getDaysDiff(dateLeft, dateRight) {
|
|
468
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns.parseISO)(dateLeft) : new Date(dateLeft);
|
|
469
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns.parseISO)(dateRight) : new Date(dateRight);
|
|
470
|
+
return (0, import_date_fns.differenceInDays)(left, right);
|
|
471
|
+
}
|
|
472
|
+
function getHoursDiff(dateLeft, dateRight) {
|
|
473
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns.parseISO)(dateLeft) : new Date(dateLeft);
|
|
474
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns.parseISO)(dateRight) : new Date(dateRight);
|
|
475
|
+
return (0, import_date_fns.differenceInHours)(left, right);
|
|
476
|
+
}
|
|
477
|
+
function getMinutesDiff(dateLeft, dateRight) {
|
|
478
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns.parseISO)(dateLeft) : new Date(dateLeft);
|
|
479
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns.parseISO)(dateRight) : new Date(dateRight);
|
|
480
|
+
return (0, import_date_fns.differenceInMinutes)(left, right);
|
|
481
|
+
}
|
|
482
|
+
function addDaysToDate(date, amount) {
|
|
483
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
484
|
+
return (0, import_date_fns.addDays)(dateObj, amount);
|
|
485
|
+
}
|
|
486
|
+
function subDaysFromDate(date, amount) {
|
|
487
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
488
|
+
return (0, import_date_fns.subDays)(dateObj, amount);
|
|
489
|
+
}
|
|
490
|
+
function addMonthsToDate(date, amount) {
|
|
491
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
492
|
+
return (0, import_date_fns.addMonths)(dateObj, amount);
|
|
493
|
+
}
|
|
494
|
+
function subMonthsFromDate(date, amount) {
|
|
495
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
496
|
+
return (0, import_date_fns.subMonths)(dateObj, amount);
|
|
497
|
+
}
|
|
498
|
+
function getStartOfDay(date) {
|
|
499
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
500
|
+
return (0, import_date_fns.startOfDay)(dateObj);
|
|
501
|
+
}
|
|
502
|
+
function getEndOfDay(date) {
|
|
503
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
504
|
+
return (0, import_date_fns.endOfDay)(dateObj);
|
|
505
|
+
}
|
|
506
|
+
function getStartOfWeek(date) {
|
|
507
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
508
|
+
return (0, import_date_fns.startOfWeek)(dateObj, { weekStartsOn: 1 });
|
|
509
|
+
}
|
|
510
|
+
function getEndOfWeek(date) {
|
|
511
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
512
|
+
return (0, import_date_fns.endOfWeek)(dateObj, { weekStartsOn: 1 });
|
|
513
|
+
}
|
|
514
|
+
function getStartOfMonth(date) {
|
|
515
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
516
|
+
return (0, import_date_fns.startOfMonth)(dateObj);
|
|
517
|
+
}
|
|
518
|
+
function getEndOfMonth(date) {
|
|
519
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
520
|
+
return (0, import_date_fns.endOfMonth)(dateObj);
|
|
521
|
+
}
|
|
522
|
+
function getStartOfYear(date) {
|
|
523
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
524
|
+
return (0, import_date_fns.startOfYear)(dateObj);
|
|
525
|
+
}
|
|
526
|
+
function getEndOfYear(date) {
|
|
527
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
528
|
+
return (0, import_date_fns.endOfYear)(dateObj);
|
|
529
|
+
}
|
|
530
|
+
function isBeforeDate(date, dateToCompare) {
|
|
531
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
532
|
+
const compareObj = typeof dateToCompare === "string" ? (0, import_date_fns.parseISO)(dateToCompare) : new Date(dateToCompare);
|
|
533
|
+
return (0, import_date_fns.isBefore)(dateObj, compareObj);
|
|
534
|
+
}
|
|
535
|
+
function isAfterDate(date, dateToCompare) {
|
|
536
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns.parseISO)(date) : new Date(date);
|
|
537
|
+
const compareObj = typeof dateToCompare === "string" ? (0, import_date_fns.parseISO)(dateToCompare) : new Date(dateToCompare);
|
|
538
|
+
return (0, import_date_fns.isAfter)(dateObj, compareObj);
|
|
539
|
+
}
|
|
540
|
+
function isSameDayDate(dateLeft, dateRight) {
|
|
541
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns.parseISO)(dateLeft) : new Date(dateLeft);
|
|
542
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns.parseISO)(dateRight) : new Date(dateRight);
|
|
543
|
+
return (0, import_date_fns.isSameDay)(left, right);
|
|
544
|
+
}
|
|
545
|
+
function getTimestamp() {
|
|
546
|
+
return Date.now();
|
|
547
|
+
}
|
|
548
|
+
function getTimestampInSeconds() {
|
|
549
|
+
return Math.floor(Date.now() / 1e3);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/date/utc/index.ts
|
|
553
|
+
var import_date_fns2 = require("date-fns");
|
|
554
|
+
var import_date_fns_tz = require("date-fns-tz");
|
|
555
|
+
var UTC_TIMEZONE = "UTC";
|
|
556
|
+
function toUTC(date) {
|
|
557
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
558
|
+
return (0, import_date_fns_tz.fromZonedTime)(dateObj, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
559
|
+
}
|
|
560
|
+
function fromUTC(utcDate) {
|
|
561
|
+
const dateObj = typeof utcDate === "string" ? (0, import_date_fns2.parseISO)(utcDate) : new Date(utcDate);
|
|
562
|
+
return (0, import_date_fns_tz.toZonedTime)(dateObj, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
563
|
+
}
|
|
564
|
+
function formatUTC(date, formatStr = "yyyy-MM-dd HH:mm:ss") {
|
|
565
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
566
|
+
if (!(0, import_date_fns2.isValid)(dateObj)) return "";
|
|
567
|
+
return (0, import_date_fns_tz.formatInTimeZone)(dateObj, UTC_TIMEZONE, formatStr);
|
|
568
|
+
}
|
|
569
|
+
function formatUTCDateOnly(date) {
|
|
570
|
+
return formatUTC(date, "yyyy-MM-dd");
|
|
571
|
+
}
|
|
572
|
+
function formatUTCTimeOnly(date) {
|
|
573
|
+
return formatUTC(date, "HH:mm:ss");
|
|
574
|
+
}
|
|
575
|
+
function toISOString(date) {
|
|
576
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
577
|
+
return dateObj.toISOString();
|
|
578
|
+
}
|
|
579
|
+
function getUTCNow() {
|
|
580
|
+
return /* @__PURE__ */ new Date();
|
|
581
|
+
}
|
|
582
|
+
function getUTCTimestamp() {
|
|
583
|
+
return Date.now();
|
|
584
|
+
}
|
|
585
|
+
function getUTCTimestampInSeconds() {
|
|
586
|
+
return Math.floor(Date.now() / 1e3);
|
|
587
|
+
}
|
|
588
|
+
function getUTCStartOfDay(date) {
|
|
589
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
590
|
+
const utcDate = (0, import_date_fns_tz.toZonedTime)(dateObj, UTC_TIMEZONE);
|
|
591
|
+
return (0, import_date_fns2.startOfDay)(utcDate);
|
|
592
|
+
}
|
|
593
|
+
function getUTCEndOfDay(date) {
|
|
594
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
595
|
+
const utcDate = (0, import_date_fns_tz.toZonedTime)(dateObj, UTC_TIMEZONE);
|
|
596
|
+
return (0, import_date_fns2.endOfDay)(utcDate);
|
|
597
|
+
}
|
|
598
|
+
function getUTCStartOfMonth(date) {
|
|
599
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
600
|
+
const utcDate = (0, import_date_fns_tz.toZonedTime)(dateObj, UTC_TIMEZONE);
|
|
601
|
+
return (0, import_date_fns2.startOfMonth)(utcDate);
|
|
602
|
+
}
|
|
603
|
+
function getUTCEndOfMonth(date) {
|
|
604
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
605
|
+
const utcDate = (0, import_date_fns_tz.toZonedTime)(dateObj, UTC_TIMEZONE);
|
|
606
|
+
return (0, import_date_fns2.endOfMonth)(utcDate);
|
|
607
|
+
}
|
|
608
|
+
function addDaysUTC(date, amount) {
|
|
609
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
610
|
+
return (0, import_date_fns2.addDays)(dateObj, amount);
|
|
611
|
+
}
|
|
612
|
+
function subDaysUTC(date, amount) {
|
|
613
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
614
|
+
return (0, import_date_fns2.subDays)(dateObj, amount);
|
|
615
|
+
}
|
|
616
|
+
function addMonthsUTC(date, amount) {
|
|
617
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
618
|
+
return (0, import_date_fns2.addMonths)(dateObj, amount);
|
|
619
|
+
}
|
|
620
|
+
function subMonthsUTC(date, amount) {
|
|
621
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
622
|
+
return (0, import_date_fns2.subMonths)(dateObj, amount);
|
|
623
|
+
}
|
|
624
|
+
function getUTCDaysDiff(dateLeft, dateRight) {
|
|
625
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns2.parseISO)(dateLeft) : new Date(dateLeft);
|
|
626
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns2.parseISO)(dateRight) : new Date(dateRight);
|
|
627
|
+
return (0, import_date_fns2.differenceInDays)(left, right);
|
|
628
|
+
}
|
|
629
|
+
function getUTCHoursDiff(dateLeft, dateRight) {
|
|
630
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns2.parseISO)(dateLeft) : new Date(dateLeft);
|
|
631
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns2.parseISO)(dateRight) : new Date(dateRight);
|
|
632
|
+
return (0, import_date_fns2.differenceInHours)(left, right);
|
|
633
|
+
}
|
|
634
|
+
function getUTCMinutesDiff(dateLeft, dateRight) {
|
|
635
|
+
const left = typeof dateLeft === "string" ? (0, import_date_fns2.parseISO)(dateLeft) : new Date(dateLeft);
|
|
636
|
+
const right = typeof dateRight === "string" ? (0, import_date_fns2.parseISO)(dateRight) : new Date(dateRight);
|
|
637
|
+
return (0, import_date_fns2.differenceInMinutes)(left, right);
|
|
638
|
+
}
|
|
639
|
+
function getTimezoneOffset() {
|
|
640
|
+
return (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
641
|
+
}
|
|
642
|
+
function getTimezoneOffsetHours() {
|
|
643
|
+
return -(/* @__PURE__ */ new Date()).getTimezoneOffset() / 60;
|
|
644
|
+
}
|
|
645
|
+
function getUTCYearStartTimestamp(year) {
|
|
646
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
647
|
+
const date = new Date(Date.UTC(targetYear, 0, 1, 0, 0, 0, 0));
|
|
648
|
+
return date.getTime();
|
|
649
|
+
}
|
|
650
|
+
function getUTCYearEndTimestamp(year) {
|
|
651
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
652
|
+
const date = new Date(Date.UTC(targetYear, 11, 31, 23, 59, 59, 999));
|
|
653
|
+
return date.getTime();
|
|
654
|
+
}
|
|
655
|
+
function getUTCYearStart(year) {
|
|
656
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
657
|
+
return new Date(Date.UTC(targetYear, 0, 1, 0, 0, 0, 0));
|
|
658
|
+
}
|
|
659
|
+
function getUTCYearEnd(year) {
|
|
660
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
661
|
+
return new Date(Date.UTC(targetYear, 11, 31, 23, 59, 59, 999));
|
|
662
|
+
}
|
|
663
|
+
function getUTCWeeksInYear(year) {
|
|
664
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
665
|
+
const date = new Date(Date.UTC(targetYear, 0, 1));
|
|
666
|
+
return (0, import_date_fns2.getISOWeeksInYear)(date);
|
|
667
|
+
}
|
|
668
|
+
function getUTCWeekStart(year, week) {
|
|
669
|
+
const date = new Date(Date.UTC(year, 0, 4));
|
|
670
|
+
const weekDate = (0, import_date_fns2.setISOWeek)(date, week);
|
|
671
|
+
return (0, import_date_fns2.startOfWeek)(weekDate, { weekStartsOn: 1 });
|
|
672
|
+
}
|
|
673
|
+
function getUTCWeekEnd(year, week) {
|
|
674
|
+
const date = new Date(Date.UTC(year, 0, 4));
|
|
675
|
+
const weekDate = (0, import_date_fns2.setISOWeek)(date, week);
|
|
676
|
+
return (0, import_date_fns2.endOfWeek)(weekDate, { weekStartsOn: 1 });
|
|
677
|
+
}
|
|
678
|
+
function getUTCAllWeeksInYear(year) {
|
|
679
|
+
const targetYear = year ?? (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
680
|
+
const weeksCount = getUTCWeeksInYear(targetYear);
|
|
681
|
+
const weeks = [];
|
|
682
|
+
for (let week = 1; week <= weeksCount; week++) {
|
|
683
|
+
const start = getUTCWeekStart(targetYear, week);
|
|
684
|
+
const end = getUTCWeekEnd(targetYear, week);
|
|
685
|
+
weeks.push({
|
|
686
|
+
week,
|
|
687
|
+
start,
|
|
688
|
+
end,
|
|
689
|
+
startTimestamp: start.getTime(),
|
|
690
|
+
endTimestamp: end.getTime()
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return weeks;
|
|
694
|
+
}
|
|
695
|
+
function getUTCWeekNumber(date) {
|
|
696
|
+
const dateObj = typeof date === "string" ? (0, import_date_fns2.parseISO)(date) : new Date(date);
|
|
697
|
+
return (0, import_date_fns2.getISOWeek)(dateObj);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/decimal/index.ts
|
|
701
|
+
var import_decimal = __toESM(require("decimal.js"), 1);
|
|
702
|
+
|
|
703
|
+
// src/decimal/utils/index.ts
|
|
704
|
+
var import_decimal2 = __toESM(require("decimal.js"), 1);
|
|
705
|
+
function safeDecimal(value) {
|
|
706
|
+
try {
|
|
707
|
+
if (value instanceof import_decimal2.default) {
|
|
708
|
+
return value;
|
|
709
|
+
}
|
|
710
|
+
const decimal = new import_decimal2.default(value);
|
|
711
|
+
if (decimal.isNaN()) {
|
|
712
|
+
return new import_decimal2.default(0);
|
|
713
|
+
}
|
|
714
|
+
return decimal;
|
|
715
|
+
} catch {
|
|
716
|
+
return new import_decimal2.default(0);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function add(a, b) {
|
|
720
|
+
try {
|
|
721
|
+
const decimalA = safeDecimal(a);
|
|
722
|
+
const decimalB = safeDecimal(b);
|
|
723
|
+
return decimalA.plus(decimalB).toNumber();
|
|
724
|
+
} catch {
|
|
725
|
+
return 0;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
function subtract(a, b) {
|
|
729
|
+
try {
|
|
730
|
+
const decimalA = safeDecimal(a);
|
|
731
|
+
const decimalB = safeDecimal(b);
|
|
732
|
+
return decimalA.minus(decimalB).toNumber();
|
|
733
|
+
} catch {
|
|
734
|
+
return 0;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function multiply(a, b) {
|
|
738
|
+
try {
|
|
739
|
+
const decimalA = safeDecimal(a);
|
|
740
|
+
const decimalB = safeDecimal(b);
|
|
741
|
+
return decimalA.times(decimalB).toNumber();
|
|
742
|
+
} catch {
|
|
743
|
+
return 0;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function divide(a, b) {
|
|
747
|
+
try {
|
|
748
|
+
const decimalA = safeDecimal(a);
|
|
749
|
+
const decimalB = safeDecimal(b);
|
|
750
|
+
if (decimalB.isZero()) {
|
|
751
|
+
return 0;
|
|
752
|
+
}
|
|
753
|
+
return decimalA.dividedBy(decimalB).toNumber();
|
|
754
|
+
} catch {
|
|
755
|
+
return 0;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
function equals(a, b) {
|
|
759
|
+
try {
|
|
760
|
+
const decimalA = safeDecimal(a);
|
|
761
|
+
const decimalB = safeDecimal(b);
|
|
762
|
+
return decimalA.equals(decimalB);
|
|
763
|
+
} catch {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function greaterThan(a, b) {
|
|
768
|
+
try {
|
|
769
|
+
const decimalA = safeDecimal(a);
|
|
770
|
+
const decimalB = safeDecimal(b);
|
|
771
|
+
return decimalA.greaterThan(decimalB);
|
|
772
|
+
} catch {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function lessThan(a, b) {
|
|
777
|
+
try {
|
|
778
|
+
const decimalA = safeDecimal(a);
|
|
779
|
+
const decimalB = safeDecimal(b);
|
|
780
|
+
return decimalA.lessThan(decimalB);
|
|
781
|
+
} catch {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function greaterThanOrEqual(a, b) {
|
|
786
|
+
try {
|
|
787
|
+
const decimalA = safeDecimal(a);
|
|
788
|
+
const decimalB = safeDecimal(b);
|
|
789
|
+
return decimalA.greaterThanOrEqualTo(decimalB);
|
|
790
|
+
} catch {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function lessThanOrEqual(a, b) {
|
|
795
|
+
try {
|
|
796
|
+
const decimalA = safeDecimal(a);
|
|
797
|
+
const decimalB = safeDecimal(b);
|
|
798
|
+
return decimalA.lessThanOrEqualTo(decimalB);
|
|
799
|
+
} catch {
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function round(value, decimalPlaces = 2) {
|
|
804
|
+
try {
|
|
805
|
+
const decimal = safeDecimal(value);
|
|
806
|
+
return decimal.toDecimalPlaces(decimalPlaces).toNumber();
|
|
807
|
+
} catch {
|
|
808
|
+
return 0;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
function ceil(value, decimalPlaces = 2) {
|
|
812
|
+
try {
|
|
813
|
+
const decimal = safeDecimal(value);
|
|
814
|
+
return decimal.toDecimalPlaces(decimalPlaces, import_decimal2.default.ROUND_CEIL).toNumber();
|
|
815
|
+
} catch {
|
|
816
|
+
return 0;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
function floor(value, decimalPlaces = 2) {
|
|
820
|
+
try {
|
|
821
|
+
const decimal = safeDecimal(value);
|
|
822
|
+
return decimal.toDecimalPlaces(decimalPlaces, import_decimal2.default.ROUND_FLOOR).toNumber();
|
|
823
|
+
} catch {
|
|
824
|
+
return 0;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function abs(value) {
|
|
828
|
+
try {
|
|
829
|
+
const decimal = safeDecimal(value);
|
|
830
|
+
return decimal.abs().toNumber();
|
|
831
|
+
} catch {
|
|
832
|
+
return 0;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function negate(value) {
|
|
836
|
+
try {
|
|
837
|
+
const decimal = safeDecimal(value);
|
|
838
|
+
return decimal.negated().toNumber();
|
|
839
|
+
} catch {
|
|
840
|
+
return 0;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
844
|
+
0 && (module.exports = {
|
|
845
|
+
Decimal,
|
|
846
|
+
abs,
|
|
847
|
+
add,
|
|
848
|
+
addDaysToDate,
|
|
849
|
+
addDaysUTC,
|
|
850
|
+
addMonthsToDate,
|
|
851
|
+
addMonthsUTC,
|
|
852
|
+
ceil,
|
|
853
|
+
debounce,
|
|
854
|
+
divide,
|
|
855
|
+
equals,
|
|
856
|
+
floor,
|
|
857
|
+
formatDate,
|
|
858
|
+
formatDateOnly,
|
|
859
|
+
formatMoney,
|
|
860
|
+
formatMoneyToChinese,
|
|
861
|
+
formatNumber,
|
|
862
|
+
formatPercent,
|
|
863
|
+
formatRelativeTime,
|
|
864
|
+
formatTimeOnly,
|
|
865
|
+
formatUTC,
|
|
866
|
+
formatUTCDateOnly,
|
|
867
|
+
formatUTCTimeOnly,
|
|
868
|
+
fromUTC,
|
|
869
|
+
getAllQueryParams,
|
|
870
|
+
getBrowser,
|
|
871
|
+
getBrowserEngine,
|
|
872
|
+
getBrowserVersion,
|
|
873
|
+
getDaysDiff,
|
|
874
|
+
getDeviceInfo,
|
|
875
|
+
getDevicePixelRatio,
|
|
876
|
+
getDeviceType,
|
|
877
|
+
getEndOfDay,
|
|
878
|
+
getEndOfMonth,
|
|
879
|
+
getEndOfWeek,
|
|
880
|
+
getEndOfYear,
|
|
881
|
+
getHoursDiff,
|
|
882
|
+
getMinutesDiff,
|
|
883
|
+
getOS,
|
|
884
|
+
getQueryParam,
|
|
885
|
+
getQueryParamAll,
|
|
886
|
+
getScreenResolution,
|
|
887
|
+
getStartOfDay,
|
|
888
|
+
getStartOfMonth,
|
|
889
|
+
getStartOfWeek,
|
|
890
|
+
getStartOfYear,
|
|
891
|
+
getTimestamp,
|
|
892
|
+
getTimestampInSeconds,
|
|
893
|
+
getTimezoneOffset,
|
|
894
|
+
getTimezoneOffsetHours,
|
|
895
|
+
getUTCAllWeeksInYear,
|
|
896
|
+
getUTCDaysDiff,
|
|
897
|
+
getUTCEndOfDay,
|
|
898
|
+
getUTCEndOfMonth,
|
|
899
|
+
getUTCHoursDiff,
|
|
900
|
+
getUTCMinutesDiff,
|
|
901
|
+
getUTCNow,
|
|
902
|
+
getUTCStartOfDay,
|
|
903
|
+
getUTCStartOfMonth,
|
|
904
|
+
getUTCTimestamp,
|
|
905
|
+
getUTCTimestampInSeconds,
|
|
906
|
+
getUTCWeekEnd,
|
|
907
|
+
getUTCWeekNumber,
|
|
908
|
+
getUTCWeekStart,
|
|
909
|
+
getUTCWeeksInYear,
|
|
910
|
+
getUTCYearEnd,
|
|
911
|
+
getUTCYearEndTimestamp,
|
|
912
|
+
getUTCYearStart,
|
|
913
|
+
getUTCYearStartTimestamp,
|
|
914
|
+
getViewportSize,
|
|
915
|
+
greaterThan,
|
|
916
|
+
greaterThanOrEqual,
|
|
917
|
+
isAfterDate,
|
|
918
|
+
isAndroid,
|
|
919
|
+
isBeforeDate,
|
|
920
|
+
isDesktop,
|
|
921
|
+
isIOS,
|
|
922
|
+
isMobile,
|
|
923
|
+
isSameDayDate,
|
|
924
|
+
isTablet,
|
|
925
|
+
isTouchDevice,
|
|
926
|
+
isValidDate,
|
|
927
|
+
isWeChat,
|
|
928
|
+
lessThan,
|
|
929
|
+
lessThanOrEqual,
|
|
930
|
+
multiply,
|
|
931
|
+
negate,
|
|
932
|
+
parseDate,
|
|
933
|
+
parseMoney,
|
|
934
|
+
round,
|
|
935
|
+
subDaysFromDate,
|
|
936
|
+
subDaysUTC,
|
|
937
|
+
subMonthsFromDate,
|
|
938
|
+
subMonthsUTC,
|
|
939
|
+
subtract,
|
|
940
|
+
throttle,
|
|
941
|
+
toISOString,
|
|
942
|
+
toUTC
|
|
943
|
+
});
|