util-helpers 5.1.1 → 5.1.3

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.
Files changed (42) hide show
  1. package/dist/util-helpers.js +4 -5
  2. package/dist/util-helpers.js.map +1 -1
  3. package/dist/util-helpers.min.js +1 -1
  4. package/dist/util-helpers.min.js.map +1 -1
  5. package/esm/VERSION.js +1 -1
  6. package/esm/formatMoney.js +4 -5
  7. package/lib/VERSION.js +1 -1
  8. package/lib/formatMoney.js +3 -4
  9. package/package.json +1 -1
  10. package/types/AsyncMemo.d.ts +1 -1
  11. package/types/bytesToSize.d.ts +2 -2
  12. package/types/calculateCursorPosition.d.ts +2 -2
  13. package/types/checkFileType.d.ts +20 -0
  14. package/types/compressImage.d.ts +6 -5
  15. package/types/download.d.ts +2 -0
  16. package/types/fileReader.d.ts +1 -1
  17. package/types/filterTree.d.ts +2 -2
  18. package/types/findTreeNode.d.ts +1 -1
  19. package/types/findTreeNodes.d.ts +1 -1
  20. package/types/findTreeSelect.d.ts +1 -1
  21. package/types/formatBankCard.d.ts +2 -2
  22. package/types/formatMobile.d.ts +1 -1
  23. package/types/formatMoney.d.ts +5 -3
  24. package/types/getFileType.d.ts +9 -0
  25. package/types/isBankCard.d.ts +2 -2
  26. package/types/isBusinessLicense.d.ts +1 -1
  27. package/types/isChinese.d.ts +2 -2
  28. package/types/isIdCard.d.ts +2 -2
  29. package/types/isPassword.d.ts +3 -3
  30. package/types/isTWCard.d.ts +1 -1
  31. package/types/isValidNumber.d.ts +1 -1
  32. package/types/listToTree.d.ts +5 -5
  33. package/types/loadScript.d.ts +3 -3
  34. package/types/numberToChinese.d.ts +7 -7
  35. package/types/padZero.d.ts +1 -1
  36. package/types/randomString.d.ts +2 -2
  37. package/types/replaceChar.d.ts +3 -3
  38. package/types/round.d.ts +1 -1
  39. package/types/setDataURLPrefix.d.ts +2 -2
  40. package/types/transformFieldNames.d.ts +1 -1
  41. package/types/transformObjectValue.d.ts +1 -1
  42. package/types/validatePassword.d.ts +3 -3
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.1.1";
1
+ var VERSION = "5.1.3";
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.3";
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.3",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -36,7 +36,7 @@ declare class AsyncMemo<DataType = any> {
36
36
  * @param {string} [key] 缓存键,如果没有该值将直接执行异步方法。
37
37
  * @param {Object} [options] 配置项
38
38
  * @param {number} [options.ttl] 数据存活时间
39
- * @param {boolean} [options.persisted=true] 数据持久化,如果存在缓存数据,直接返回缓存数据,不再执行异步方法。<br/>即使不开启该配置,不影响在异步执行成功后缓存数据。
39
+ * @param {boolean} [options.persisted=true] 数据持久化,默认`true`。如果存在缓存数据,直接返回缓存数据,不再执行异步方法。<br/>即使不开启该配置,不影响在异步执行成功后缓存数据。
40
40
  * @returns {Promise<*>} 异步结果
41
41
  */
