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/esm/bytesToSize.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @param {number} bytes 字节大小
|
|
8
8
|
* @param {Object} [options] 配置项
|
|
9
9
|
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
10
|
+
* @param {number} [options.precision=2] 精度
|
|
10
11
|
* @returns {string} 存储单位值
|
|
11
12
|
* @example
|
|
12
13
|
*
|
|
@@ -23,13 +24,15 @@
|
|
|
23
24
|
function bytesToSize(bytes) {
|
|
24
25
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25
26
|
var _options$spaceMark = options.spaceMark,
|
|
26
|
-
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark
|
|
27
|
+
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
|
|
28
|
+
_options$precision = options.precision,
|
|
29
|
+
precision = _options$precision === void 0 ? 2 : _options$precision;
|
|
27
30
|
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
28
31
|
if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
|
|
29
32
|
var k = 1024;
|
|
30
33
|
// 存储单位
|
|
31
34
|
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
32
35
|
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
33
|
-
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(
|
|
36
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
|
|
34
37
|
}
|
|
35
38
|
export default bytesToSize;
|
package/esm/formatMoney.js
CHANGED
|
@@ -77,25 +77,25 @@ function formatDec(decStr, precision, decimal) {
|
|
|
77
77
|
* @alias module:Processor.formatMoney
|
|
78
78
|
* @since 1.1.0
|
|
79
79
|
* @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
|
|
80
|
-
* @param {Object} [options]
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {string} [options.symbol]
|
|
83
|
-
* @param {string} [options.thousand=","]
|
|
84
|
-
* @param {string} [options.decimal="."]
|
|
80
|
+
* @param {Object} [options] 金额格式化配置
|
|
81
|
+
* @param {number} [options.precision=2] 保留位数 (最高:10位)
|
|
82
|
+
* @param {string} [options.symbol] 货币符号
|
|
83
|
+
* @param {string} [options.thousand=","] 千分位符号
|
|
84
|
+
* @param {string} [options.decimal="."] 小数位符号
|
|
85
85
|
* @returns {string} 格式化的金额
|
|
86
86
|
* @example
|
|
87
87
|
*
|
|
88
88
|
* // 整数
|
|
89
|
-
* formatMoney(
|
|
89
|
+
* formatMoney(1000); // 1,000.00
|
|
90
90
|
*
|
|
91
91
|
* // 小数(默认保留2位小数)
|
|
92
|
-
* formatMoney(
|
|
92
|
+
* formatMoney(3000.03); // 3,000.03
|
|
93
93
|
*
|
|
94
94
|
* // 保留4位小数
|
|
95
|
-
* formatMoney(
|
|
95
|
+
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
96
96
|
*
|
|
97
97
|
* // 保留10位小数
|
|
98
|
-
* formatMoney(
|
|
98
|
+
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
99
99
|
*
|
|
100
100
|
* // 自定义单位符号
|
|
101
101
|
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
@@ -106,6 +106,8 @@ function formatDec(decStr, precision, decimal) {
|
|
|
106
106
|
* // 自定义小数位分割符(默认'.')
|
|
107
107
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
108
108
|
*
|
|
109
|
+
* // 字符串数字
|
|
110
|
+
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
109
111
|
*/
|
|
110
112
|
var formatMoney = function formatMoney(num) {
|
|
111
113
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
package/esm/utils/config.js
CHANGED
package/lib/bytesToSize.js
CHANGED
|
@@ -13,6 +13,7 @@ exports["default"] = void 0;
|
|
|
13
13
|
* @param {number} bytes 字节大小
|
|
14
14
|
* @param {Object} [options] 配置项
|
|
15
15
|
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
16
|
+
* @param {number} [options.precision=2] 精度
|
|
16
17
|
* @returns {string} 存储单位值
|
|
17
18
|
* @example
|
|
18
19
|
*
|
|
@@ -29,14 +30,16 @@ exports["default"] = void 0;
|
|
|
29
30
|
function bytesToSize(bytes) {
|
|
30
31
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
31
32
|
var _options$spaceMark = options.spaceMark,
|
|
32
|
-
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark
|
|
33
|
+
spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
|
|
34
|
+
_options$precision = options.precision,
|
|
35
|
+
precision = _options$precision === void 0 ? 2 : _options$precision;
|
|
33
36
|
var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
|
|
34
37
|
if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
|
|
35
38
|
var k = 1024;
|
|
36
39
|
// 存储单位
|
|
37
40
|
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
38
41
|
var i = Math.floor(Math.log(numBytes) / Math.log(k));
|
|
39
|
-
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(
|
|
42
|
+
return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
|
|
40
43
|
}
|
|
41
44
|
var _default = bytesToSize;
|
|
42
45
|
exports["default"] = _default;
|
package/lib/formatMoney.js
CHANGED
|
@@ -88,25 +88,25 @@ function formatDec(decStr, precision, decimal) {
|
|
|
88
88
|
* @alias module:Processor.formatMoney
|
|
89
89
|
* @since 1.1.0
|
|
90
90
|
* @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
|
|
91
|
-
* @param {Object} [options]
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {string} [options.symbol]
|
|
94
|
-
* @param {string} [options.thousand=","]
|
|
95
|
-
* @param {string} [options.decimal="."]
|
|
91
|
+
* @param {Object} [options] 金额格式化配置
|
|
92
|
+
* @param {number} [options.precision=2] 保留位数 (最高:10位)
|
|
93
|
+
* @param {string} [options.symbol] 货币符号
|
|
94
|
+
* @param {string} [options.thousand=","] 千分位符号
|
|
95
|
+
* @param {string} [options.decimal="."] 小数位符号
|
|
96
96
|
* @returns {string} 格式化的金额
|
|
97
97
|
* @example
|
|
98
98
|
*
|
|
99
99
|
* // 整数
|
|
100
|
-
* formatMoney(
|
|
100
|
+
* formatMoney(1000); // 1,000.00
|
|
101
101
|
*
|
|
102
102
|
* // 小数(默认保留2位小数)
|
|
103
|
-
* formatMoney(
|
|
103
|
+
* formatMoney(3000.03); // 3,000.03
|
|
104
104
|
*
|
|
105
105
|
* // 保留4位小数
|
|
106
|
-
* formatMoney(
|
|
106
|
+
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
107
107
|
*
|
|
108
108
|
* // 保留10位小数
|
|
109
|
-
* formatMoney(
|
|
109
|
+
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
110
110
|
*
|
|
111
111
|
* // 自定义单位符号
|
|
112
112
|
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
@@ -117,6 +117,8 @@ function formatDec(decStr, precision, decimal) {
|
|
|
117
117
|
* // 自定义小数位分割符(默认'.')
|
|
118
118
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
119
119
|
*
|
|
120
|
+
* // 字符串数字
|
|
121
|
+
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
120
122
|
*/
|
|
121
123
|
var formatMoney = function formatMoney(num) {
|
|
122
124
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
package/lib/utils/config.js
CHANGED
package/package.json
CHANGED
package/types/bytesToSize.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export default bytesToSize;
|
|
|
8
8
|
* @param {number} bytes 字节大小
|
|
9
9
|
* @param {Object} [options] 配置项
|
|
10
10
|
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
11
|
+
* @param {number} [options.precision=2] 精度
|
|
11
12
|
* @returns {string} 存储单位值
|
|
12
13
|
* @example
|
|
13
14
|
*
|
|
@@ -23,4 +24,5 @@ export default bytesToSize;
|
|
|
23
24
|
*/
|
|
24
25
|
declare function bytesToSize(bytes: number, options?: {
|
|
25
26
|
spaceMark?: string | undefined;
|
|
27
|
+
precision?: number | undefined;
|
|
26
28
|
} | undefined): string;
|
package/types/formatMoney.d.ts
CHANGED
|
@@ -6,25 +6,25 @@ export default formatMoney;
|
|
|
6
6
|
* @alias module:Processor.formatMoney
|
|
7
7
|
* @since 1.1.0
|
|
8
8
|
* @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
|
|
9
|
-
* @param {Object} [options]
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {string} [options.symbol]
|
|
12
|
-
* @param {string} [options.thousand=","]
|
|
13
|
-
* @param {string} [options.decimal="."]
|
|
9
|
+
* @param {Object} [options] 金额格式化配置
|
|
10
|
+
* @param {number} [options.precision=2] 保留位数 (最高:10位)
|
|
11
|
+
* @param {string} [options.symbol] 货币符号
|
|
12
|
+
* @param {string} [options.thousand=","] 千分位符号
|
|
13
|
+
* @param {string} [options.decimal="."] 小数位符号
|
|
14
14
|
* @returns {string} 格式化的金额
|
|
15
15
|
* @example
|
|
16
16
|
*
|
|
17
17
|
* // 整数
|
|
18
|
-
* formatMoney(
|
|
18
|
+
* formatMoney(1000); // 1,000.00
|
|
19
19
|
*
|
|
20
20
|
* // 小数(默认保留2位小数)
|
|
21
|
-
* formatMoney(
|
|
21
|
+
* formatMoney(3000.03); // 3,000.03
|
|
22
22
|
*
|
|
23
23
|
* // 保留4位小数
|
|
24
|
-
* formatMoney(
|
|
24
|
+
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
25
25
|
*
|
|
26
26
|
* // 保留10位小数
|
|
27
|
-
* formatMoney(
|
|
27
|
+
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
28
28
|
*
|
|
29
29
|
* // 自定义单位符号
|
|
30
30
|
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
@@ -35,9 +35,11 @@ export default formatMoney;
|
|
|
35
35
|
* // 自定义小数位分割符(默认'.')
|
|
36
36
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
37
37
|
*
|
|
38
|
+
* // 字符串数字
|
|
39
|
+
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
38
40
|
*/
|
|
39
41
|
declare function formatMoney(num: string | number, options?: {
|
|
40
|
-
precision?:
|
|
42
|
+
precision?: number | undefined;
|
|
41
43
|
symbol?: string | undefined;
|
|
42
44
|
thousand?: string | undefined;
|
|
43
45
|
decimal?: string | undefined;
|