@ivujs/i-utils 2.1.2 → 2.1.4
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/cjs/color/index.cjs +3 -3
- package/dist/cjs/crypto/base64/base64.cjs +4 -4
- package/dist/cjs/crypto/md5/index.cjs +2 -2
- package/dist/cjs/crypto/sha256/index.cjs +4 -4
- package/dist/cjs/crypto/sm3/index.cjs +1 -1
- package/dist/cjs/crypto/sm3/sm3.cjs +1 -1
- package/dist/cjs/crypto/sm4/index.cjs +5 -5
- package/dist/cjs/crypto/sm4/sm4.cjs +11 -11
- package/dist/cjs/date/index.cjs +8 -7
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/math/index.cjs +6 -6
- package/dist/cjs/string/index.cjs +9 -9
- package/dist/es/color/index.mjs +3 -3
- package/dist/es/crypto/base64/base64.mjs +4 -4
- package/dist/es/crypto/md5/index.mjs +2 -2
- package/dist/es/crypto/sha256/index.mjs +4 -4
- package/dist/es/crypto/sm3/index.mjs +1 -1
- package/dist/es/crypto/sm3/sm3.mjs +1 -1
- package/dist/es/crypto/sm4/index.mjs +5 -5
- package/dist/es/crypto/sm4/sm4.mjs +11 -11
- package/dist/es/date/index.d.ts +1 -1
- package/dist/es/date/index.mjs +8 -7
- package/dist/es/index.mjs +1 -1
- package/dist/es/math/index.mjs +6 -6
- package/dist/es/string/index.mjs +9 -9
- package/dist/index.d.ts +2 -2
- package/dist/lib/index.full.umd.js +55 -54
- package/dist/lib/index.full.umd.min.js +2 -2
- package/dist/lib/index.full.umd.min.js.map +1 -1
- package/dist/resolver/auto-imports.cjs +1 -1
- package/dist/resolver/auto-imports.mjs +1 -1
- package/package.json +96 -96
|
@@ -48,7 +48,7 @@ const FK = new Uint32Array([0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc]);
|
|
|
48
48
|
function hexToUint8Array(str) {
|
|
49
49
|
str = str.replace(/\s+/g, ""); // 去除空格
|
|
50
50
|
if (str.length % 2 !== 0)
|
|
51
|
-
throw new
|
|
51
|
+
throw new TypeError("hexToUint8Array: hex string length must be even from sm4");
|
|
52
52
|
const arr = new Uint8Array(str.length / 2);
|
|
53
53
|
for (let i = 0; i < str.length; i += 2) {
|
|
54
54
|
arr[i / 2] = parseInt(str.substr(i, 2), 16) & 0xff;
|
|
@@ -110,7 +110,7 @@ function normalizeInput(input, cryptFlag) {
|
|
|
110
110
|
return hexToUint8Array(input);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
throw new
|
|
113
|
+
throw new TypeError(`normalizeInput: unsupported input type: ${typeof input} from sm4`);
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
116
|
* 标准化密钥/IV为Uint8Array
|
|
@@ -134,10 +134,10 @@ function normalizeKeyIv(keyOrIv, expectedLength, name) {
|
|
|
134
134
|
arr = new Uint8Array(keyOrIv);
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
|
-
throw new
|
|
137
|
+
throw new TypeError(`normalizeKeyIv: unsupported ${name} type: ${typeof keyOrIv} from sm4`);
|
|
138
138
|
}
|
|
139
139
|
if (arr.length !== expectedLength) {
|
|
140
|
-
throw new
|
|
140
|
+
throw new TypeError(`normalizeKeyIv: ${name} must be ${expectedLength * 8} bits (${expectedLength} bytes) from sm4`);
|
|
141
141
|
}
|
|
142
142
|
return arr;
|
|
143
143
|
}
|
|
@@ -189,7 +189,7 @@ function linearTransformKey(b) {
|
|
|
189
189
|
function sm4BlockCrypt(inputBlock, outputBlock, roundKeys) {
|
|
190
190
|
// 确保输入块是16字节
|
|
191
191
|
if (inputBlock.length !== BLOCK_SIZE) {
|
|
192
|
-
throw new
|
|
192
|
+
throw new TypeError(`sm4BlockCrypt: input block must be ${BLOCK_SIZE} bytes for block crypt from sm4`);
|
|
193
193
|
}
|
|
194
194
|
// 字节数组转32比特字数组(4个字,共128比特)
|
|
195
195
|
const x = new Uint32Array(4);
|
|
@@ -284,7 +284,7 @@ function pkcs7Unpad(data) {
|
|
|
284
284
|
// 验证填充合法性
|
|
285
285
|
for (let i = 1; i <= paddingCount; i++) {
|
|
286
286
|
if (data[data.length - i] !== paddingCount) {
|
|
287
|
-
throw new
|
|
287
|
+
throw new TypeError("pkcs7Unpad: invalid PKCS#7 padding from sm4");
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
return data.subarray(0, data.length - paddingCount);
|
|
@@ -307,7 +307,7 @@ function sm4Core(inputData, key, cryptFlag, options = {}) {
|
|
|
307
307
|
} = options;
|
|
308
308
|
// 校验模式
|
|
309
309
|
if (![SM4_MODE_ECB, SM4_MODE_CBC].includes(mode)) {
|
|
310
|
-
throw new
|
|
310
|
+
throw new TypeError(`sm4Core: unsupported mode: ${mode}, only 'ecb' and 'cbc' are supported from sm4`);
|
|
311
311
|
}
|
|
312
312
|
// 标准化输入、密钥、IV
|
|
313
313
|
const input = normalizeInput(inputData, cryptFlag);
|
|
@@ -322,7 +322,7 @@ function sm4Core(inputData, key, cryptFlag, options = {}) {
|
|
|
322
322
|
processedInput = pkcs7Pad(input);
|
|
323
323
|
// 确保填充后是16字节的倍数
|
|
324
324
|
if (processedInput.length % BLOCK_SIZE !== 0) {
|
|
325
|
-
throw new
|
|
325
|
+
throw new TypeError("sm4Core: PKCS7 padding failed: data length is not multiple of block size from sm4");
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
// 生成轮密钥
|
|
@@ -382,7 +382,7 @@ function sm4Core(inputData, key, cryptFlag, options = {}) {
|
|
|
382
382
|
case SM4_OUTPUT_ARRAYBUFFER:
|
|
383
383
|
return finalOutput.buffer;
|
|
384
384
|
default:
|
|
385
|
-
throw new
|
|
385
|
+
throw new TypeError(`sm4Core: unsupported output format: ${output} from sm4`);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
// ========== 便捷API(函数式,符合设计准则) ==========
|
|
@@ -394,7 +394,7 @@ function sm4Core(inputData, key, cryptFlag, options = {}) {
|
|
|
394
394
|
function generateIv(outputFormat = SM4_OUTPUT_HEX) {
|
|
395
395
|
// 1. 校验浏览器是否支持 crypto
|
|
396
396
|
if (!window?.crypto?.getRandomValues) {
|
|
397
|
-
throw new
|
|
397
|
+
throw new TypeError("generateIv: your browser does not support secure random generation (crypto API) from sm4");
|
|
398
398
|
}
|
|
399
399
|
// 2. 生成 16 字节安全随机数
|
|
400
400
|
const ivUint8 = new Uint8Array(IV_SIZE);
|
|
@@ -425,7 +425,7 @@ function generateIv(outputFormat = SM4_OUTPUT_HEX) {
|
|
|
425
425
|
function generateKey(outputFormat = SM4_OUTPUT_HEX) {
|
|
426
426
|
// 校验浏览器/Node环境的安全随机数API
|
|
427
427
|
if (!window?.crypto?.getRandomValues && !global?.crypto?.getRandomValues) {
|
|
428
|
-
throw new
|
|
428
|
+
throw new TypeError("generateKey: the current environment does not support secure random number generation. please upgrade your browser/Node.js from sm4");
|
|
429
429
|
}
|
|
430
430
|
// 生成16字节随机数(SM4密钥固定16字节)
|
|
431
431
|
const cryptoObj = window?.crypto || global?.crypto;
|
package/dist/es/date/index.d.ts
CHANGED
|
@@ -619,7 +619,7 @@ export declare function toDateUTC(date?: Date): Date;
|
|
|
619
619
|
* const localDate = new Date('2025-01-26 08:00:00');
|
|
620
620
|
* console.log(toUTCString(localDate)); // 2025-01-26 00:00:00
|
|
621
621
|
*/
|
|
622
|
-
export declare function
|
|
622
|
+
export declare function toDateUTCString(date?: Date, options?: DateOptions): string;
|
|
623
623
|
/**
|
|
624
624
|
* 日期字符串转为日期对象
|
|
625
625
|
* @description 支持日期字符串,时间戳,Unix时间戳
|
package/dist/es/date/index.mjs
CHANGED
|
@@ -1104,7 +1104,7 @@ function toDateUTC(date = new Date()) {
|
|
|
1104
1104
|
* const localDate = new Date('2025-01-26 08:00:00');
|
|
1105
1105
|
* console.log(toUTCString(localDate)); // 2025-01-26 00:00:00
|
|
1106
1106
|
*/
|
|
1107
|
-
function
|
|
1107
|
+
function toDateUTCString(date = new Date(), options = { format: "yyyy-MM-dd HH:mm:ss" }) {
|
|
1108
1108
|
const utcDate = toDateUTC(date);
|
|
1109
1109
|
return toDateString(utcDate, options);
|
|
1110
1110
|
}
|
|
@@ -1115,8 +1115,9 @@ function toDataUTCString(date = new Date(), options = { format: "yyyy-MM-dd HH:m
|
|
|
1115
1115
|
* @returns {Date} 返回日期对象
|
|
1116
1116
|
*/
|
|
1117
1117
|
function toDate(value) {
|
|
1118
|
+
// 为空抛出异常
|
|
1118
1119
|
if (isNull(value)) {
|
|
1119
|
-
throw new TypeError("value
|
|
1120
|
+
throw new TypeError("toDate: value cannot be null or undefined");
|
|
1120
1121
|
}
|
|
1121
1122
|
// 是日期字符串
|
|
1122
1123
|
if (isString(value)) {
|
|
@@ -1132,7 +1133,7 @@ function toDate(value) {
|
|
|
1132
1133
|
}
|
|
1133
1134
|
// 不支持的日期格式
|
|
1134
1135
|
else {
|
|
1135
|
-
throw new
|
|
1136
|
+
throw new TypeError(`toDate: invalid input type: ${typeof value}, expected string or number`);
|
|
1136
1137
|
}
|
|
1137
1138
|
}
|
|
1138
1139
|
/**
|
|
@@ -1144,13 +1145,13 @@ function toDate(value) {
|
|
|
1144
1145
|
*/
|
|
1145
1146
|
function toDateString(date, options = { format: "yyyy-MM-dd", lang: "zh" }) {
|
|
1146
1147
|
const { format = "yyyy-MM-dd", lang = "zh" } = options;
|
|
1148
|
+
// 为空抛出异常
|
|
1147
1149
|
if (isNull(date)) {
|
|
1148
|
-
throw new TypeError("date
|
|
1150
|
+
throw new TypeError("toDateString: date cannot be null or undefined");
|
|
1149
1151
|
}
|
|
1150
1152
|
// 判断是否是日期对象
|
|
1151
1153
|
if (!isDate(date)) {
|
|
1152
|
-
|
|
1153
|
-
return "";
|
|
1154
|
+
throw new TypeError(`toDateString: invalid input type: ${typeof date}, expected Date object`);
|
|
1154
1155
|
}
|
|
1155
1156
|
// 日期转化替换
|
|
1156
1157
|
const replaceRules = {
|
|
@@ -1244,4 +1245,4 @@ function _datePadZero(value) {
|
|
|
1244
1245
|
return num > 9 ? String(num) : "0" + num;
|
|
1245
1246
|
}
|
|
1246
1247
|
|
|
1247
|
-
export { addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addWeek, addYear, fromDateUTC, getAge, getBetweenDates, getBetweenMonths, getBetweenYears, getChineseZodiac, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getNow, getOverTime, getPastTime, getQuarter, getTimestamp, getUnixTimestamp, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, isAM, isAfter, isAfterTomorrow, isBefore, isBeforeYesterday, isBetween, isCommonYear, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isPM, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isToday, isTomorrow, isWeekend, isWorkday, isYesterday, lastMonth, lastWeek, lastYear, nextMonth, nextWeek, nextYear,
|
|
1248
|
+
export { addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addWeek, addYear, fromDateUTC, getAge, getBetweenDates, getBetweenMonths, getBetweenYears, getChineseZodiac, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getNow, getOverTime, getPastTime, getQuarter, getTimestamp, getUnixTimestamp, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, isAM, isAfter, isAfterTomorrow, isBefore, isBeforeYesterday, isBetween, isCommonYear, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isPM, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isToday, isTomorrow, isWeekend, isWorkday, isYesterday, lastMonth, lastWeek, lastYear, nextMonth, nextWeek, nextYear, toDate, toDateString, toDateUTC, toDateUTCString, today, tomorrow, yesterday };
|
package/dist/es/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export { parseFloat, parseInt } from './number/index.mjs';
|
|
|
10
10
|
export { arrayAvg, arrayBottom, arrayComplement, arrayCreate, arrayDifference, arrayDown, arrayEquals, arrayInsert, arrayInsertAfter, arrayInsertBefore, arrayIntersect, arrayMax, arrayMin, arrayRemove, arrayRemoveAfter, arrayRemoveBefore, arrayShuffle, arraySort, arraySortBy, arraySum, arraySwap, arrayToTree, arrayTop, arrayUnion, arrayUnique, arrayUp, inArray, treeToArray } from './array/index.mjs';
|
|
11
11
|
export { clone, deepClone, getValueByPath, jsonToMap, mapToJson, mapToObject, merge, objectEquals, objectToMap, parseJson, setValueByPath, stringifyJson } from './object/index.mjs';
|
|
12
12
|
export { debounce, sleep, throttle } from './function/index.mjs';
|
|
13
|
-
export { addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addWeek, addYear, fromDateUTC, getAge, getBetweenDates, getBetweenMonths, getBetweenYears, getChineseZodiac, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getNow, getOverTime, getPastTime, getQuarter, getTimestamp, getUnixTimestamp, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, isAM, isAfter, isAfterTomorrow, isBefore, isBeforeYesterday, isBetween, isCommonYear, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isPM, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isToday, isTomorrow, isWeekend, isWorkday, isYesterday, lastMonth, lastWeek, lastYear, nextMonth, nextWeek, nextYear,
|
|
13
|
+
export { addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addWeek, addYear, fromDateUTC, getAge, getBetweenDates, getBetweenMonths, getBetweenYears, getChineseZodiac, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getNow, getOverTime, getPastTime, getQuarter, getTimestamp, getUnixTimestamp, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, isAM, isAfter, isAfterTomorrow, isBefore, isBeforeYesterday, isBetween, isCommonYear, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isPM, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isToday, isTomorrow, isWeekend, isWorkday, isYesterday, lastMonth, lastWeek, lastYear, nextMonth, nextWeek, nextYear, toDate, toDateString, toDateUTC, toDateUTCString, today, tomorrow, yesterday } from './date/index.mjs';
|
|
14
14
|
export { add, divide, gcd, modulo, multiply, scm, subtract, toDecimal, toFixed } from './math/index.mjs';
|
|
15
15
|
export { isChinese, isEmail, isEnglish, isExternal, isIdCard, isLowerCase, isMobile, isUpperCase, isUrl, regexpTest } from './regexp/index.mjs';
|
|
16
16
|
export { getRandom, getRandomDigit } from './random/index.mjs';
|
package/dist/es/math/index.mjs
CHANGED
|
@@ -162,7 +162,7 @@ function toFixed(num, decimals = 2, mode = MATH.ROUND) {
|
|
|
162
162
|
return _toFixedFloor(num, decimals);
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
|
-
throw new
|
|
165
|
+
throw new TypeError("toFixed: mode is MATH.ROUND 0 or MATH.ROUND_FLOOR");
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -183,7 +183,7 @@ function toDecimal(num, decimals = 2, mode = MATH.ROUND) {
|
|
|
183
183
|
}
|
|
184
184
|
// 错误保留格式
|
|
185
185
|
else {
|
|
186
|
-
throw new
|
|
186
|
+
throw new TypeError("toDecimal: mode is MATH.ROUND 0 or MATH.ROUND_FLOOR");
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
/* 内部函数 */
|
|
@@ -246,11 +246,11 @@ function _toFixedFloor(num, decimals = 2) {
|
|
|
246
246
|
// num可能是字符串,先转数字再判断NaN
|
|
247
247
|
const numVal = Number(num);
|
|
248
248
|
if (isNaN(numVal)) {
|
|
249
|
-
throw new
|
|
249
|
+
throw new TypeError(`${num} is NaN`);
|
|
250
250
|
}
|
|
251
251
|
// 校验小数位数范围
|
|
252
252
|
if (decimals < 0 || decimals > 20) {
|
|
253
|
-
throw new
|
|
253
|
+
throw new TypeError("_toFixedFloor: decimals places must be between 0 and 20");
|
|
254
254
|
}
|
|
255
255
|
// 默认为保留的小数点后两位
|
|
256
256
|
const dec = Math.max(0, Math.floor(decimals)); // 确保小数位数为非负整数
|
|
@@ -289,7 +289,7 @@ function _toFixedFloor(num, decimals = 2) {
|
|
|
289
289
|
*/
|
|
290
290
|
function _toDecimalRound(num, decimals = 2) {
|
|
291
291
|
if (isNaN(Number(num))) {
|
|
292
|
-
throw new
|
|
292
|
+
throw new TypeError(`_toDecimalRound: ${num} is not a number`);
|
|
293
293
|
}
|
|
294
294
|
const n = Math.pow(10, decimals);
|
|
295
295
|
return Math.round(Number(num) * n) / n;
|
|
@@ -302,7 +302,7 @@ function _toDecimalRound(num, decimals = 2) {
|
|
|
302
302
|
*/
|
|
303
303
|
function _toDecimalFloor(num, decimals = 2) {
|
|
304
304
|
if (isNaN(Number(num))) {
|
|
305
|
-
throw new
|
|
305
|
+
throw new TypeError(`_toDecimalFloor: ${num} is not a number`);
|
|
306
306
|
}
|
|
307
307
|
const n = Math.pow(10, decimals);
|
|
308
308
|
return Math.floor(Number(num) * n) / n;
|
package/dist/es/string/index.mjs
CHANGED
|
@@ -94,7 +94,7 @@ function toSnakeCase(value) {
|
|
|
94
94
|
}
|
|
95
95
|
// 不符合格式
|
|
96
96
|
else {
|
|
97
|
-
throw new TypeError(
|
|
97
|
+
throw new TypeError(`toSnakeCase: value should be a string`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -119,7 +119,7 @@ function toKebabCase(value) {
|
|
|
119
119
|
}
|
|
120
120
|
// 不符合格式
|
|
121
121
|
else {
|
|
122
|
-
throw new TypeError("value should be a string");
|
|
122
|
+
throw new TypeError("toKebabCase: value should be a string");
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
@@ -147,7 +147,7 @@ function toCamelCase(value) {
|
|
|
147
147
|
}
|
|
148
148
|
// 不符合格式
|
|
149
149
|
else {
|
|
150
|
-
throw new TypeError("value should be a string");
|
|
150
|
+
throw new TypeError("toCamelCase: value should be a string");
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
@@ -177,7 +177,7 @@ function toPascalCase(value) {
|
|
|
177
177
|
}
|
|
178
178
|
// 不符合格式
|
|
179
179
|
else {
|
|
180
|
-
throw new TypeError("value should be a string");
|
|
180
|
+
throw new TypeError("toPascalCase: value should be a string");
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
/* 字符串格式化 */
|
|
@@ -191,10 +191,10 @@ function toPascalCase(value) {
|
|
|
191
191
|
function padZeroStart(value, maxLength = 2) {
|
|
192
192
|
value = String(value).trim();
|
|
193
193
|
if (maxLength < 0) {
|
|
194
|
-
throw new TypeError("maxLength should be greater than 0");
|
|
194
|
+
throw new TypeError("padZeroStart: maxLength should be greater than 0");
|
|
195
195
|
}
|
|
196
196
|
if (isNull(value) || isNaN(value)) {
|
|
197
|
-
throw new
|
|
197
|
+
throw new TypeError("padZeroStart: value must be a valid number or numeric string");
|
|
198
198
|
}
|
|
199
199
|
// 前面补0
|
|
200
200
|
let len = value.toString().length;
|
|
@@ -214,10 +214,10 @@ function padZeroStart(value, maxLength = 2) {
|
|
|
214
214
|
function padZeroEnd(value, maxLength = 2) {
|
|
215
215
|
value = String(value).trim();
|
|
216
216
|
if (maxLength < 0) {
|
|
217
|
-
throw new TypeError("maxLength should be greater than 0");
|
|
217
|
+
throw new TypeError("padZeroEnd: maxLength should be greater than 0");
|
|
218
218
|
}
|
|
219
219
|
if (isNull(value) || isNaN(value)) {
|
|
220
|
-
throw new
|
|
220
|
+
throw new TypeError("padZeroEnd: value must be a valid number or numeric string");
|
|
221
221
|
}
|
|
222
222
|
// 后面补0
|
|
223
223
|
let len = value.toString().length;
|
|
@@ -303,7 +303,7 @@ function formatRmbChinese(money) {
|
|
|
303
303
|
money = parseFloat(String(money));
|
|
304
304
|
if (money >= maxNum) {
|
|
305
305
|
// 超出最大处理数字,抛出异常
|
|
306
|
-
throw new
|
|
306
|
+
throw new TypeError("formatRmbChinese: calculated number overflow");
|
|
307
307
|
}
|
|
308
308
|
if (money === 0) {
|
|
309
309
|
chineseStr = cnNums[0] + cnIntLast + cnInteger;
|
package/dist/index.d.ts
CHANGED
|
@@ -1370,7 +1370,7 @@ declare function toDateUTC(date?: Date): Date;
|
|
|
1370
1370
|
* const localDate = new Date('2025-01-26 08:00:00');
|
|
1371
1371
|
* console.log(toUTCString(localDate)); // 2025-01-26 00:00:00
|
|
1372
1372
|
*/
|
|
1373
|
-
declare function
|
|
1373
|
+
declare function toDateUTCString(date?: Date, options?: DateOptions): string;
|
|
1374
1374
|
/**
|
|
1375
1375
|
* 日期字符串转为日期对象
|
|
1376
1376
|
* @description 支持日期字符串,时间戳,Unix时间戳
|
|
@@ -2694,5 +2694,5 @@ declare function clearClipboard(): Promise<any>;
|
|
|
2694
2694
|
|
|
2695
2695
|
declare function testLoaded(): void;
|
|
2696
2696
|
|
|
2697
|
-
export { DATE, ID_CARD, KEYCODE, LANG, MATH, REGEXP, SM4, SORT, add, addClass, addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addStyle, addWeek, addYear, appendSearchParam, appendToSearchParam, arrayAvg, arrayBottom, arrayComplement, arrayCreate, arrayDifference, arrayDown, arrayEquals, arrayInsert, arrayInsertAfter, arrayInsertBefore, arrayIntersect, arrayMax, arrayMin, arrayRemove, arrayRemoveAfter, arrayRemoveBefore, arrayShuffle, arraySort, arraySortBy, arraySum, arraySwap, arrayToTree, arrayTop, arrayUnion, arrayUnique, arrayUp, base64Decode, base64DecodeURI, base64Encode, base64EncodeURI, base64FromHex, base64FromUint8Array, base64ToBlob, base64ToFile, base64ToHex, base64ToUint8Array, blobToBase64, blobToFile, blobToText, clearClipboard, clearCookie, clearLocalStorage, clearSessionStorage, clone, debounce, deepClone, deepCompare, divide, downloadBlobFile, downloadFileUrl, equals, equalsIgnoreCase, fileToBase64, fileToBlob, fileToUrl, formatFileSize, formatRmbChinese, formatStartOf, formatStartOfBankCard, formatStartOfIDCard, formatStartOfMobile, formatStartOfName, formatTemplate, formatThousand, formatTitle, fromDateUTC, gcd, generateSM4Iv, generateSM4Key, getAge, getAgeByIDCard, getBetweenDates, getBetweenMonths, getBetweenYears, getBirthdayByIDCard, getBrowserInfo, getChineseZodiac, getClipboard, getClipboardText, getCookie, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getDrawHex, getDrawRgb, getDrawRgba, getFileName, getFileSuffix, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getGUID, getHost, getHostName, getInfoByIDCard, getKeyCode, getKeyName, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getLimit, getLocalStorage, getNextPage, getNow, getOverTime, getPastTime, getPort, getPrevPage, getProtocol, getProvinceByIDCard, getQuarter, getRainbowPager, getRandom, getRandomDigit, getSearchParam, getSearchString, getSessionStorage, getSexByIDCard, getStyle, getTimestamp, getTotalPage, getUUID, getUnixTimestamp, getUrlHash, getUrlPath, getValueByPath, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, hasClass, hasSearchParam, hexToHsl, hexToRgb, hexToRgba, htmlDecode, htmlEncode, inArray, inString, isAM, isAfter, isAfterTomorrow, isAndroid, isArray, isAsyncFunction, isBefore, isBeforeYesterday, isBetween, isBigInt, isBlank, isBoolean, isChinese, isCommonYear, isDate, isDecimal, isEmail, isEmpty, isEnglish, isError, isExternal, isFalse, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isFunction, isFunctionString, isIdCard, isInteger, isIos, isIpad, isIphone, isJson, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isLinux, isLowerCase, isMac, isMap, isMobile, isNaN, isNotBlank, isNotEmpty, isNotNaN, isNotNull, isNotUndefined, isNull, isNumber, isObject, isPM, isPc, isPhone, isPromise, isQQ, isRegExp, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isSet, isString, isSupportCookie, isSupportStorage, isSymbol, isToday, isTomorrow, isTrue, isUndefined, isUpperCase, isUrl, isWeakMap, isWeakSet, isWeekend, isWeixin, isWindows, isWindowsPhone, isWorkday, isYesterday, jsonToMap, lastMonth, lastWeek, lastYear, mapToJson, mapToObject, md5, md5Hmac, md5HmacRaw, md5Raw, merge, modulo, multiply, nextMonth, nextWeek, nextYear, objectEquals, objectToMap, padZeroEnd, padZeroStart, parseFloat, parseInt, parseJson, parseSearchParam, prependSearchParam, prependToSearchParam, regexpTest, removeClass, removeCookie, removeLocalStorage, removeSearchParam, removeSessionStorage, removeStyle, replaceAll, replaceClass, rgbToHex, rgbaToHex, rgbaToHsl, scm, setClipboard, setClipboardText, setCookie, setLocalStorage, setSearchParam, setSessionStorage, setValueByPath, sha224, sha224Hmac, sha224HmacRaw, sha224Raw, sha256, sha256Hmac, sha256HmacRaw, sha256Raw, sleep, sm3Encrypt, sm3EncryptHmac, sm4Decrypt, sm4Encrypt, stringifyJson, stringifySearchParam, subtract, testLoaded, throttle, toCamelCase,
|
|
2697
|
+
export { DATE, ID_CARD, KEYCODE, LANG, MATH, REGEXP, SM4, SORT, add, addClass, addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addStyle, addWeek, addYear, appendSearchParam, appendToSearchParam, arrayAvg, arrayBottom, arrayComplement, arrayCreate, arrayDifference, arrayDown, arrayEquals, arrayInsert, arrayInsertAfter, arrayInsertBefore, arrayIntersect, arrayMax, arrayMin, arrayRemove, arrayRemoveAfter, arrayRemoveBefore, arrayShuffle, arraySort, arraySortBy, arraySum, arraySwap, arrayToTree, arrayTop, arrayUnion, arrayUnique, arrayUp, base64Decode, base64DecodeURI, base64Encode, base64EncodeURI, base64FromHex, base64FromUint8Array, base64ToBlob, base64ToFile, base64ToHex, base64ToUint8Array, blobToBase64, blobToFile, blobToText, clearClipboard, clearCookie, clearLocalStorage, clearSessionStorage, clone, debounce, deepClone, deepCompare, divide, downloadBlobFile, downloadFileUrl, equals, equalsIgnoreCase, fileToBase64, fileToBlob, fileToUrl, formatFileSize, formatRmbChinese, formatStartOf, formatStartOfBankCard, formatStartOfIDCard, formatStartOfMobile, formatStartOfName, formatTemplate, formatThousand, formatTitle, fromDateUTC, gcd, generateSM4Iv, generateSM4Key, getAge, getAgeByIDCard, getBetweenDates, getBetweenMonths, getBetweenYears, getBirthdayByIDCard, getBrowserInfo, getChineseZodiac, getClipboard, getClipboardText, getCookie, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getDrawHex, getDrawRgb, getDrawRgba, getFileName, getFileSuffix, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getGUID, getHost, getHostName, getInfoByIDCard, getKeyCode, getKeyName, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getLimit, getLocalStorage, getNextPage, getNow, getOverTime, getPastTime, getPort, getPrevPage, getProtocol, getProvinceByIDCard, getQuarter, getRainbowPager, getRandom, getRandomDigit, getSearchParam, getSearchString, getSessionStorage, getSexByIDCard, getStyle, getTimestamp, getTotalPage, getUUID, getUnixTimestamp, getUrlHash, getUrlPath, getValueByPath, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, hasClass, hasSearchParam, hexToHsl, hexToRgb, hexToRgba, htmlDecode, htmlEncode, inArray, inString, isAM, isAfter, isAfterTomorrow, isAndroid, isArray, isAsyncFunction, isBefore, isBeforeYesterday, isBetween, isBigInt, isBlank, isBoolean, isChinese, isCommonYear, isDate, isDecimal, isEmail, isEmpty, isEnglish, isError, isExternal, isFalse, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isFunction, isFunctionString, isIdCard, isInteger, isIos, isIpad, isIphone, isJson, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isLinux, isLowerCase, isMac, isMap, isMobile, isNaN, isNotBlank, isNotEmpty, isNotNaN, isNotNull, isNotUndefined, isNull, isNumber, isObject, isPM, isPc, isPhone, isPromise, isQQ, isRegExp, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isSet, isString, isSupportCookie, isSupportStorage, isSymbol, isToday, isTomorrow, isTrue, isUndefined, isUpperCase, isUrl, isWeakMap, isWeakSet, isWeekend, isWeixin, isWindows, isWindowsPhone, isWorkday, isYesterday, jsonToMap, lastMonth, lastWeek, lastYear, mapToJson, mapToObject, md5, md5Hmac, md5HmacRaw, md5Raw, merge, modulo, multiply, nextMonth, nextWeek, nextYear, objectEquals, objectToMap, padZeroEnd, padZeroStart, parseFloat, parseInt, parseJson, parseSearchParam, prependSearchParam, prependToSearchParam, regexpTest, removeClass, removeCookie, removeLocalStorage, removeSearchParam, removeSessionStorage, removeStyle, replaceAll, replaceClass, rgbToHex, rgbaToHex, rgbaToHsl, scm, setClipboard, setClipboardText, setCookie, setLocalStorage, setSearchParam, setSessionStorage, setValueByPath, sha224, sha224Hmac, sha224HmacRaw, sha224Raw, sha256, sha256Hmac, sha256HmacRaw, sha256Raw, sleep, sm3Encrypt, sm3EncryptHmac, sm4Decrypt, sm4Encrypt, stringifyJson, stringifySearchParam, subtract, testLoaded, throttle, toCamelCase, toDate, toDateString, toDateUTC, toDateUTCString, toDecimal, toFixed, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toUpperCase, today, tomorrow, treeToArray, trim, trimAll, trimEnd, trimStart, urlToBase64, urlToFile, yesterday };
|
|
2698
2698
|
export type { DateOptions, SM4DataType, SM4Options };
|