42
42
  run(asyncFn: (...args: any[]) => Promise<DataType>, key?: string, options?: {
@@ -10,8 +10,8 @@ type BytesToSizeOptions = {
10
10
  * @since 3.8.0
11
11
  * @param {number} bytes 字节大小
12
12
  * @param {Object} [options] 配置项
13
- * @param {string} [options.spaceMark=' '] 间隔字符
14
- * @param {number} [options.precision=2] 精度
13
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
14
+ * @param {number} [options.precision=2] 精度,默认`2`
15
15
  * @returns {string} 存储单位值
16
16
  * @example
17
17
  *
@@ -16,8 +16,8 @@ type CalculateCursorPositionOptions = {
16
16
  * @param {string} rawValue 当前输入原值
17
17
  * @param {string} ctrlValue 当前格式化后的值
18
18
  * @param {Object} [options] 配置项
19
- * @param {string|string[]} [options.placeholderChar=' '] 占位符
20
- * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认去掉非数字,意味着 ctrlValue 需要去掉非数字。
19
+ * @param {string|string[]} [options.placeholderChar=' '] 占位符,默认`' '`
20
+ * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认`/\D/g` 去掉非数字,意味着 ctrlValue 需要去掉非数字。
21
21
  * @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
22
22
  * @returns {number} 格式化后的光标位置
23
23
  */
@@ -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;
@@ -43,13 +43,13 @@ interface CompressImage {
43
43
  * @param {number} [options.width] 自定义图片宽度,默认图片自身宽度
44
44
  * @param {number} [options.height] 自定义图片高度,默认图片自身高度
45
45
  * @param {number} [options.rotate] 旋转
46
- * @param {Array | function} [options.offset=[0, 0]] x,y轴偏移值
47
- * @param {string} [options.background=#fff] 背景颜色
46
+ * @param {Array | function} [options.offset=[0, 0]] x,y轴偏移值,默认`[0, 0]`
47
+ * @param {string} [options.background=#fff] 背景颜色,默认`#fff`
48
48
  * @param {number | function} [options.canvasWidth] 画布宽度,默认图片宽度
49
49
  * @param {number | function} [options.canvasHeight] 画布高度,默认图片高度
50
- * @param {'blob' | 'dataURL'} [options.format='blob'] 导出格式
51
- * @param {string} [options.type='image/jpeg'] 图片类型
52
- * @param {number} [options.quality=0.8] 图片质量
50
+ * @param {'blob' | 'dataURL'} [options.format='blob'] 导出格式,默认`blob`
51
+ * @param {string} [options.type='image/jpeg'] 图片类型,默认`image/jpeg`
52
+ * @param {number} [options.quality=0.8] 图片质量,默认`0.8`
53
53
  * @param {function} [options.beforeCompress] 图片加载完成,画布创建之前调用
54
54
  * @param {function} [options.beforeDraw] 图片载入画布之前调用
55
55
  * @param {function} [options.afterDraw] 图片载入画布之后调用
@@ -60,6 +60,7 @@ interface CompressImage {
60
60
  * // 默认返回压缩后的 blob 对象
61
61
  * compressImage(file).then(blob=>{
62
62
  * // do something
63
+ * // 转为文件对象 new File([blob], file.name, { type: file.type })
63
64
  * });
64
65
  *
65
66
  * // 设置返回格式 data url
@@ -35,6 +35,8 @@ type DownloadOptions = {
35
35
  *
36
36
  * <em style="font-weight: bold;">注意:微信浏览器不支持H5下载文件。</em>
37
37
  *
38
+ * <em>响应头中有 "Content-Disposition" 字段,客户端获取不到?</em> 请参考查阅 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) 。
39
+ *
38
40
  * @static
39
41
  * @alias module:Other.download
40
42
  * @since 4.16.0
@@ -19,7 +19,7 @@ interface FileReader {
19
19
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader FileReader}
20
20
  * @since 4.16.0
21
21
  * @param {Blob} blob Blob 或 File 对象
22
- * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型
22
+ * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型,默认`dataURL`。可选 `arrayBuffer` `binaryString` `dataURL` `text` 。
23
23
  * @returns {Promise<string|ArrayBuffer>} 文件内容
24
24
  * @example
25
25
  * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
@@ -9,8 +9,8 @@ type NodeAssign = 'spread' | 'self';
9
9
  * @since 4.15.0
10
10
  * @param {Object[]} tree 树结构数据
11
11
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,结果将包含该节点
12
- * @param {string} [childrenField='children'] 子级字段名
13
- * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
12
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
13
+ * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式,默认`spread`。`spread`表示使用展开运算符创建新值,`self`-表示使用自身对象。
14
14
  * @returns {Object[]}
15
15
  * @example
16
16
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.14.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,将返回该节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object|undefined}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.15.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,返回结果将包含该节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object[]}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.14.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object[]}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -10,8 +10,8 @@ type Options = {
10
10
  * @since 1.1.0
11
11
  * @param {string} bankCardNo 要处理的字符串
12
12
  * @param {Object} [options] 配置项
13
- * @param {string} [options.spaceMark=' '] 间隔字符
14
- * @param {number} [options.length=4] 间隔长度
13
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
14
+ * @param {number} [options.length=4] 间隔长度,默认`4`
15
15
  * @returns {string} 格式化的银行卡号
16
16
  * @example
17
17
  *
@@ -9,7 +9,7 @@ type Options = {
9
9
  * @since 4.5.0
10
10
  * @param {string} mobileNo 手机号码
11
11
  * @param {Object} [options] 配置项
12
- * @param {string} [options.spaceMark=' '] 间隔字符
12
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
13
13
  * @returns {string} 格式化后的手机号码
14
14
  * @example
15
15
  *
@@ -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
  * 格式化金额
@@ -12,10 +13,11 @@ type Options = {
12
13
  * @since 1.1.0
13
14
  * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
14
15
  * @param {Object} [options] 金额格式化配置
15
- * @param {number} [options.precision=2] 保留位数 (最高:10位)
16
+ * @param {number} [options.precision=2] 保留位数,默认`2`。最高`10`。
16
17
  * @param {string} [options.symbol] 货币符号
17
- * @param {string} [options.thousand=","] 千分位符号
18
- * @param {string} [options.decimal="."] 小数位符号
18
+ * @param {string} [options.thousand=","] 千分位符号, 默认`,`
19
+ * @param {string} [options.decimal="."] 小数位符号,默认`.`
20
+ * @param {boolean} [options.strict=ture] 严格模式,默认`true`。开启后,只支持非空字符串和数字格式化,其他类型值如`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;
@@ -11,8 +11,8 @@ type Options = {
11
11
  * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html 常用银行账号位数参考}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
- * @param {boolean} [options.loose=false] 宽松模式,8-30位数字
15
- * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码
14
+ * @param {boolean} [options.loose=false] 宽松模式,默认`false`。正常模式10-21位数字(个人账户),宽松模式8-30位数字(企业账户)。
15
+ * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码,默认`false`
16
16
  * @returns {boolean} 值是否为银行卡号
17
17
  * @example
18
18
  *
@@ -10,7 +10,7 @@ type Options = {
10
10
  * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html GS15—2006 工商行政管理市场主体注册号编制规则}
11
11
  * @param {*} value 要检测的值
12
12
  * @param {Object} [options] 配置项
13
- * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
13
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,默认`true`。如果为false,不校验校验位。
14
14
  * @returns {boolean} 值是否为营业执照号
15
15
  * @example
16
16
  *
@@ -13,8 +13,8 @@ type Options = {
13
13
  * @see {@link https://zh.wikipedia.org/wiki/Unicode區段 Unicode区段}
14
14
  * @param {*} value 要检测的值
15
15
  * @param {Object} [options] 配置项
16
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
17
- * @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-I。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
16
+ * @param {boolean} [options.loose=false] 宽松模式,默认`false`。如果为`true`,只要包含中文就返回`true`
17
+ * @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-I,默认`false`。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
18
18
  * @returns {boolean} 值是否为中文
19
19
  * @example
20
20
  *
@@ -14,8 +14,8 @@ type Options = {
14
14
  * @see {@link https://baike.baidu.com/item/居民身份证号码 居民身份证号码}
15
15
  * @param {*} value 要检测的值
16
16
  * @param {Object} [options] 配置项
17
- * @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
18
- * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,仅支持18位身份证号码
17
+ * @param {boolean} [options.loose=false] 宽松模式,默认`false`。如果为`true`,支持15位身份证号码
18
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,默认`true`。仅在`loose=false`时生效
19
19
  * @returns {boolean} 值是否为身份证号
20
20
  * @example
21
21
  *
@@ -11,9 +11,9 @@ import validatePassword from './validatePassword';
11
11
  * @see {@link https://baike.baidu.com/item/ASCII#3 ASCII}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
- * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
15
- * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
16
- * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
14
+ * @param {number} [options.level=2] 密码强度,默认`2`。`1`-包含一种字符 `2`-包含两种字符 `3`-包含三种字符。(大写字母、小写字母、数字、特殊字符)
15
+ * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,默认`false`。为 ture 时,大小写字母视为一种字符
16
+ * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符,默认`!@#$%^&*()-=_+[]\|{},./?<>~`
17
17
  * @returns {boolean} 值是否符合密码强度
18
18
  * @example
19
19
  *
@@ -10,7 +10,7 @@ type Options = {
10
10
  * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证 台湾居民来往大陆通行证}
11
11
  * @param {*} value 要检测的值
12
12
  * @param {Object} [options] 配置项
13
- * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
13
+ * @param {boolean} [options.loose=false] 宽松模式,默认`false`。如果为true,表示支持一次性短期通行证
14
14
  * @returns {boolean} 是否为台湾居民来往大陆通行证
15
15
  * @example
16
16
  *
@@ -5,7 +5,7 @@
5
5
  * @alias module:Validator.isValidNumber
6
6
  * @since 4.17.2
7
7
  * @param {*} value 待检测的值
8
- * @param {boolean} [strict=false] 严格模式,如果为 true ,仅支持字符串和数字类型,不处理其他类型隐式转换,且空字符串返回 false 。
8
+ * @param {boolean} [strict=false] 严格模式,默认`false`。如果为 true ,仅支持字符串和数字类型,不处理其他类型隐式转换,且空字符串返回 false 。
9
9
  * @returns {boolean} 值是否为有效数值
10
10
  * @example
11
11
  *
@@ -14,11 +14,11 @@ type Options = {
14
14
  * @since 4.14.0
15
15
  * @param {Object[]} list 列表数据
16
16
  * @param {Object} [options] 配置项
17
- * @param {string} [options.keyField='id'] 当前数据的键值字段名称
18
- * @param {string} [options.parentField='pid'] 当前数据的父级字段名称
19
- * @param {string} [options.childrenField='children'] 子级字段名称
20
- * @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为nullarray表示为[]
21
- * @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
17
+ * @param {string} [options.keyField='id'] 当前数据的键值字段名称,默认`id`
18
+ * @param {string} [options.parentField='pid'] 当前数据的父级字段名称,默认`pid`
19
+ * @param {string} [options.childrenField='children'] 子级字段名称,默认`children`
20
+ * @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,默认`none`。`none`表示删除该子级,`null`表示为`null`,`array`表示为`[]`。
21
+ * @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式,默认`spread`。`spread`表示使用展开运算符创建新值,`self`表示使用自身对象。
22
22
  * @returns {Object[]} 树结构
23
23
  * @example
24
24
  *
@@ -12,10 +12,10 @@ type ScriptAttribute = Pick<HTMLScriptElement, 'async' | 'crossOrigin' | 'defer'
12
12
  * @since 4.19.0
13
13
  * @param {string} src js 地址。
14
14
  * @param {Object} [options] script 标签属性。比如 `defer` `onload` `onerror` `id` 等,下面列举部分带有默认值或额外扩展的配置。
15
- * @param {boolean} [options.destroyOnError=true] 如果加载失败或错误,自动删除 dom 中的 script 标签。
15
+ * @param {boolean} [options.destroyOnError=true] 如果加载失败或错误,自动删除 dom 中的 script 标签。默认`true`
16
16
  * @param {Object} [options.attrs] 自定义 script 属性,通过 script.setAttribute 设置。
17
- * @param {boolean} [options.async=true] 异步加载。
18
- * @param {string} [options.type='text/javascript'] 类型。
17
+ * @param {boolean} [options.async=true] 异步加载。默认`true`
18
+ * @param {string} [options.type='text/javascript'] 类型。默认`text/javascript`
19
19
  * @return {Promise<HTMLScriptElement>} 异步返回 script 元素。
20
20
  * @example
21
21
  *
@@ -20,14 +20,14 @@ type Options = {
20
20
  * @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 出版物上数字用法}
21
21
  * @param {number} num 数字
22
22
  * @param {Object} [options] 配置项
23
- * @param {boolean} [options.big5=false] 繁体
24
- * @param {boolean} [options.unit=true] 计数单位
25
- * @param {string} [options.decimal="点"] 中文小数点,繁体字为點
26
- * @param {string} [options.zero="零"] 设置0。常用配置
27
- * @param {string} [options.negative="负"] 负数前面的字
23
+ * @param {boolean} [options.big5=false] 繁体,默认`false`
24
+ * @param {boolean} [options.unit=true] 计数单位,默认`true`
25
+ * @param {string} [options.decimal="点"] 中文小数点。默认`点`,当`big5=true`时,默认`點`
26
+ * @param {string} [options.zero="零"] 设置0,默认`零`。常用配置
27
+ * @param {string} [options.negative="负"] 负数前面的字,默认`负`
28
28
  * @param {Object} [options.unitConfig] 节点单位配置
29
- * @param {string} [options.unitConfig.w="万"] 设置计数单位万。常用配置
30
- * @param {string} [options.unitConfig.y="亿"] 设置计数单位亿。常用配置
29
+ * @param {string} [options.unitConfig.w="万"] 设置计数单位万,默认`万`。常用配置
30
+ * @param {string} [options.unitConfig.y="亿"] 设置计数单位亿,默认`亿`。常用配置
31
31
  * @returns {string} 中文数字
32
32
  * @example
33
33
  *
@@ -5,7 +5,7 @@
5
5
  * @alias module:Processor.padZero
6
6
  * @since 4.7.0
7
7
  * @param {string|number} value 要处理的值
8
- * @param {number} [size=2] 指定字符串长度
8
+ * @param {number} [size=2] 指定字符串长度,默认`2`
9
9
  * @returns {string} 用零填充数字到给定长度的字符串
10
10
  * @example
11
11
  * padZero(5); // 05
@@ -8,8 +8,8 @@ interface RandomString {
8
8
  * @function
9
9
  * @alias module:Other.randomString
10
10
  * @since 4.8.0
11
- * @param {number} [len=0] 长度
12
- * @param {'number' | 'lower' | 'upper' | string} [pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 字符池,默认为数字和大小写字母,支持number/lower/upper
11
+ * @param {number} [len=0] 长度,默认`0`
12
+ * @param {'number' | 'lower' | 'upper' | string} [pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'] 字符池,默认为数字和大小写字母。支持设置类型`number` `lower` `upper` 或字符串。
13
13
  * @returns {string} 随机字符串
14
14
  * @example
15
15
  *
@@ -13,9 +13,9 @@ type Options = {
13
13
  * @since 1.1.0
14
14
  * @param {string} str 要处理的字符串
15
15
  * @param {Object} [options] 配置项
16
- * @param {number} [options.start=3] 开始位置
17
- * @param {number} [options.end=-4] 结束位置
18
- * @param {string} [options.char="*"] 替换字符
16
+ * @param {number} [options.start=3] 开始位置,默认`3`
17
+ * @param {number} [options.end=-4] 结束位置,默认`-4`
18
+ * @param {string} [options.char="*"] 替换字符,默认`*`
19
19
  * @param {number} [options.repeat] 替换字符的重复次数,默认为替换内容长度,可设置为固定值
20
20
  * @param {string} [options.exclude] 排除字符,如果指定排除项,repeat设置无效
21
21
  * @returns {string} 处理后的字符
package/types/round.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @alias module:Math.round
6
6
  * @since 3.1.0
7
7
  * @param {number|string} num 要四舍五入的数字
8
- * @param {number} [precision=0] 四舍五入的精度
8
+ * @param {number} [precision=0] 四舍五入的精度,默认`0`
9
9
  * @returns {number} 四舍五入的数字
10
10
  * @example
11
11
  *
@@ -9,8 +9,8 @@
9
9
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URLs}
10
10
  * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types MIME types}
11
11
  * @param {string} data 数据本身
12
- * @param {string} [mimeType="image/png"] MIME 类型
13
- * @param {boolean} [base64=true] 添加 base64 标识
12
+ * @param {string} [mimeType="image/png"] MIME 类型,默认`image/png`
13
+ * @param {boolean} [base64=true] 添加 base64 标识,默认`true`
14
14
  * @returns {string} DataURL 格式的字符串
15
15
  * @example
16
16
  *
@@ -12,7 +12,7 @@ type TransformFieldNames<D extends any, F extends Record<string, any>, C extends
12
12
  * @param {Object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
13
13
  * @param {Object} fieldNames 字段名映射
14
14
  * @param {string} [childrenField] 子级数据字段名
15
- * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
15
+ * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式,默认`spread`。`spread`表示使用展开运算符创建新值,`self`表示使用自身对象。
16
16
  * @returns {Object[]}
17
17
  * @example
18
18
  *
@@ -15,7 +15,7 @@ interface TransformObjectValue {
15
15
  * @since 4.23.0
16
16
  * @param {Array | Object} data 要转换值的普通对象或数组
17
17
  * @param {Function} fn 遍历普通对象或数组键值方法
18
- * @param {boolean} [deep=true] 深度遍历,检测值为普通对象或数组时递归处理。默认 true
18
+ * @param {boolean} [deep=true] 深度遍历,检测值为普通对象或数组时递归处理。默认`true`
19
19
  * @returns {Array | Object} 如果是普通对象或数组,返回一个新的对象或数组,否则返回自身
20
20
  * @example
21
21
  *
@@ -26,9 +26,9 @@ type Options = {
26
26
  * @see {@link https://baike.baidu.com/item/ASCII#3 ASCII}
27
27
  * @param {string} value 要检测的值
28
28
  * @param {Object} [options] 配置项
29
- * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
30
- * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
31
- * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
29
+ * @param {number} [options.level=2] 密码强度,默认`2`。`1`-包含一种字符 `2`-包含两种字符 `3`-包含三种字符。(大写字母、小写字母、数字、特殊字符)
30
+ * @param {boolean} [options.ignoreCase=false] 是否忽略大小写,默认`false`。如果为`ture`,大小写字母视为一种字符
31
+ * @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符,默认`!@#$%^&*()-=_+[]\|{},./?<>~`
32
32
  * @returns {ValidatePasswordReturn} 验证结果
33
33
  * @example
34
34
  *