util-helpers 4.15.1 → 4.15.2
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/util-helpers.js +17 -12
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/bytesToSize.js +5 -2
- package/esm/formatMoney.js +11 -9
- package/esm/utils/config.js +1 -1
- package/lib/bytesToSize.js +5 -2
- package/lib/formatMoney.js +11 -9
- package/lib/utils/config.js +1 -1
- package/package.json +1 -1
- package/types/bytesToSize.d.ts +2 -0
- package/types/formatMoney.d.ts +12 -10
package/dist/util-helpers.js
CHANGED
|
@@ -537,7 +537,7 @@
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// eslint-disable-next-line no-undef
|
|
540
|
-
var version = "4.15.
|
|
540
|
+
var version = "4.15.2";
|
|
541
541
|
|
|
542
542
|
/**
|
|
543
543
|
* 打印警告信息
|
|
@@ -1897,25 +1897,25 @@
|
|
|
1897
1897
|
* @alias module:Processor.formatMoney
|
|
1898
1898
|
* @since 1.1.0
|
|
1899
1899
|
* @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
|
|
1900
|
-
* @param {Object} [options]
|
|
1901
|
-
* @param {
|
|
1902
|
-
* @param {string} [options.symbol]
|
|
1903
|
-
* @param {string} [options.thousand=","]
|
|
1904
|
-
* @param {string} [options.decimal="."]
|
|
1900
|
+
* @param {Object} [options] 金额格式化配置
|
|
1901
|
+
* @param {number} [options.precision=2] 保留位数 (最高:10位)
|
|
1902
|
+
* @param {string} [options.symbol] 货币符号
|
|
1903
|
+
* @param {string} [options.thousand=","] 千分位符号
|
|
1904
|
+
* @param {string} [options.decimal="."] 小数位符号
|
|
1905
1905
|
* @returns {string} 格式化的金额
|
|
1906
1906
|
* @example
|
|
1907
1907
|
*
|
|
1908
1908
|
* // 整数
|
|
1909
|
-
* formatMoney(
|
|
1909
|
+
* formatMoney(1000); // 1,000.00
|
|
1910
1910
|
*
|
|
1911
1911
|
* // 小数(默认保留2位小数)
|
|
1912
|
-
* formatMoney(
|
|
1912
|
+
* formatMoney(3000.03); // 3,000.03
|
|
1913
1913
|
*
|
|
1914
1914
|
* // 保留4位小数
|
|
1915
|
-
* formatMoney(
|
|
1915
|
+
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
1916
1916
|
*
|
|
1917
1917
|
* // 保留10位小数
|
|
1918
|
-
* formatMoney(
|
|
1918
|
+
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
1919
1919
|
*
|
|
1920
1920
|
* // 自定义单位符号
|
|
1921
1921
|
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
@@ -1926,6 +1926,8 @@
|
|
|
1926
1926
|
* // 自定义小数位分割符(默认'.')
|
|
1927
1927
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
1928
1928
|
*
|
|
1929
|
+
* // 字符串数字
|
|
1930
|
+
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
1929
1931
|
*/
|
|
1930
1932
|
var formatMoney = function formatMoney(num) {
|
|
1931
1933
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -2319,6 +2321,7 @@
|
|
|
2319
2321
|
* @param {number} bytes 字节大小
|
|
2320
2322
|
* @param {Object} [options] 配置项
|
|
2321
2323
|
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
2324
|
+
* @param {number} [options.precision=2] 精度
|
|
2322
2325
|
* @returns {string} 存储单位值
|
|
2323
2326
|
* @example
|
|
2324
2327
|
*
|
|
@@ -2335,14 +2338,16 @@
|
|
|
2335
2338
|
function bytesToSize(bytes) {
|
|
2336
2339
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2337
2340
|
var _options$spaceMark = options.spaceMark,
|
|
2338
|
-
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark
|
|
2341
|
+
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
|
|
2342
|
+
_options$precision = options.precision,
|
|
2343
|
+
precision = _options$precision === void 0 ? 2 : _options$precision;
|
|
2339
2344
|
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
2340
2345
|
if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
|
|
2341
2346
|
var k = 1024;
|
|
2342
2347
|
// 存储单位
|
|
2343
2348
|
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
2344
2349
|
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
2345
|
-
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(
|
|
2350
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
|
|
2346
2351
|
}
|
|
2347
2352
|
|
|
2348
2353
|
var regIdCard = /*#__PURE__*/_wrapRegExp(/^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i, {
|