dozy 1.0.108 → 1.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +72 -23
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -450,47 +450,96 @@ declare const shanghaiDateFormatter: Intl.DateTimeFormat;
|
|
|
450
450
|
*/
|
|
451
451
|
declare function $formatDate(dateInput: string | number | Date): string;
|
|
452
452
|
/**
|
|
453
|
-
*
|
|
453
|
+
* 格式化数值为字符串,保留指定小数位数,并添加千分位分隔符。
|
|
454
454
|
*
|
|
455
455
|
* 行为说明:
|
|
456
|
-
* -
|
|
457
|
-
* -
|
|
458
|
-
* -
|
|
456
|
+
* - 使用 `toFixed(bits)` 保留指定位数的小数。
|
|
457
|
+
* - 通过 `$formatWithCommas` 添加千分位逗号分隔符。
|
|
458
|
+
* - 当输入不是有效数字时返回 `'-'`。
|
|
459
|
+
*
|
|
460
|
+
* @param value 要格式化的数值(原始值,无需换算)。
|
|
461
|
+
* @param bits 小数位数,默认为 `0`。
|
|
462
|
+
* @returns 返回格式化后的字符串(含千分位);输入无效时返回 `'-'`。
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* $format(1234.5, 2) // 返回 "1,234.50"
|
|
466
|
+
* $format(1234, 0) // 返回 "1,234"
|
|
467
|
+
*/
|
|
468
|
+
declare function $format(value?: number, bits?: number): string;
|
|
469
|
+
/**
|
|
470
|
+
* 【积分专用】格式化积分数值为字符串,并添加千分位分隔符。
|
|
471
|
+
*
|
|
472
|
+
* ⚠ 积分单位语义(重要):
|
|
473
|
+
* - 积分系统中,底层存储的是整数 "积分"(points),前端展示的是 "单位值"(display unit)。
|
|
474
|
+
* - 换算关系:`10^bits` 个积分 = 1 个展示单位。即 `bits` 是 **单位换算指数**,不是小数位数。
|
|
475
|
+
* - 例如 `bits=2` 时:100 积分 = 1.00 展示单位,1234 积分 = 12.34 展示单位。
|
|
476
|
+
* - 例如 `bits=3` 时:1000 积分 = 1.000 展示单位,500 积分 = 0.500 展示单位。
|
|
477
|
+
* - 展示后的小数位数恰好等于 `bits`,这是换算的 **自然结果**,而非 `bits` 的定义。
|
|
478
|
+
*
|
|
479
|
+
* 行为说明:
|
|
480
|
+
* - 先将积分值乘以 `10^(-bits)` 换算为展示值,然后底层调用 `$format` 格式化。
|
|
459
481
|
* - 当输入不是有效数字时返回 `'-'`。
|
|
460
482
|
*
|
|
461
|
-
* @param points
|
|
462
|
-
* @param bits
|
|
483
|
+
* @param points 积分值(底层原始值,整数语义)。
|
|
484
|
+
* @param bits 单位换算指数:`10^bits` 积分 = 1 展示单位,默认为 `2`(即 100 积分 = 1.00)。
|
|
463
485
|
* @returns 返回格式化后的字符串(含千分位);输入无效时返回 `'-'`。
|
|
464
486
|
*
|
|
465
487
|
* @example
|
|
466
|
-
* $formatPoints(
|
|
467
|
-
* $formatPoints(
|
|
468
|
-
* $formatPoints(
|
|
488
|
+
* $formatPoints(1234, 2) // 100 积分 = 1.00 → 返回 "12.34"
|
|
489
|
+
* $formatPoints(123, 2) // 返回 "1.23"
|
|
490
|
+
* $formatPoints(500, 3) // 1000 积分 = 1.000 → 返回 "0.500"
|
|
469
491
|
*/
|
|
470
492
|
declare function $formatPoints(points?: number, bits?: number): string;
|
|
471
493
|
/**
|
|
472
494
|
* 格式化数值为带符号和颜色的显示元组,并添加千分位分隔符。
|
|
473
495
|
*
|
|
474
496
|
* 行为说明:
|
|
475
|
-
* -
|
|
476
|
-
* - 通过 `$formatWithCommas` 添加千分位逗号分隔符。
|
|
497
|
+
* - 使用 `toFixed(bits)` 格式化并通过 `$formatWithCommas` 添加千分位逗号分隔符。
|
|
477
498
|
* - 根据数值正负自动添加符号前缀并分配对应颜色。
|
|
478
|
-
* -
|
|
479
|
-
*
|
|
480
|
-
*
|
|
499
|
+
* - 颜色规则由 `greenUp` 参数控制:
|
|
500
|
+
* - `greenUp = true`(默认,积分惯例):增加→绿 `'#0a0'`,减少→红 `'#a00'`。
|
|
501
|
+
* - `greenUp = false`(股市惯例):增加→红 `'#a00'`,减少→绿 `'#0a0'`。
|
|
502
|
+
* - 零或无变化:无前缀,颜色 `'#333'`(深灰色)。
|
|
481
503
|
* - 当输入不是有效数字时返回 `['+?', '#333']`。
|
|
482
504
|
*
|
|
483
|
-
* @param
|
|
484
|
-
* @param bits
|
|
505
|
+
* @param value 要格式化的数值(原始值,无需换算)。
|
|
506
|
+
* @param bits 小数位数,默认为 `0`。
|
|
507
|
+
* @param greenUp 颜色惯例:`true`=绿涨红跌(积分默认),`false`=红涨绿跌(股市)。默认 `true`。
|
|
508
|
+
* @returns 返回包含显示文本(含千分位)和颜色的元组 `[display, color]`。
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* $formatWithChange(1234.5, 2) // ["+1,234.50", "#0a0"] (积分惯例: 绿涨)
|
|
512
|
+
* $formatWithChange(1234.5, 2, false) // ["+1,234.50", "#a00"] (股市惯例: 红涨)
|
|
513
|
+
* $formatWithChange(-50, 2) // ["-50.00", "#a00"]
|
|
514
|
+
* $formatWithChange(0, 2) // ["0.00", "#333"]
|
|
515
|
+
*/
|
|
516
|
+
declare function $formatWithChange(value?: number, bits?: number, greenUp?: boolean): [display: string, color: string];
|
|
517
|
+
/**
|
|
518
|
+
* 【积分专用】格式化积分数值为带符号和颜色的显示元组,并添加千分位分隔符。
|
|
519
|
+
*
|
|
520
|
+
* ⚠ 积分单位语义(重要):
|
|
521
|
+
* - 积分系统中,底层存储的是整数 "积分"(points),前端展示的是 "单位值"(display unit)。
|
|
522
|
+
* - 换算关系:`10^bits` 个积分 = 1 个展示单位。即 `bits` 是 **单位换算指数**,不是小数位数。
|
|
523
|
+
* - 例如 `bits=2` 时:100 积分 = 1.00 展示单位,1234 积分 = 12.34 展示单位。
|
|
524
|
+
* - 例如 `bits=3` 时:1000 积分 = 1.000 展示单位,500 积分 = 0.500 展示单位。
|
|
525
|
+
* - 展示后的小数位数恰好等于 `bits`,这是换算的 **自然结果**,而非 `bits` 的定义。
|
|
526
|
+
*
|
|
527
|
+
* 行为说明:
|
|
528
|
+
* - 先将积分值乘以 `10^(-bits)` 换算为展示值,然后底层调用 `$formatWithChange` 格式化。
|
|
529
|
+
* - 颜色规则由 `greenUp` 参数控制(默认 `greenUp = true`,即积分惯例:增加→绿,减少→红)。
|
|
530
|
+
*
|
|
531
|
+
* @param points 积分值(底层原始值,整数语义)。
|
|
532
|
+
* @param bits 单位换算指数:`10^bits` 积分 = 1 展示单位,默认为 `2`(即 100 积分 = 1.00)。
|
|
533
|
+
* @param greenUp 颜色惯例:`true`=绿涨红跌(积分默认),`false`=红涨绿跌(股市)。默认 `true`。
|
|
485
534
|
* @returns 返回包含显示文本(含千分位)和颜色的元组 `[display, color]`。
|
|
486
535
|
*
|
|
487
536
|
* @example
|
|
488
|
-
* $formatPointsWithChange(
|
|
489
|
-
* $formatPointsWithChange(
|
|
490
|
-
* $formatPointsWithChange(
|
|
491
|
-
* $formatPointsWithChange(0, 2)
|
|
537
|
+
* $formatPointsWithChange(1234, 2) // ["+12.34", "#0a0"] (100 积分=1.00, 绿涨)
|
|
538
|
+
* $formatPointsWithChange(-500, 2) // ["-5.00", "#a00"]
|
|
539
|
+
* $formatPointsWithChange(1234, 2, false) // ["+12.34", "#a00"] (股市惯例: 红涨)
|
|
540
|
+
* $formatPointsWithChange(0, 2) // ["0.00", "#333"]
|
|
492
541
|
*/
|
|
493
|
-
declare function $formatPointsWithChange(points?: number, bits?: number): [display: string, color: string];
|
|
542
|
+
declare function $formatPointsWithChange(points?: number, bits?: number, greenUp?: boolean): [display: string, color: string];
|
|
494
543
|
/**
|
|
495
544
|
* 字节数语义化显示,格式与 npm `pretty-bytes` 库一致(1000 进制)。
|
|
496
545
|
*
|
|
@@ -1470,6 +1519,6 @@ declare function toRgbString(input: string | Color | any): string | undefined;
|
|
|
1470
1519
|
*/
|
|
1471
1520
|
declare function toHslString(input: string | Color | any): string | undefined;
|
|
1472
1521
|
|
|
1473
|
-
declare const DOZY = "1.0.
|
|
1522
|
+
declare const DOZY = "1.0.109";
|
|
1474
1523
|
|
|
1475
|
-
export { $Headers, $Request, $Response, $URL, $URLSearchParams, $arrayFrom, $arrayIsArray, $assign, $backgroundColor, $borderColor, $capitalize, $checkValidEmailWithUnicode, $clamp, $clearInterval, $clearTimeout, $clone, $compressImage, $compressImageBase64, $compressImageDefaultOptions, $copy, $crypto, $date, $decodeBase64ToBinary, $decodeBase64ToUnicode, $deepClone, $defineProperty, $document, $encodeUnicodeToBase64, $ensureUrl, $entries, $escapeHTML, $escapeXML, $fallbackCopy, $fetch, $fileToBase64, $formatDate, $formatK, $formatPoints, $formatPointsWithChange, $formatWithCommas, $freeze, $genSSF, $getFileType, $getHue, $getTimeString, $hasKey, $humanizeBytes, $if, $inRange, $inRange2, $inferExtensionFormPureBase64, $inferMimeTypeFormPureBase64, $is, $isObject, $isPlainClass, $isValidEmailWithUnicode, $isValidOrBriefURL, $jsonParse, $jsonStringify, $keys, $lastIndex, $lindex, $loadOpt, $location, $log, $lplus, $magic, $math, $now, $numberIsFinite, $numberIsNaN, $oc, $open, $parseParams, $promise, $pureText, $purifyBase64, $randomByte, $replaceHolesWithUndefined, $rmvSlash, $rsValue, $rsetValue, $rvalue, $s, $sc, $setInterval, $setRange, $setTimeout, $stringFromCharCode, $stringFromCodePoint, $stringToRange, $strings, $toDataUrlFromBase64, $validName, $values, $window, type Any, type Atoa, type Coord, type Coord3, DEFAULT_XLS_BASE_MULTIPLIER, DEFAULT_XLS_MAX_ASPECT_RATIO, DEFAULT_XLS_MAX_ASPECT_RATIO_FACTOR, DOZY, type DozyConfig, type DozyConfigItem, type FileType, Gens, type Hel, type IOpt, type Items, type Null, type Nullable, RainbowGen, RepoStore, type ScaleComputer, type ScaleIniter, type ScaleResponsiveOptions, StringObfuscator, type UNumber, __GensDirectives, _res, boxShadow, dozy, enableScaler, err403, errArg, errCode, errContent, errMsg, errNotLoggedIn, errToString, getBrightness, getColorMap, isNowAroundUtcHour, isNull, isValidColor, maybeString, registerCustomColor, s, shanghaiDateFormatter, smallChance, smartParse, smartString, standardIniter, textShadow, toHexString, toHslString, toRgbString, toRgbaArray, web$enableHttpsRedirect, web$enableProdProtector, web$encodeURI, web$pathStartData, web$redirectToDomain, web$replaceHash, web$setPathTarget, xtrim };
|
|
1524
|
+
export { $Headers, $Request, $Response, $URL, $URLSearchParams, $arrayFrom, $arrayIsArray, $assign, $backgroundColor, $borderColor, $capitalize, $checkValidEmailWithUnicode, $clamp, $clearInterval, $clearTimeout, $clone, $compressImage, $compressImageBase64, $compressImageDefaultOptions, $copy, $crypto, $date, $decodeBase64ToBinary, $decodeBase64ToUnicode, $deepClone, $defineProperty, $document, $encodeUnicodeToBase64, $ensureUrl, $entries, $escapeHTML, $escapeXML, $fallbackCopy, $fetch, $fileToBase64, $format, $formatDate, $formatK, $formatPoints, $formatPointsWithChange, $formatWithChange, $formatWithCommas, $freeze, $genSSF, $getFileType, $getHue, $getTimeString, $hasKey, $humanizeBytes, $if, $inRange, $inRange2, $inferExtensionFormPureBase64, $inferMimeTypeFormPureBase64, $is, $isObject, $isPlainClass, $isValidEmailWithUnicode, $isValidOrBriefURL, $jsonParse, $jsonStringify, $keys, $lastIndex, $lindex, $loadOpt, $location, $log, $lplus, $magic, $math, $now, $numberIsFinite, $numberIsNaN, $oc, $open, $parseParams, $promise, $pureText, $purifyBase64, $randomByte, $replaceHolesWithUndefined, $rmvSlash, $rsValue, $rsetValue, $rvalue, $s, $sc, $setInterval, $setRange, $setTimeout, $stringFromCharCode, $stringFromCodePoint, $stringToRange, $strings, $toDataUrlFromBase64, $validName, $values, $window, type Any, type Atoa, type Coord, type Coord3, DEFAULT_XLS_BASE_MULTIPLIER, DEFAULT_XLS_MAX_ASPECT_RATIO, DEFAULT_XLS_MAX_ASPECT_RATIO_FACTOR, DOZY, type DozyConfig, type DozyConfigItem, type FileType, Gens, type Hel, type IOpt, type Items, type Null, type Nullable, RainbowGen, RepoStore, type ScaleComputer, type ScaleIniter, type ScaleResponsiveOptions, StringObfuscator, type UNumber, __GensDirectives, _res, boxShadow, dozy, enableScaler, err403, errArg, errCode, errContent, errMsg, errNotLoggedIn, errToString, getBrightness, getColorMap, isNowAroundUtcHour, isNull, isValidColor, maybeString, registerCustomColor, s, shanghaiDateFormatter, smallChance, smartParse, smartString, standardIniter, textShadow, toHexString, toHslString, toRgbString, toRgbaArray, web$enableHttpsRedirect, web$enableProdProtector, web$encodeURI, web$pathStartData, web$redirectToDomain, web$replaceHash, web$setPathTarget, xtrim };
|
package/dist/index.js
CHANGED
|
@@ -502,21 +502,31 @@ function $formatDate(dateInput) {
|
|
|
502
502
|
const minute = getPart("minute");
|
|
503
503
|
return `${year}\u5E74${month}\u6708${day}\u65E5 ${hour}:${minute}`;
|
|
504
504
|
}
|
|
505
|
+
function $format(value, bits = 0) {
|
|
506
|
+
if (!$sc(value)) return "-";
|
|
507
|
+
return $formatWithCommas(value.toFixed(bits));
|
|
508
|
+
}
|
|
505
509
|
function $formatPoints(points, bits = 2) {
|
|
506
510
|
if (!$sc(points)) return "-";
|
|
507
|
-
return $
|
|
511
|
+
return $format(points * Math.pow(10, -bits), bits);
|
|
508
512
|
}
|
|
509
|
-
function $
|
|
513
|
+
function $formatWithChange(value, bits = 0, greenUp = true) {
|
|
514
|
+
if (!$sc(value)) return ["+?", "#333"];
|
|
515
|
+
const up = greenUp ? "#0a0" : "#a00";
|
|
516
|
+
const down = greenUp ? "#a00" : "#0a0";
|
|
510
517
|
let color = "#333";
|
|
511
|
-
if (!$sc(points)) return ["+?", color];
|
|
512
518
|
let prefix = "";
|
|
513
|
-
if (
|
|
519
|
+
if (value > 0) {
|
|
514
520
|
prefix = "+";
|
|
515
|
-
color =
|
|
516
|
-
} else if (
|
|
517
|
-
color =
|
|
521
|
+
color = up;
|
|
522
|
+
} else if (value < 0) {
|
|
523
|
+
color = down;
|
|
518
524
|
}
|
|
519
|
-
return [prefix + $formatWithCommas(
|
|
525
|
+
return [prefix + $formatWithCommas(value.toFixed(bits)), color];
|
|
526
|
+
}
|
|
527
|
+
function $formatPointsWithChange(points, bits = 2, greenUp = true) {
|
|
528
|
+
if (!$sc(points)) return ["+?", "#333"];
|
|
529
|
+
return $formatWithChange(points * Math.pow(10, -bits), bits, greenUp);
|
|
520
530
|
}
|
|
521
531
|
var BYTE_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB"];
|
|
522
532
|
function $humanizeBytes(n) {
|
|
@@ -8165,7 +8175,7 @@ function toHslString(input) {
|
|
|
8165
8175
|
}
|
|
8166
8176
|
|
|
8167
8177
|
// src/index.ts
|
|
8168
|
-
var DOZY = "1.0.
|
|
8178
|
+
var DOZY = "1.0.109";
|
|
8169
8179
|
/*! Bundled license information:
|
|
8170
8180
|
|
|
8171
8181
|
@octokit/request-error/dist-src/index.js:
|
|
@@ -8176,6 +8186,6 @@ var DOZY = "1.0.108";
|
|
|
8176
8186
|
(* v8 ignore else -- @preserve *)
|
|
8177
8187
|
*/
|
|
8178
8188
|
|
|
8179
|
-
export { $Headers, $Request, $Response, $URL, $URLSearchParams, $arrayFrom, $arrayIsArray, $assign, $backgroundColor, $borderColor, $capitalize, $checkValidEmailWithUnicode, $clamp, $clearInterval, $clearTimeout, $clone, $compressImage, $compressImageBase64, $compressImageDefaultOptions, $copy, $crypto, $date, $decodeBase64ToBinary, $decodeBase64ToUnicode, $deepClone, $defineProperty, $document, $encodeUnicodeToBase64, $ensureUrl, $entries, $escapeHTML, $escapeXML, $fallbackCopy, $fetch, $fileToBase64, $formatDate, $formatK, $formatPoints, $formatPointsWithChange, $formatWithCommas, $freeze, $genSSF, $getFileType, $getHue, $getTimeString, $hasKey, $humanizeBytes, $if, $inRange, $inRange2, $inferExtensionFormPureBase64, $inferMimeTypeFormPureBase64, $is, $isObject, $isPlainClass, $isValidEmailWithUnicode, $isValidOrBriefURL, $jsonParse, $jsonStringify, $keys, $lastIndex, $lindex, $loadOpt, $location, $log, $lplus, $magic, $math, $now, $numberIsFinite, $numberIsNaN, $oc, $open, $parseParams, $promise, $pureText, $purifyBase64, $randomByte, $replaceHolesWithUndefined, $rmvSlash, $rsValue, $rsetValue, $rvalue, $s, $sc, $setInterval, $setRange, $setTimeout, $stringFromCharCode, $stringFromCodePoint, $stringToRange, $strings, $toDataUrlFromBase64, $validName, $values, $window, src_exports as ColorLib, DEFAULT_XLS_BASE_MULTIPLIER, DEFAULT_XLS_MAX_ASPECT_RATIO, DEFAULT_XLS_MAX_ASPECT_RATIO_FACTOR, DOZY, Gens, RainbowGen, RepoStore, StringObfuscator, __GensDirectives, _res, boxShadow, customAlphabet, dozy, enableScaler, err403, errArg, errCode, errContent, errMsg, errNotLoggedIn, errToString, getBrightness, getColorMap, isNowAroundUtcHour, isNull, isValidColor, maybeString, nanoid, registerCustomColor, s, shanghaiDateFormatter, smallChance, smartParse, smartString, standardIniter, textShadow, toHexString, toHslString, toRgbString, toRgbaArray, urlAlphabet, web$enableHttpsRedirect, web$enableProdProtector, web$encodeURI, web$pathStartData, web$redirectToDomain, web$replaceHash, web$setPathTarget, xtrim };
|
|
8189
|
+
export { $Headers, $Request, $Response, $URL, $URLSearchParams, $arrayFrom, $arrayIsArray, $assign, $backgroundColor, $borderColor, $capitalize, $checkValidEmailWithUnicode, $clamp, $clearInterval, $clearTimeout, $clone, $compressImage, $compressImageBase64, $compressImageDefaultOptions, $copy, $crypto, $date, $decodeBase64ToBinary, $decodeBase64ToUnicode, $deepClone, $defineProperty, $document, $encodeUnicodeToBase64, $ensureUrl, $entries, $escapeHTML, $escapeXML, $fallbackCopy, $fetch, $fileToBase64, $format, $formatDate, $formatK, $formatPoints, $formatPointsWithChange, $formatWithChange, $formatWithCommas, $freeze, $genSSF, $getFileType, $getHue, $getTimeString, $hasKey, $humanizeBytes, $if, $inRange, $inRange2, $inferExtensionFormPureBase64, $inferMimeTypeFormPureBase64, $is, $isObject, $isPlainClass, $isValidEmailWithUnicode, $isValidOrBriefURL, $jsonParse, $jsonStringify, $keys, $lastIndex, $lindex, $loadOpt, $location, $log, $lplus, $magic, $math, $now, $numberIsFinite, $numberIsNaN, $oc, $open, $parseParams, $promise, $pureText, $purifyBase64, $randomByte, $replaceHolesWithUndefined, $rmvSlash, $rsValue, $rsetValue, $rvalue, $s, $sc, $setInterval, $setRange, $setTimeout, $stringFromCharCode, $stringFromCodePoint, $stringToRange, $strings, $toDataUrlFromBase64, $validName, $values, $window, src_exports as ColorLib, DEFAULT_XLS_BASE_MULTIPLIER, DEFAULT_XLS_MAX_ASPECT_RATIO, DEFAULT_XLS_MAX_ASPECT_RATIO_FACTOR, DOZY, Gens, RainbowGen, RepoStore, StringObfuscator, __GensDirectives, _res, boxShadow, customAlphabet, dozy, enableScaler, err403, errArg, errCode, errContent, errMsg, errNotLoggedIn, errToString, getBrightness, getColorMap, isNowAroundUtcHour, isNull, isValidColor, maybeString, nanoid, registerCustomColor, s, shanghaiDateFormatter, smallChance, smartParse, smartString, standardIniter, textShadow, toHexString, toHslString, toRgbString, toRgbaArray, urlAlphabet, web$enableHttpsRedirect, web$enableProdProtector, web$encodeURI, web$pathStartData, web$redirectToDomain, web$replaceHash, web$setPathTarget, xtrim };
|
|
8180
8190
|
//# sourceMappingURL=index.js.map
|
|
8181
8191
|
//# sourceMappingURL=index.js.map
|