util-helpers 5.1.1 → 5.1.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/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.1.1";
1
+ var VERSION = "5.1.2";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -1,5 +1,5 @@
1
1
  import { __read } from 'tslib';
2
- import { isNaN } from 'ut2';
2
+ import { isString, isNumber, isNaN } from 'ut2';
3
3
  import { transformEffectiveNumber, checkBoundary, trimLeftZero } from './utils/math.util.js';
4
4
  import devWarn from './utils/devWarn.js';
5
5
  import isValidNumber from './isValidNumber.js';
@@ -41,10 +41,9 @@ function formatDec(decStr, precision, decimal) {
41
41
  return decimal + ret;
42
42
  }
43
43
  var formatMoney = function (num, options) {
44
- if (num === void 0) { num = ''; }
45
44
  if (options === void 0) { options = {}; }
46
- var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
47
- if (!checkNumber(num)) {
45
+ var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c, _d = options.strict, strict = _d === void 0 ? true : _d;
46
+ if (!checkNumber(num) || (strict && (!isString(num) || num === '') && !isNumber(num))) {
48
47
  return '';
49
48
  }
50
49
  if (typeof num === 'number' && !isFinite(num)) {
@@ -60,7 +59,7 @@ var formatMoney = function (num, options) {
60
59
  thousand = typeof thousand === 'string' ? thousand : ',';
61
60
  decimal = typeof decimal === 'string' ? decimal : '.';
62
61
  var strNum = transformEffectiveNumber(num) + '';
63
- var _d = __read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
62
+ var _e = __read(strNum.split('.'), 2), intStr = _e[0], decStr = _e[1];
64
63
  return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
65
64
  };
66
65
  var formatMoney$1 = formatMoney;
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.1.1";
3
+ var VERSION = "5.1.2";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -43,10 +43,9 @@ function formatDec(decStr, precision, decimal) {
43
43
  return decimal + ret;
44
44
  }
45
45
  var formatMoney = function (num, options) {
46
- if (num === void 0) { num = ''; }
47
46
  if (options === void 0) { options = {}; }
48
- var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
49
- if (!checkNumber(num)) {
47
+ var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c, _d = options.strict, strict = _d === void 0 ? true : _d;
48
+ if (!checkNumber(num) || (strict && (!ut2.isString(num) || num === '') && !ut2.isNumber(num))) {
50
49
  return '';
51
50
  }
52
51
  if (typeof num === 'number' && !isFinite(num)) {
@@ -62,7 +61,7 @@ var formatMoney = function (num, options) {
62
61
  thousand = typeof thousand === 'string' ? thousand : ',';
63
62
  decimal = typeof decimal === 'string' ? decimal : '.';
64
63
  var strNum = math_util.transformEffectiveNumber(num) + '';
65
- var _d = tslib.__read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
64
+ var _e = tslib.__read(strNum.split('.'), 2), intStr = _e[0], decStr = _e[1];
66
65
  return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
67
66
  };
68
67
  var formatMoney$1 = formatMoney;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -10,6 +10,26 @@ import { UploadFile } from './utils/file.util';
10
10
  * @param {File} file 文件对象。支持 antd `UploadFile` 对象。
11
11
  * @param {string} [accept] 文件类型说明符。
12
12
  * @returns {boolean} 如果 `file` 符合 `accept` 返回 `true`, 否则返回 `false`。
13
+ * @example
14
+ *
15
+ * const pdf = new File([], '1.pdf', { type: 'application/pdf' });
16
+ * const jpeg = new File([], 'xx.jpeg', { type: 'image/jpeg' });
17
+ *
18
+ * // 文件类型
19
+ * checkFileType(pdf, 'application/pdf'); // true
20
+ * checkFileType(jpeg, 'image/jpeg'); // true
21
+ *
22
+ * // 通配符
23
+ * checkFileType(jpeg, 'image/*'); // true
24
+ * checkFileType(pdf, 'image/*'); // false
25
+ * checkFileType(pdf, 'application/*'); // true
26
+ * checkFileType(pdf, '*'); // true
27
+ * checkFileType(jpeg, '*'); // true
28
+ *
29
+ * // 文件名扩展名
30
+ * checkFileType(jpeg, '.png,.jpeg,.jpg'); // true
31
+ * checkFileType(pdf, '.pdf'); // true
32
+ *
13
33
  */
14
34
  declare function checkFileType(file: File | UploadFile, accept?: string): boolean;
15
35
  export default checkFileType;
@@ -3,6 +3,7 @@ type Options = {
3
3
  symbol?: string;
4
4
  thousand?: string;
5
5
  decimal?: string;
6
+ strict?: boolean;
6
7
  };
7
8
  /**
8
9
  * 格式化金额
@@ -16,6 +17,7 @@ type Options = {
16
17
  * @param {string} [options.symbol] 货币符号
17
18
  * @param {string} [options.thousand=","] 千分位符号
18
19
  * @param {string} [options.decimal="."] 小数位符号
20
+ * @param {boolean} [options.strict=ture] 严格模式。开启后,只支持非空字符串和数字格式化,其他类型值如`null` `undefined` `true` `false`等将返回空字符串。
19
21
  * @returns {string} 格式化的金额
20
22
  * @example
21
23
  *
@@ -5,8 +5,17 @@ import { UploadFile } from './utils/file.util';
5
5
  * @static
6
6
  * @alias module:Other.getFileType
7
7
  * @since 5.1.0
8
+ * @requires Other.checkFileType
8
9
  * @param {File} file 文件对象。支持 antd `UploadFile` 对象。
9
10
  * @returns {"image" | "audio" | "video" | "pdf" | "word" | "excel" | undefined} 如果是 `image` `audio` `video` `pdf` `word` `excel` 这些类型的文件,返回对应的类型值,否则返回 `undefined`。
11
+ * @example
12
+ *
13
+ * const pdf = new File([], '1.pdf', { type: 'application/pdf' });
14
+ * const jpeg = new File([], 'xx.jpeg', { type: 'image/jpeg' });
15
+ *
16
+ * getFileType(pdf); // 'pdf'
17
+ * getFileType(jpeg); // 'image'
18
+ *
10
19
  */
11
20
  declare function getFileType(file: File | UploadFile): "image" | "audio" | "video" | "pdf" | "word" | "excel" | undefined;
12
21
  export default getFileType;