@base-web-kits/base-tools-ts 1.3.5 → 1.3.8
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 +93 -0
- package/dist/base-tools-ts.umd.global.js +3915 -3658
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/buffer/SSEParser.d.ts.map +1 -1
- package/dist/buffer/index.d.ts +3 -0
- package/dist/buffer/index.d.ts.map +1 -0
- package/dist/index.cjs +621 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +620 -363
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ts/buffer/SSEParser.ts +1 -0
- package/src/ts/buffer/index.ts +2 -0
- package/src/ts/index.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -95,282 +95,126 @@ var EventBus = class {
|
|
|
95
95
|
};
|
|
96
96
|
var EventBus_default = new EventBus();
|
|
97
97
|
|
|
98
|
-
// src/ts/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let acc = big(rest2[0]);
|
|
114
|
-
for (const x of rest2.slice(1)) acc = acc.plus(big(x));
|
|
115
|
-
return acc.toNumber();
|
|
116
|
-
}
|
|
117
|
-
function mathMinus(...rest2) {
|
|
118
|
-
let acc = big(rest2[0]);
|
|
119
|
-
for (const x of rest2.slice(1)) acc = acc.minus(big(x));
|
|
120
|
-
return acc.toNumber();
|
|
121
|
-
}
|
|
122
|
-
function mathTimes(...rest2) {
|
|
123
|
-
let acc = big(rest2[0]);
|
|
124
|
-
for (const x of rest2.slice(1)) acc = acc.times(big(x));
|
|
125
|
-
return acc.toNumber();
|
|
126
|
-
}
|
|
127
|
-
function mathDiv(...rest2) {
|
|
128
|
-
let acc = big(rest2[0]);
|
|
129
|
-
for (const x of rest2.slice(1)) acc = acc.div(big(x));
|
|
130
|
-
return acc.toNumber();
|
|
131
|
-
}
|
|
132
|
-
function mathPow(x, y) {
|
|
133
|
-
return big(x).pow(big(y)).toNumber();
|
|
134
|
-
}
|
|
135
|
-
function mathRound(x, dp = 0, rm = BigNumber.ROUND_HALF_UP) {
|
|
136
|
-
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
137
|
-
}
|
|
138
|
-
function mathFixed(x, dp = 2, rm = BigNumber.ROUND_HALF_UP) {
|
|
139
|
-
return big(x).toFixed(dp, rm);
|
|
140
|
-
}
|
|
141
|
-
function mathCompare(a, b) {
|
|
142
|
-
return big(a).comparedTo(big(b));
|
|
143
|
-
}
|
|
144
|
-
function mathEqual(a, b) {
|
|
145
|
-
return big(a).isEqualTo(big(b));
|
|
146
|
-
}
|
|
147
|
-
function mathGreaterThan(a, b) {
|
|
148
|
-
return big(a).isGreaterThan(big(b));
|
|
149
|
-
}
|
|
150
|
-
function mathGreaterThanOrEqual(a, b) {
|
|
151
|
-
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
152
|
-
}
|
|
153
|
-
function mathLessThan(a, b) {
|
|
154
|
-
return big(a).isLessThan(big(b));
|
|
155
|
-
}
|
|
156
|
-
function mathLessThanOrEqual(a, b) {
|
|
157
|
-
return big(a).isLessThanOrEqualTo(big(b));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// src/ts/number/format.ts
|
|
161
|
-
function zeroPad(n, len = 2) {
|
|
162
|
-
return String(n).padStart(len, "0");
|
|
163
|
-
}
|
|
164
|
-
function withUnit(num, unit = "") {
|
|
165
|
-
if (num === null || num === void 0 || num === "") return "";
|
|
166
|
-
if (typeof num === "number") return `${num}${unit}`;
|
|
167
|
-
const str = String(num).trim();
|
|
168
|
-
if (str === "") return "";
|
|
169
|
-
return isNaN(+str) ? str : `${str}${unit}`;
|
|
170
|
-
}
|
|
171
|
-
function withUnitPx(num) {
|
|
172
|
-
return withUnit(num, "px");
|
|
173
|
-
}
|
|
174
|
-
function withDistance(m) {
|
|
175
|
-
const n = Number(m != null ? m : 0);
|
|
176
|
-
if (!Number.isFinite(n)) return "0m";
|
|
177
|
-
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
178
|
-
}
|
|
179
|
-
function toThousandth(str) {
|
|
180
|
-
const v = String(str != null ? str : "").trim();
|
|
181
|
-
if (v === "") return "";
|
|
182
|
-
let sign = "";
|
|
183
|
-
let num = v;
|
|
184
|
-
if (num[0] === "-" || num[0] === "+") {
|
|
185
|
-
sign = num[0];
|
|
186
|
-
num = num.slice(1);
|
|
187
|
-
}
|
|
188
|
-
const [intPart, decPart] = num.split(".");
|
|
189
|
-
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
190
|
-
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
191
|
-
}
|
|
192
|
-
function toChineseNum(num) {
|
|
193
|
-
const numInt = Math.trunc(+num);
|
|
194
|
-
if (numInt === 0) return "\u96F6";
|
|
195
|
-
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
196
|
-
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
197
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
198
|
-
const section4 = (n2) => {
|
|
199
|
-
let str = "", zeroFlag = false;
|
|
200
|
-
for (let i = 0; i < 4; i++) {
|
|
201
|
-
const d = n2 % 10;
|
|
202
|
-
n2 = Math.floor(n2 / 10);
|
|
203
|
-
if (d === 0) {
|
|
204
|
-
zeroFlag = true;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (zeroFlag) str = digit[0] + str;
|
|
208
|
-
str = digit[d] + unit[i] + str;
|
|
209
|
-
zeroFlag = false;
|
|
210
|
-
}
|
|
211
|
-
return str;
|
|
212
|
-
};
|
|
213
|
-
let res = "";
|
|
214
|
-
let sectionIndex = 0;
|
|
215
|
-
let n = Math.abs(numInt);
|
|
216
|
-
while (n > 0) {
|
|
217
|
-
const seg = n % 1e4;
|
|
218
|
-
n = Math.floor(n / 1e4);
|
|
219
|
-
if (seg) {
|
|
220
|
-
const segStr = section4(seg);
|
|
221
|
-
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
222
|
-
} else if (res && !res.startsWith("\u96F6")) {
|
|
223
|
-
res = `\u96F6${res}`;
|
|
224
|
-
}
|
|
225
|
-
sectionIndex++;
|
|
226
|
-
}
|
|
227
|
-
res = res.replace(/^一十/, "\u5341");
|
|
228
|
-
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
229
|
-
}
|
|
230
|
-
function toChineseCurrency(amount, opts = {}) {
|
|
231
|
-
var _a, _b, _c;
|
|
232
|
-
const dp = (_a = opts.precision) != null ? _a : 2;
|
|
233
|
-
const rm = (_b = opts.rm) != null ? _b : BigNumber.ROUND_HALF_UP;
|
|
234
|
-
const yuan = (_c = opts.yuanChar) != null ? _c : "\u5143";
|
|
235
|
-
if (amount === null || amount === void 0) return "";
|
|
236
|
-
const bn = new BigNumber(amount);
|
|
237
|
-
if (!bn.isFinite()) return "";
|
|
238
|
-
const s = bn.toFixed(dp, rm);
|
|
239
|
-
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
240
|
-
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
241
|
-
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
242
|
-
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
243
|
-
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
244
|
-
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
245
|
-
const section4 = (n) => {
|
|
246
|
-
let str = "";
|
|
247
|
-
let zeroFlag = false;
|
|
248
|
-
for (let i = 0; i < 4; i++) {
|
|
249
|
-
const d = n.mod(10).toNumber();
|
|
250
|
-
n = n.idiv(10);
|
|
251
|
-
if (d === 0) {
|
|
252
|
-
zeroFlag = true;
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (zeroFlag) str = digit[0] + str;
|
|
256
|
-
str = digit[d] + unit[i] + str;
|
|
257
|
-
zeroFlag = false;
|
|
258
|
-
}
|
|
259
|
-
return str.replace(/零+$/g, "");
|
|
260
|
-
};
|
|
261
|
-
const intNum = new BigNumber(intStr);
|
|
262
|
-
let res = "";
|
|
263
|
-
if (intNum.isZero()) {
|
|
264
|
-
res = digit[0];
|
|
265
|
-
} else {
|
|
266
|
-
let n = intNum.abs();
|
|
267
|
-
let sectionIndex = 0;
|
|
268
|
-
while (n.gt(0)) {
|
|
269
|
-
const seg = n.mod(1e4);
|
|
270
|
-
n = n.idiv(1e4);
|
|
271
|
-
if (seg.gt(0)) {
|
|
272
|
-
const segStr = section4(seg);
|
|
273
|
-
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
274
|
-
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
275
|
-
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
276
|
-
} else if (res && !res.startsWith(digit[0])) {
|
|
277
|
-
res = digit[0] + res;
|
|
278
|
-
}
|
|
279
|
-
sectionIndex++;
|
|
280
|
-
}
|
|
281
|
-
res = res.replace(/^壹拾/, "\u62FE");
|
|
282
|
-
}
|
|
283
|
-
let frac = "";
|
|
284
|
-
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
285
|
-
const ch = decStr[i] || "0";
|
|
286
|
-
const d = ch.charCodeAt(0) - 48;
|
|
287
|
-
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
288
|
-
}
|
|
289
|
-
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// src/ts/number/random.ts
|
|
293
|
-
function randomBoolean() {
|
|
294
|
-
return Math.random() < 0.5;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// src/ts/day/index.ts
|
|
298
|
-
dayjs.extend(customParseFormat);
|
|
299
|
-
dayjs.extend(utc);
|
|
300
|
-
dayjs.extend(timezone);
|
|
301
|
-
dayjs.extend(relativeTime);
|
|
302
|
-
dayjs.extend(advancedFormat);
|
|
303
|
-
dayjs.locale("zh-cn");
|
|
304
|
-
function toDayjs(t, fmt) {
|
|
305
|
-
if (t === null || t === void 0) return dayjs();
|
|
306
|
-
if (typeof t === "number") {
|
|
307
|
-
const s = String(Math.trunc(t));
|
|
308
|
-
return dayjs(s.length === 10 ? t * 1e3 : t, fmt);
|
|
309
|
-
}
|
|
310
|
-
if (typeof t === "string") {
|
|
311
|
-
const s = t.trim();
|
|
312
|
-
if (/^\d{10}$/.test(s)) return dayjs(Number(s) * 1e3, fmt);
|
|
313
|
-
if (/^\d{13}$/.test(s)) return dayjs(Number(s), fmt);
|
|
314
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY-MM-DD");
|
|
315
|
-
if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY/MM/DD");
|
|
316
|
-
if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
317
|
-
return dayjs(s, fmt || "YYYY-MM-DD HH:mm:ss");
|
|
318
|
-
if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
319
|
-
return dayjs(s, fmt || "YYYY/MM/DD HH:mm:ss");
|
|
320
|
-
return dayjs(s, fmt);
|
|
321
|
-
}
|
|
322
|
-
return dayjs(t, fmt);
|
|
323
|
-
}
|
|
324
|
-
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
325
|
-
const now = toDayjs(Date.now());
|
|
326
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
327
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
328
|
-
const startDay = now.add(-n, "day");
|
|
329
|
-
const endDay = now;
|
|
330
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
331
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
332
|
-
return [start, end];
|
|
333
|
-
}
|
|
334
|
-
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
335
|
-
const now = toDayjs(Date.now());
|
|
336
|
-
const n = Math.max(0, Math.trunc(offset));
|
|
337
|
-
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
338
|
-
const startDay = now;
|
|
339
|
-
const endDay = now.add(n, "day");
|
|
340
|
-
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
341
|
-
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
342
|
-
return [start, end];
|
|
343
|
-
}
|
|
344
|
-
function getCountdownParts(diff) {
|
|
345
|
-
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
346
|
-
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
347
|
-
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
348
|
-
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
349
|
-
const s = Math.floor(diff / 1e3 % 60);
|
|
350
|
-
const ms = diff % 1e3;
|
|
351
|
-
return {
|
|
352
|
-
d: zeroPad(d),
|
|
353
|
-
h: zeroPad(h),
|
|
354
|
-
m: zeroPad(m),
|
|
355
|
-
s: zeroPad(s),
|
|
356
|
-
ms: zeroPad(ms, 3)
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
function getAgeByBirthdate(birthdate) {
|
|
360
|
-
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
361
|
-
const now = toDayjs(Date.now());
|
|
362
|
-
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
363
|
-
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
364
|
-
if (adjustedMonths >= 12) {
|
|
365
|
-
let age = Math.floor(adjustedMonths / 12);
|
|
366
|
-
const birthdayThisYear = birth.add(age, "year");
|
|
367
|
-
if (now.isBefore(birthdayThisYear)) {
|
|
368
|
-
age--;
|
|
98
|
+
// src/ts/buffer/PolyfillTextDecoder.ts
|
|
99
|
+
var PolyfillTextDecoder = class {
|
|
100
|
+
constructor() {
|
|
101
|
+
__publicField(this, "leftOver", new Uint8Array(0));
|
|
102
|
+
}
|
|
103
|
+
decode(input, options) {
|
|
104
|
+
var _a;
|
|
105
|
+
const stream = (_a = options == null ? void 0 : options.stream) != null ? _a : false;
|
|
106
|
+
let bytes;
|
|
107
|
+
if (!input) {
|
|
108
|
+
bytes = new Uint8Array(0);
|
|
109
|
+
} else if (input instanceof ArrayBuffer) {
|
|
110
|
+
bytes = new Uint8Array(input);
|
|
111
|
+
} else {
|
|
112
|
+
bytes = input;
|
|
369
113
|
}
|
|
370
|
-
|
|
114
|
+
if (this.leftOver.length > 0) {
|
|
115
|
+
const merged = new Uint8Array(this.leftOver.length + bytes.length);
|
|
116
|
+
merged.set(this.leftOver);
|
|
117
|
+
merged.set(bytes, this.leftOver.length);
|
|
118
|
+
bytes = merged;
|
|
119
|
+
this.leftOver = new Uint8Array(0);
|
|
120
|
+
}
|
|
121
|
+
const len = bytes.length;
|
|
122
|
+
if (len === 0) return "";
|
|
123
|
+
const parts = [];
|
|
124
|
+
let i = 0;
|
|
125
|
+
const replacement = "\uFFFD";
|
|
126
|
+
const isContinuationByte = (b) => (b & 192) === 128;
|
|
127
|
+
while (i < len) {
|
|
128
|
+
const byte1 = bytes[i];
|
|
129
|
+
if (byte1 < 128) {
|
|
130
|
+
parts.push(String.fromCharCode(byte1));
|
|
131
|
+
i += 1;
|
|
132
|
+
} else if (byte1 >= 194 && byte1 < 224) {
|
|
133
|
+
if (i + 1 >= len) {
|
|
134
|
+
if (stream) {
|
|
135
|
+
this.leftOver = bytes.slice(i);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
parts.push(replacement);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
const byte2 = bytes[i + 1];
|
|
142
|
+
if (!isContinuationByte(byte2)) {
|
|
143
|
+
parts.push(replacement);
|
|
144
|
+
i += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
parts.push(String.fromCharCode((byte1 & 31) << 6 | byte2 & 63));
|
|
148
|
+
i += 2;
|
|
149
|
+
} else if (byte1 >= 224 && byte1 < 240) {
|
|
150
|
+
if (i + 2 >= len) {
|
|
151
|
+
if (stream) {
|
|
152
|
+
this.leftOver = bytes.slice(i);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
parts.push(replacement);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
const byte2 = bytes[i + 1];
|
|
159
|
+
const byte3 = bytes[i + 2];
|
|
160
|
+
if (!isContinuationByte(byte2) || !isContinuationByte(byte3)) {
|
|
161
|
+
parts.push(replacement);
|
|
162
|
+
i += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (byte1 === 224 && byte2 < 160) {
|
|
166
|
+
parts.push(replacement);
|
|
167
|
+
i += 3;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (byte1 === 237 && byte2 >= 160) {
|
|
171
|
+
parts.push(replacement);
|
|
172
|
+
i += 3;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const codeUnit = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
|
|
176
|
+
parts.push(String.fromCharCode(codeUnit));
|
|
177
|
+
i += 3;
|
|
178
|
+
} else if (byte1 >= 240 && byte1 <= 244) {
|
|
179
|
+
if (i + 3 >= len) {
|
|
180
|
+
if (stream) {
|
|
181
|
+
this.leftOver = bytes.slice(i);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
parts.push(replacement);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
const byte2 = bytes[i + 1];
|
|
188
|
+
const byte3 = bytes[i + 2];
|
|
189
|
+
const byte4 = bytes[i + 3];
|
|
190
|
+
if (!isContinuationByte(byte2) || !isContinuationByte(byte3) || !isContinuationByte(byte4)) {
|
|
191
|
+
parts.push(replacement);
|
|
192
|
+
i += 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (byte1 === 240 && byte2 < 144) {
|
|
196
|
+
parts.push(replacement);
|
|
197
|
+
i += 4;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (byte1 === 244 && byte2 >= 144) {
|
|
201
|
+
parts.push(replacement);
|
|
202
|
+
i += 4;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const codepoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
|
|
206
|
+
const offset = codepoint - 65536;
|
|
207
|
+
parts.push(String.fromCharCode(55296 + (offset >> 10), 56320 + (offset & 1023)));
|
|
208
|
+
i += 4;
|
|
209
|
+
} else {
|
|
210
|
+
parts.push(replacement);
|
|
211
|
+
i += 1;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return parts.join("");
|
|
371
215
|
}
|
|
372
|
-
|
|
373
|
-
|
|
216
|
+
};
|
|
217
|
+
var PolyfillTextDecoder_default = PolyfillTextDecoder;
|
|
374
218
|
|
|
375
219
|
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/array/at.mjs
|
|
376
220
|
function at(arr, indices) {
|
|
@@ -2737,116 +2581,528 @@ function trimEnd(str, chars) {
|
|
|
2737
2581
|
if (chars === void 0) {
|
|
2738
2582
|
return str.trimEnd();
|
|
2739
2583
|
}
|
|
2740
|
-
let endIndex = str.length;
|
|
2741
|
-
switch (typeof chars) {
|
|
2742
|
-
case "string": {
|
|
2743
|
-
if (chars.length !== 1) {
|
|
2744
|
-
throw new Error(`The 'chars' parameter should be a single character string.`);
|
|
2745
|
-
}
|
|
2746
|
-
while (endIndex > 0 && str[endIndex - 1] === chars) {
|
|
2747
|
-
endIndex--;
|
|
2584
|
+
let endIndex = str.length;
|
|
2585
|
+
switch (typeof chars) {
|
|
2586
|
+
case "string": {
|
|
2587
|
+
if (chars.length !== 1) {
|
|
2588
|
+
throw new Error(`The 'chars' parameter should be a single character string.`);
|
|
2589
|
+
}
|
|
2590
|
+
while (endIndex > 0 && str[endIndex - 1] === chars) {
|
|
2591
|
+
endIndex--;
|
|
2592
|
+
}
|
|
2593
|
+
break;
|
|
2594
|
+
}
|
|
2595
|
+
case "object": {
|
|
2596
|
+
while (endIndex > 0 && chars.includes(str[endIndex - 1])) {
|
|
2597
|
+
endIndex--;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
return str.substring(0, endIndex);
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/string/trimStart.mjs
|
|
2605
|
+
function trimStart(str, chars) {
|
|
2606
|
+
if (chars === void 0) {
|
|
2607
|
+
return str.trimStart();
|
|
2608
|
+
}
|
|
2609
|
+
let startIndex = 0;
|
|
2610
|
+
switch (typeof chars) {
|
|
2611
|
+
case "string": {
|
|
2612
|
+
while (startIndex < str.length && str[startIndex] === chars) {
|
|
2613
|
+
startIndex++;
|
|
2614
|
+
}
|
|
2615
|
+
break;
|
|
2616
|
+
}
|
|
2617
|
+
case "object": {
|
|
2618
|
+
while (startIndex < str.length && chars.includes(str[startIndex])) {
|
|
2619
|
+
startIndex++;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
return str.substring(startIndex);
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/string/trim.mjs
|
|
2627
|
+
function trim(str, chars) {
|
|
2628
|
+
if (chars === void 0) {
|
|
2629
|
+
return str.trim();
|
|
2630
|
+
}
|
|
2631
|
+
return trimStart(trimEnd(str, chars), chars);
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/string/unescape.mjs
|
|
2635
|
+
var htmlUnescapes = {
|
|
2636
|
+
"&": "&",
|
|
2637
|
+
"<": "<",
|
|
2638
|
+
">": ">",
|
|
2639
|
+
""": '"',
|
|
2640
|
+
"'": "'"
|
|
2641
|
+
};
|
|
2642
|
+
function unescape2(str) {
|
|
2643
|
+
return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (match) => htmlUnescapes[match] || "'");
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/string/upperCase.mjs
|
|
2647
|
+
function upperCase(str) {
|
|
2648
|
+
const words$1 = words(str);
|
|
2649
|
+
let result = "";
|
|
2650
|
+
for (let i = 0; i < words$1.length; i++) {
|
|
2651
|
+
result += words$1[i].toUpperCase();
|
|
2652
|
+
if (i < words$1.length - 1) {
|
|
2653
|
+
result += " ";
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
return result;
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/string/upperFirst.mjs
|
|
2660
|
+
function upperFirst(str) {
|
|
2661
|
+
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/util/attempt.mjs
|
|
2665
|
+
function attempt(func) {
|
|
2666
|
+
try {
|
|
2667
|
+
return [null, func()];
|
|
2668
|
+
} catch (error) {
|
|
2669
|
+
return [error, null];
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/util/attemptAsync.mjs
|
|
2674
|
+
function attemptAsync(func) {
|
|
2675
|
+
return __async(this, null, function* () {
|
|
2676
|
+
try {
|
|
2677
|
+
const result = yield func();
|
|
2678
|
+
return [null, result];
|
|
2679
|
+
} catch (error) {
|
|
2680
|
+
return [error, null];
|
|
2681
|
+
}
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/util/invariant.mjs
|
|
2686
|
+
function invariant(condition, message) {
|
|
2687
|
+
if (condition) {
|
|
2688
|
+
return;
|
|
2689
|
+
}
|
|
2690
|
+
if (typeof message === "string") {
|
|
2691
|
+
throw new Error(message);
|
|
2692
|
+
}
|
|
2693
|
+
throw message;
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
// src/ts/buffer/SSEParser.ts
|
|
2697
|
+
var SSEParser = class {
|
|
2698
|
+
constructor(onMessage) {
|
|
2699
|
+
__publicField(this, "buffer", "");
|
|
2700
|
+
__publicField(this, "onMessage");
|
|
2701
|
+
__publicField(this, "decoder");
|
|
2702
|
+
__publicField(this, "eventDataLines", []);
|
|
2703
|
+
__publicField(this, "eventType");
|
|
2704
|
+
__publicField(this, "eventId");
|
|
2705
|
+
__publicField(this, "eventRetry");
|
|
2706
|
+
this.onMessage = onMessage;
|
|
2707
|
+
this.decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8") : new PolyfillTextDecoder_default();
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* 接收流式数据
|
|
2711
|
+
* @param buffer ArrayBuffer
|
|
2712
|
+
*/
|
|
2713
|
+
receive(buffer) {
|
|
2714
|
+
const text = this.decoder.decode(new Uint8Array(buffer), { stream: true });
|
|
2715
|
+
this.appendText(text);
|
|
2716
|
+
}
|
|
2717
|
+
/**
|
|
2718
|
+
* 刷新解码器残留数据并处理尾部未换行的内容
|
|
2719
|
+
*/
|
|
2720
|
+
flush() {
|
|
2721
|
+
const tail2 = this.decoder.decode(void 0, { stream: false });
|
|
2722
|
+
if (tail2) this.appendText(tail2);
|
|
2723
|
+
this.flushRemainder();
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* 追加文本并按行拆分处理,保留不完整尾行
|
|
2727
|
+
* @param text 新到达的文本片段
|
|
2728
|
+
*/
|
|
2729
|
+
appendText(text) {
|
|
2730
|
+
this.buffer += text;
|
|
2731
|
+
const lines = this.buffer.split(/\r?\n/);
|
|
2732
|
+
this.buffer = lines.pop() || "";
|
|
2733
|
+
this.processLines(lines);
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* 处理缓冲区中剩余的尾行内容
|
|
2737
|
+
*/
|
|
2738
|
+
flushRemainder() {
|
|
2739
|
+
if (!this.buffer.trim()) {
|
|
2740
|
+
this.buffer = "";
|
|
2741
|
+
return;
|
|
2742
|
+
}
|
|
2743
|
+
const rest2 = this.buffer;
|
|
2744
|
+
this.buffer = "";
|
|
2745
|
+
this.processLines([rest2, ""]);
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* 解析每行 SSE 数据并触发回调
|
|
2749
|
+
* @param lines 以换行切分后的行内容
|
|
2750
|
+
*/
|
|
2751
|
+
processLines(lines) {
|
|
2752
|
+
for (const line of lines) {
|
|
2753
|
+
if (!line.trim()) {
|
|
2754
|
+
this.dispatchEvent();
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
if (line.startsWith(":")) continue;
|
|
2758
|
+
const colonIndex = line.indexOf(":");
|
|
2759
|
+
const field = colonIndex === -1 ? line : line.slice(0, colonIndex);
|
|
2760
|
+
let value = colonIndex === -1 ? "" : line.slice(colonIndex + 1);
|
|
2761
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
2762
|
+
if (field === "data") {
|
|
2763
|
+
this.eventDataLines.push(value);
|
|
2764
|
+
continue;
|
|
2765
|
+
}
|
|
2766
|
+
if (field === "event") {
|
|
2767
|
+
this.eventType = value || void 0;
|
|
2768
|
+
continue;
|
|
2769
|
+
}
|
|
2770
|
+
if (field === "id") {
|
|
2771
|
+
this.eventId = value || void 0;
|
|
2772
|
+
continue;
|
|
2773
|
+
}
|
|
2774
|
+
if (field === "retry") {
|
|
2775
|
+
const retry2 = Number(value);
|
|
2776
|
+
this.eventRetry = Number.isFinite(retry2) ? retry2 : void 0;
|
|
2777
|
+
continue;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* 将当前缓存的一次 SSE 事件分发给回调
|
|
2783
|
+
* @description 以空行作为事件边界,将多行 data 合并后再解析;处理 "[DONE]" 结束标记;分发完成后会重置事件缓存
|
|
2784
|
+
*/
|
|
2785
|
+
dispatchEvent() {
|
|
2786
|
+
if (!this.eventDataLines.length) {
|
|
2787
|
+
this.resetEvent();
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
const data = this.eventDataLines.join("\n");
|
|
2791
|
+
if (!data) {
|
|
2792
|
+
this.resetEvent();
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
if (data.trim() === "[DONE]") {
|
|
2796
|
+
this.safeOnMessage({ type: "DONE" });
|
|
2797
|
+
this.resetEvent();
|
|
2798
|
+
return;
|
|
2799
|
+
}
|
|
2800
|
+
let msg;
|
|
2801
|
+
try {
|
|
2802
|
+
const json = JSON.parse(data);
|
|
2803
|
+
msg = isPlainObject(json) ? json : { data: json };
|
|
2804
|
+
} catch (e) {
|
|
2805
|
+
msg = { raw: data };
|
|
2806
|
+
}
|
|
2807
|
+
if (this.eventType && msg.event === void 0) msg.event = this.eventType;
|
|
2808
|
+
if (this.eventType && msg.type === void 0) msg.type = this.eventType;
|
|
2809
|
+
if (this.eventId && msg.id === void 0) msg.id = this.eventId;
|
|
2810
|
+
if (this.eventRetry !== void 0 && msg.retry === void 0) msg.retry = this.eventRetry;
|
|
2811
|
+
this.safeOnMessage(msg);
|
|
2812
|
+
this.resetEvent();
|
|
2813
|
+
}
|
|
2814
|
+
/** 安全调用 onMessage 回调,捕获并打印错误 */
|
|
2815
|
+
safeOnMessage(msg) {
|
|
2816
|
+
try {
|
|
2817
|
+
this.onMessage(msg);
|
|
2818
|
+
} catch (onMessageError) {
|
|
2819
|
+
console.error("SSEParser onMessage error:", onMessageError);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
/** 重置当前 SSE 事件的临时缓存 */
|
|
2823
|
+
resetEvent() {
|
|
2824
|
+
this.eventDataLines = [];
|
|
2825
|
+
this.eventType = void 0;
|
|
2826
|
+
this.eventId = void 0;
|
|
2827
|
+
this.eventRetry = void 0;
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2830
|
+
|
|
2831
|
+
// src/ts/day/index.ts
|
|
2832
|
+
import dayjs from "dayjs";
|
|
2833
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
2834
|
+
import utc from "dayjs/plugin/utc.js";
|
|
2835
|
+
import timezone from "dayjs/plugin/timezone.js";
|
|
2836
|
+
import relativeTime from "dayjs/plugin/relativeTime.js";
|
|
2837
|
+
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
2838
|
+
import "dayjs/locale/zh-cn.js";
|
|
2839
|
+
|
|
2840
|
+
// src/ts/number/big.ts
|
|
2841
|
+
import BigNumber from "bignumber.js";
|
|
2842
|
+
function big(x) {
|
|
2843
|
+
return x instanceof BigNumber ? x : new BigNumber(x);
|
|
2844
|
+
}
|
|
2845
|
+
function mathPlus(...rest2) {
|
|
2846
|
+
let acc = big(rest2[0]);
|
|
2847
|
+
for (const x of rest2.slice(1)) acc = acc.plus(big(x));
|
|
2848
|
+
return acc.toNumber();
|
|
2849
|
+
}
|
|
2850
|
+
function mathMinus(...rest2) {
|
|
2851
|
+
let acc = big(rest2[0]);
|
|
2852
|
+
for (const x of rest2.slice(1)) acc = acc.minus(big(x));
|
|
2853
|
+
return acc.toNumber();
|
|
2854
|
+
}
|
|
2855
|
+
function mathTimes(...rest2) {
|
|
2856
|
+
let acc = big(rest2[0]);
|
|
2857
|
+
for (const x of rest2.slice(1)) acc = acc.times(big(x));
|
|
2858
|
+
return acc.toNumber();
|
|
2859
|
+
}
|
|
2860
|
+
function mathDiv(...rest2) {
|
|
2861
|
+
let acc = big(rest2[0]);
|
|
2862
|
+
for (const x of rest2.slice(1)) acc = acc.div(big(x));
|
|
2863
|
+
return acc.toNumber();
|
|
2864
|
+
}
|
|
2865
|
+
function mathPow(x, y) {
|
|
2866
|
+
return big(x).pow(big(y)).toNumber();
|
|
2867
|
+
}
|
|
2868
|
+
function mathRound(x, dp = 0, rm = BigNumber.ROUND_HALF_UP) {
|
|
2869
|
+
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
2870
|
+
}
|
|
2871
|
+
function mathFixed(x, dp = 2, rm = BigNumber.ROUND_HALF_UP) {
|
|
2872
|
+
return big(x).toFixed(dp, rm);
|
|
2873
|
+
}
|
|
2874
|
+
function mathCompare(a, b) {
|
|
2875
|
+
return big(a).comparedTo(big(b));
|
|
2876
|
+
}
|
|
2877
|
+
function mathEqual(a, b) {
|
|
2878
|
+
return big(a).isEqualTo(big(b));
|
|
2879
|
+
}
|
|
2880
|
+
function mathGreaterThan(a, b) {
|
|
2881
|
+
return big(a).isGreaterThan(big(b));
|
|
2882
|
+
}
|
|
2883
|
+
function mathGreaterThanOrEqual(a, b) {
|
|
2884
|
+
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
2885
|
+
}
|
|
2886
|
+
function mathLessThan(a, b) {
|
|
2887
|
+
return big(a).isLessThan(big(b));
|
|
2888
|
+
}
|
|
2889
|
+
function mathLessThanOrEqual(a, b) {
|
|
2890
|
+
return big(a).isLessThanOrEqualTo(big(b));
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
// src/ts/number/format.ts
|
|
2894
|
+
function zeroPad(n, len = 2) {
|
|
2895
|
+
return String(n).padStart(len, "0");
|
|
2896
|
+
}
|
|
2897
|
+
function withUnit(num, unit = "") {
|
|
2898
|
+
if (num === null || num === void 0 || num === "") return "";
|
|
2899
|
+
if (typeof num === "number") return `${num}${unit}`;
|
|
2900
|
+
const str = String(num).trim();
|
|
2901
|
+
if (str === "") return "";
|
|
2902
|
+
return isNaN(+str) ? str : `${str}${unit}`;
|
|
2903
|
+
}
|
|
2904
|
+
function withUnitPx(num) {
|
|
2905
|
+
return withUnit(num, "px");
|
|
2906
|
+
}
|
|
2907
|
+
function withDistance(m) {
|
|
2908
|
+
const n = Number(m != null ? m : 0);
|
|
2909
|
+
if (!Number.isFinite(n)) return "0m";
|
|
2910
|
+
return n >= 1e3 ? `${+(n / 1e3).toFixed(2)}km` : `${+n.toFixed(2)}m`;
|
|
2911
|
+
}
|
|
2912
|
+
function toThousandth(str) {
|
|
2913
|
+
const v = String(str != null ? str : "").trim();
|
|
2914
|
+
if (v === "") return "";
|
|
2915
|
+
let sign = "";
|
|
2916
|
+
let num = v;
|
|
2917
|
+
if (num[0] === "-" || num[0] === "+") {
|
|
2918
|
+
sign = num[0];
|
|
2919
|
+
num = num.slice(1);
|
|
2920
|
+
}
|
|
2921
|
+
const [intPart, decPart] = num.split(".");
|
|
2922
|
+
const groupedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
2923
|
+
return decPart !== void 0 && decPart !== "" ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;
|
|
2924
|
+
}
|
|
2925
|
+
function toChineseNum(num) {
|
|
2926
|
+
const numInt = Math.trunc(+num);
|
|
2927
|
+
if (numInt === 0) return "\u96F6";
|
|
2928
|
+
const digit = ["\u96F6", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D"];
|
|
2929
|
+
const unit = ["", "\u5341", "\u767E", "\u5343"];
|
|
2930
|
+
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
2931
|
+
const section4 = (n2) => {
|
|
2932
|
+
let str = "", zeroFlag = false;
|
|
2933
|
+
for (let i = 0; i < 4; i++) {
|
|
2934
|
+
const d = n2 % 10;
|
|
2935
|
+
n2 = Math.floor(n2 / 10);
|
|
2936
|
+
if (d === 0) {
|
|
2937
|
+
zeroFlag = true;
|
|
2938
|
+
continue;
|
|
2748
2939
|
}
|
|
2749
|
-
|
|
2940
|
+
if (zeroFlag) str = digit[0] + str;
|
|
2941
|
+
str = digit[d] + unit[i] + str;
|
|
2942
|
+
zeroFlag = false;
|
|
2750
2943
|
}
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2944
|
+
return str;
|
|
2945
|
+
};
|
|
2946
|
+
let res = "";
|
|
2947
|
+
let sectionIndex = 0;
|
|
2948
|
+
let n = Math.abs(numInt);
|
|
2949
|
+
while (n > 0) {
|
|
2950
|
+
const seg = n % 1e4;
|
|
2951
|
+
n = Math.floor(n / 1e4);
|
|
2952
|
+
if (seg) {
|
|
2953
|
+
const segStr = section4(seg);
|
|
2954
|
+
res = segStr + (sectionIndex ? bigUnit[sectionIndex] : "") + res;
|
|
2955
|
+
} else if (res && !res.startsWith("\u96F6")) {
|
|
2956
|
+
res = `\u96F6${res}`;
|
|
2755
2957
|
}
|
|
2958
|
+
sectionIndex++;
|
|
2756
2959
|
}
|
|
2757
|
-
|
|
2960
|
+
res = res.replace(/^一十/, "\u5341");
|
|
2961
|
+
return numInt < 0 ? `\u8D1F${res}` : res;
|
|
2758
2962
|
}
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2963
|
+
function toChineseCurrency(amount, opts = {}) {
|
|
2964
|
+
var _a, _b, _c;
|
|
2965
|
+
const dp = (_a = opts.precision) != null ? _a : 2;
|
|
2966
|
+
const rm = (_b = opts.rm) != null ? _b : BigNumber.ROUND_HALF_UP;
|
|
2967
|
+
const yuan = (_c = opts.yuanChar) != null ? _c : "\u5143";
|
|
2968
|
+
if (amount === null || amount === void 0) return "";
|
|
2969
|
+
const bn = new BigNumber(amount);
|
|
2970
|
+
if (!bn.isFinite()) return "";
|
|
2971
|
+
const s = bn.toFixed(dp, rm);
|
|
2972
|
+
const sign = s.startsWith("-") ? "\u8D1F" : "";
|
|
2973
|
+
const [intStr, decStr = ""] = s.replace(/^-/, "").split(".");
|
|
2974
|
+
const digit = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
2975
|
+
const unit = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
2976
|
+
const bigUnit = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
2977
|
+
const smallUnit = ["\u89D2", "\u5206", "\u5398"];
|
|
2978
|
+
const section4 = (n) => {
|
|
2979
|
+
let str = "";
|
|
2980
|
+
let zeroFlag = false;
|
|
2981
|
+
for (let i = 0; i < 4; i++) {
|
|
2982
|
+
const d = n.mod(10).toNumber();
|
|
2983
|
+
n = n.idiv(10);
|
|
2984
|
+
if (d === 0) {
|
|
2985
|
+
zeroFlag = true;
|
|
2986
|
+
continue;
|
|
2770
2987
|
}
|
|
2771
|
-
|
|
2988
|
+
if (zeroFlag) str = digit[0] + str;
|
|
2989
|
+
str = digit[d] + unit[i] + str;
|
|
2990
|
+
zeroFlag = false;
|
|
2772
2991
|
}
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2992
|
+
return str.replace(/零+$/g, "");
|
|
2993
|
+
};
|
|
2994
|
+
const intNum = new BigNumber(intStr);
|
|
2995
|
+
let res = "";
|
|
2996
|
+
if (intNum.isZero()) {
|
|
2997
|
+
res = digit[0];
|
|
2998
|
+
} else {
|
|
2999
|
+
let n = intNum.abs();
|
|
3000
|
+
let sectionIndex = 0;
|
|
3001
|
+
while (n.gt(0)) {
|
|
3002
|
+
const seg = n.mod(1e4);
|
|
3003
|
+
n = n.idiv(1e4);
|
|
3004
|
+
if (seg.gt(0)) {
|
|
3005
|
+
const segStr = section4(seg);
|
|
3006
|
+
const needZero = res && !res.startsWith(digit[0]) && (seg.lt(1e3) || seg.mod(1e3).isZero());
|
|
3007
|
+
const bu = sectionIndex ? bigUnit[sectionIndex] : "";
|
|
3008
|
+
res = segStr + bu + (needZero ? digit[0] : "") + res;
|
|
3009
|
+
} else if (res && !res.startsWith(digit[0])) {
|
|
3010
|
+
res = digit[0] + res;
|
|
2776
3011
|
}
|
|
3012
|
+
sectionIndex++;
|
|
2777
3013
|
}
|
|
3014
|
+
res = res.replace(/^壹拾/, "\u62FE");
|
|
2778
3015
|
}
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
if (chars === void 0) {
|
|
2785
|
-
return str.trim();
|
|
3016
|
+
let frac = "";
|
|
3017
|
+
for (let i = 0; i < Math.min(3, dp); i++) {
|
|
3018
|
+
const ch = decStr[i] || "0";
|
|
3019
|
+
const d = ch.charCodeAt(0) - 48;
|
|
3020
|
+
if (d > 0) frac += digit[d] + smallUnit[i];
|
|
2786
3021
|
}
|
|
2787
|
-
return
|
|
3022
|
+
return frac ? `${sign}${res}${yuan}${frac}` : `${sign}${res}${yuan}\u6574`;
|
|
2788
3023
|
}
|
|
2789
3024
|
|
|
2790
|
-
//
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
"<": "<",
|
|
2794
|
-
">": ">",
|
|
2795
|
-
""": '"',
|
|
2796
|
-
"'": "'"
|
|
2797
|
-
};
|
|
2798
|
-
function unescape2(str) {
|
|
2799
|
-
return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (match) => htmlUnescapes[match] || "'");
|
|
3025
|
+
// src/ts/number/random.ts
|
|
3026
|
+
function randomBoolean() {
|
|
3027
|
+
return Math.random() < 0.5;
|
|
2800
3028
|
}
|
|
2801
3029
|
|
|
2802
|
-
//
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
3030
|
+
// src/ts/day/index.ts
|
|
3031
|
+
dayjs.extend(customParseFormat);
|
|
3032
|
+
dayjs.extend(utc);
|
|
3033
|
+
dayjs.extend(timezone);
|
|
3034
|
+
dayjs.extend(relativeTime);
|
|
3035
|
+
dayjs.extend(advancedFormat);
|
|
3036
|
+
dayjs.locale("zh-cn");
|
|
3037
|
+
function toDayjs(t, fmt) {
|
|
3038
|
+
if (t === null || t === void 0) return dayjs();
|
|
3039
|
+
if (typeof t === "number") {
|
|
3040
|
+
const s = String(Math.trunc(t));
|
|
3041
|
+
return dayjs(s.length === 10 ? t * 1e3 : t, fmt);
|
|
2811
3042
|
}
|
|
2812
|
-
|
|
3043
|
+
if (typeof t === "string") {
|
|
3044
|
+
const s = t.trim();
|
|
3045
|
+
if (/^\d{10}$/.test(s)) return dayjs(Number(s) * 1e3, fmt);
|
|
3046
|
+
if (/^\d{13}$/.test(s)) return dayjs(Number(s), fmt);
|
|
3047
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY-MM-DD");
|
|
3048
|
+
if (/^\d{4}\/\d{2}\/\d{2}$/.test(s)) return dayjs(s, fmt || "YYYY/MM/DD");
|
|
3049
|
+
if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
3050
|
+
return dayjs(s, fmt || "YYYY-MM-DD HH:mm:ss");
|
|
3051
|
+
if (/^\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s))
|
|
3052
|
+
return dayjs(s, fmt || "YYYY/MM/DD HH:mm:ss");
|
|
3053
|
+
return dayjs(s, fmt);
|
|
3054
|
+
}
|
|
3055
|
+
return dayjs(t, fmt);
|
|
2813
3056
|
}
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
3057
|
+
function getDateRangeBefore(offset, fmt = "YYYY-MM-DD") {
|
|
3058
|
+
const now = toDayjs(Date.now());
|
|
3059
|
+
const n = Math.max(0, Math.trunc(offset));
|
|
3060
|
+
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
3061
|
+
const startDay = now.add(-n, "day");
|
|
3062
|
+
const endDay = now;
|
|
3063
|
+
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
3064
|
+
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
3065
|
+
return [start, end];
|
|
2818
3066
|
}
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
3067
|
+
function getDateRangeAfter(offset, fmt = "YYYY-MM-DD") {
|
|
3068
|
+
const now = toDayjs(Date.now());
|
|
3069
|
+
const n = Math.max(0, Math.trunc(offset));
|
|
3070
|
+
const hasTime = /H|h|m|s|S|A|a|x|X/.test(fmt);
|
|
3071
|
+
const startDay = now;
|
|
3072
|
+
const endDay = now.add(n, "day");
|
|
3073
|
+
const start = (hasTime ? startDay.startOf("day") : startDay).format(fmt);
|
|
3074
|
+
const end = (hasTime ? endDay.endOf("day") : endDay).format(fmt);
|
|
3075
|
+
return [start, end];
|
|
2827
3076
|
}
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
3077
|
+
function getCountdownParts(diff) {
|
|
3078
|
+
if (diff <= 0) return { d: "00", h: "00", m: "00", s: "00", ms: "000" };
|
|
3079
|
+
const d = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
3080
|
+
const h = Math.floor(diff / (1e3 * 60 * 60) % 24);
|
|
3081
|
+
const m = Math.floor(diff / (1e3 * 60) % 60);
|
|
3082
|
+
const s = Math.floor(diff / 1e3 % 60);
|
|
3083
|
+
const ms = diff % 1e3;
|
|
3084
|
+
return {
|
|
3085
|
+
d: zeroPad(d),
|
|
3086
|
+
h: zeroPad(h),
|
|
3087
|
+
m: zeroPad(m),
|
|
3088
|
+
s: zeroPad(s),
|
|
3089
|
+
ms: zeroPad(ms, 3)
|
|
3090
|
+
};
|
|
2839
3091
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
3092
|
+
function getAgeByBirthdate(birthdate) {
|
|
3093
|
+
const birth = toDayjs(birthdate, "YYYY-MM-DD");
|
|
3094
|
+
const now = toDayjs(Date.now());
|
|
3095
|
+
const totalMonths = (now.year() - birth.year()) * 12 + (now.month() - birth.month());
|
|
3096
|
+
const adjustedMonths = now.date() < birth.date() ? totalMonths - 1 : totalMonths;
|
|
3097
|
+
if (adjustedMonths >= 12) {
|
|
3098
|
+
let age = Math.floor(adjustedMonths / 12);
|
|
3099
|
+
const birthdayThisYear = birth.add(age, "year");
|
|
3100
|
+
if (now.isBefore(birthdayThisYear)) {
|
|
3101
|
+
age--;
|
|
3102
|
+
}
|
|
3103
|
+
return { age, type: "year" };
|
|
2848
3104
|
}
|
|
2849
|
-
|
|
3105
|
+
return { age: adjustedMonths, type: "month" };
|
|
2850
3106
|
}
|
|
2851
3107
|
|
|
2852
3108
|
// node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs
|
|
@@ -3680,6 +3936,7 @@ export {
|
|
|
3680
3936
|
BigNumber,
|
|
3681
3937
|
EventBus,
|
|
3682
3938
|
Mutex,
|
|
3939
|
+
SSEParser,
|
|
3683
3940
|
Semaphore,
|
|
3684
3941
|
TimeoutError,
|
|
3685
3942
|
after,
|