util-helpers 4.21.2 → 4.21.4

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 = "4.21.2";
1
+ var VERSION = "4.21.4";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
package/esm/index.js CHANGED
@@ -64,6 +64,6 @@ export { default as findTreeSelect } from './findTreeSelect.js';
64
64
  export { setDisableWarning } from './utils/config.js';
65
65
  export { default as VERSION } from './VERSION.js';
66
66
 
67
- var version = "4.21.2";
67
+ var version = "4.21.4";
68
68
 
69
69
  export { version };
package/esm/isChinese.js CHANGED
@@ -1,18 +1,23 @@
1
1
  import { toString } from 'ut2';
2
+ import { objectValues } from './utils/native.js';
2
3
 
3
4
  var chineseDictionary = {
4
5
  chineseBasic: '[\u4e00-\u9fa5]',
5
- chineseExtend: '[\u9ea6-\u9fef]',
6
- chineseExtendA: '[\u3400-\u4DB5]',
7
- chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
8
- chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
6
+ chineseExtend: '[\u9ea6-\u9fff]',
7
+ chineseExtend2: '[\uF900-\uFAD9]',
8
+ chineseExtendA: '[\u3400-\u4DBF]',
9
+ chineseExtendB: "[\uD840\uDC00-\uD869\uDEDF]",
10
+ chineseExtendC: "[\uD869\uDF00-\uD86D\uDF38]",
9
11
  chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
10
12
  chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
11
- chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
13
+ chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]",
14
+ chineseExtendG: "[\uD880\uDC00-\uD884\uDF4A]",
15
+ chineseExtendH: "[\uD884\uDF50-\uD888\uDFAF]",
16
+ chineseExtendI: "[\uD87A\uDFF0-\uD87B\uDE5D]"
12
17
  };
13
18
  var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
14
19
  var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
15
- var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
20
+ var chineseWithExtend = '(?:' + objectValues(chineseDictionary).join('|') + ')';
16
21
  var looseChineseExtendRegExp = chineseWithExtend + '+';
17
22
  var chineseExtendRegExp = '^' + chineseWithExtend + '+$';
18
23
  var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
@@ -20,11 +20,14 @@ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
20
20
  if (childrenField && isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
21
21
  newItem[childrenField] = recusion(newItem[childrenField].slice());
22
22
  }
23
- objectKeys(fieldNames).forEach(function (newKey) {
23
+ var newKeys = objectKeys(fieldNames);
24
+ newKeys.forEach(function (newKey) {
24
25
  var oldKey = fieldNames[newKey];
25
26
  if (oldKey in newItem) {
26
27
  newItem[newKey] = newItem[oldKey];
27
- delKeys.push(oldKey);
28
+ if (newKeys.indexOf(oldKey) === -1) {
29
+ delKeys.push(oldKey);
30
+ }
28
31
  }
29
32
  });
30
33
  if (delKeys.length > 0) {
@@ -2,7 +2,8 @@ import { constant, noop } from 'ut2';
2
2
  import { URLExisted } from './setup.js';
3
3
 
4
4
  var objectKeys = Object.keys;
5
+ var objectValues = Object.values;
5
6
  var createObjectURL = URLExisted ? URL.createObjectURL : constant('');
6
7
  var revokeObjectURL = URLExisted ? URL.revokeObjectURL : noop;
7
8
 
8
- export { createObjectURL, objectKeys, revokeObjectURL };
9
+ export { createObjectURL, objectKeys, objectValues, revokeObjectURL };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.21.2";
3
+ var VERSION = "4.21.4";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
package/lib/index.js CHANGED
@@ -66,7 +66,7 @@ var findTreeSelect = require('./findTreeSelect.js');
66
66
  var config = require('./utils/config.js');
67
67
  var VERSION = require('./VERSION.js');
68
68
 
69
- exports.version = "4.21.2";
69
+ exports.version = "4.21.4";
70
70
 
71
71
  exports.isMobile = isMobile;
72
72
  exports.isTelephone = isTelephone;
package/lib/isChinese.js CHANGED
@@ -1,20 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  var ut2 = require('ut2');
4
+ var native = require('./utils/native.js');
4
5
 
5
6
  var chineseDictionary = {
6
7
  chineseBasic: '[\u4e00-\u9fa5]',
7
- chineseExtend: '[\u9ea6-\u9fef]',
8
- chineseExtendA: '[\u3400-\u4DB5]',
9
- chineseExtendB: "[\uD840\uDC00-\uD869\uDED6]",
10
- chineseExtendC: "[\uD869\uDF00-\uD86D\uDF34]",
8
+ chineseExtend: '[\u9ea6-\u9fff]',
9
+ chineseExtend2: '[\uF900-\uFAD9]',
10
+ chineseExtendA: '[\u3400-\u4DBF]',
11
+ chineseExtendB: "[\uD840\uDC00-\uD869\uDEDF]",
12
+ chineseExtendC: "[\uD869\uDF00-\uD86D\uDF38]",
11
13
  chineseExtendD: "[\uD86D\uDF40-\uD86E\uDC1D]",
12
14
  chineseExtendE: "[\uD86E\uDC20-\uD873\uDEA1]",
13
- chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]"
15
+ chineseExtendF: "[\uD873\uDEB0-\uD87A\uDFE0]",
16
+ chineseExtendG: "[\uD880\uDC00-\uD884\uDF4A]",
17
+ chineseExtendH: "[\uD884\uDF50-\uD888\uDFAF]",
18
+ chineseExtendI: "[\uD87A\uDFF0-\uD87B\uDE5D]"
14
19
  };
15
20
  var looseChineseRegExp = chineseDictionary.chineseBasic + '+';
16
21
  var chineseRegExp = '^' + chineseDictionary.chineseBasic + '+$';
17
- var chineseWithExtend = '(?:' + chineseDictionary.chineseBasic + '|' + chineseDictionary.chineseExtend + '|' + chineseDictionary.chineseExtendA + '|' + chineseDictionary.chineseExtendB + '|' + chineseDictionary.chineseExtendC + '|' + chineseDictionary.chineseExtendD + '|' + chineseDictionary.chineseExtendE + '|' + chineseDictionary.chineseExtendF + ')';
22
+ var chineseWithExtend = '(?:' + native.objectValues(chineseDictionary).join('|') + ')';
18
23
  var looseChineseExtendRegExp = chineseWithExtend + '+';
19
24
  var chineseExtendRegExp = '^' + chineseWithExtend + '+$';
20
25
  var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
@@ -22,11 +22,14 @@ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
22
22
  if (childrenField && ut2.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
23
23
  newItem[childrenField] = recusion(newItem[childrenField].slice());
24
24
  }
25
- native.objectKeys(fieldNames).forEach(function (newKey) {
25
+ var newKeys = native.objectKeys(fieldNames);
26
+ newKeys.forEach(function (newKey) {
26
27
  var oldKey = fieldNames[newKey];
27
28
  if (oldKey in newItem) {
28
29
  newItem[newKey] = newItem[oldKey];
29
- delKeys.push(oldKey);
30
+ if (newKeys.indexOf(oldKey) === -1) {
31
+ delKeys.push(oldKey);
32
+ }
30
33
  }
31
34
  });
32
35
  if (delKeys.length > 0) {
@@ -4,5 +4,6 @@ var ut2 = require('ut2');
4
4
  var setup = require('./setup.js');
5
5
 
6
6
  exports.objectKeys = Object.keys;
7
+ exports.objectValues = Object.values;
7
8
  exports.createObjectURL = setup.URLExisted ? URL.createObjectURL : ut2.constant('');
8
9
  exports.revokeObjectURL = setup.URLExisted ? URL.revokeObjectURL : ut2.noop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.21.2",
3
+ "version": "4.21.4",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -24,7 +24,7 @@
24
24
  "commit": "cz",
25
25
  "prepublishOnly": "npm test && npm run build",
26
26
  "tsc": "tsc --noEmit",
27
- "prepare": "husky install"
27
+ "prepare": "husky"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
@@ -51,34 +51,36 @@
51
51
  },
52
52
  "homepage": "https://doly-dev.github.io/util-helpers/index.html",
53
53
  "devDependencies": {
54
- "@babel/core": "^7.23.9",
55
- "@babel/preset-env": "^7.23.9",
56
- "@babel/preset-typescript": "^7.23.3",
54
+ "@babel/core": "^7.24.3",
55
+ "@babel/preset-env": "^7.24.3",
56
+ "@babel/preset-typescript": "^7.24.1",
57
57
  "@commitlint/cli": "^17.8.1",
58
58
  "@commitlint/config-conventional": "^17.8.1",
59
+ "@commitlint/cz-commitlint": "^17.8.1",
59
60
  "@rollup/plugin-commonjs": "^25.0.7",
60
61
  "@rollup/plugin-node-resolve": "^15.2.3",
61
62
  "@rollup/plugin-replace": "^5.0.5",
62
63
  "@rollup/plugin-terser": "^0.4.4",
63
64
  "@rollup/plugin-typescript": "^11.1.6",
64
65
  "@types/jest": "^29.5.12",
65
- "@typescript-eslint/eslint-plugin": "^5.62.0",
66
- "@typescript-eslint/parser": "^5.62.0",
66
+ "@typescript-eslint/eslint-plugin": "^7.3.1",
67
+ "@typescript-eslint/parser": "^7.3.1",
67
68
  "babel-jest": "^29.7.0",
68
69
  "babel-plugin-minify-replace": "^0.5.0",
70
+ "commitizen": "^4.3.0",
69
71
  "cross-env": "^7.0.3",
70
- "cz-conventional-changelog": "^3.3.0",
71
72
  "docdash": "^2.0.2",
72
- "eslint": "^8.56.0",
73
- "husky": "^8.0.3",
73
+ "eslint": "^8.57.0",
74
+ "husky": "^9.0.11",
75
+ "inquirer": "8",
74
76
  "jest": "^29.7.0",
75
77
  "jest-canvas-mock": "^2.5.2",
76
78
  "jest-environment-jsdom": "^29.7.0",
77
79
  "jsdoc": "^4.0.2",
78
80
  "lint-staged": "^13.3.0",
79
- "prettier": "^2.8.8",
80
- "rollup": "^3.29.4",
81
- "typescript": "^5.3.3"
81
+ "prettier": "^3.2.5",
82
+ "rollup": "^4.13.0",
83
+ "typescript": "^5.4.3"
82
84
  },
83
85
  "lint-staged": {
84
86
  "**/*.ts": "eslint",
@@ -86,7 +88,7 @@
86
88
  },
87
89
  "config": {
88
90
  "commitizen": {
89
- "path": "./node_modules/cz-conventional-changelog"
91
+ "path": "@commitlint/cz-commitlint"
90
92
  }
91
93
  },
92
94
  "dependencies": {
package/types/ajax.d.ts CHANGED
@@ -25,7 +25,7 @@ type AjaxOptions = {
25
25
  * @property {boolean} [async=true] 是否异步执行操作
26
26
  * @property {string|null} [user=null] 用户名,用于认证用途
27
27
  * @property {string|null} [password=null] 密码,用于认证用途
28
- * @property {object} [headers] 自定义请求头
28
+ * @property {Object} [headers] 自定义请求头
29
29
  * @property {string} [responseType] 响应类型
30
30
  * @property {number} [timeout] 请求超时的毫秒数
31
31
  * @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
@@ -7,11 +7,11 @@ type NodeAssign = 'spread' | 'self';
7
7
  * @static
8
8
  * @alias module:Tree.filterTree
9
9
  * @since 4.15.0
10
- * @param {object[]} tree 树结构数据
10
+ * @param {Object[]} tree 树结构数据
11
11
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,结果将包含该节点
12
12
  * @param {string} [childrenField='children'] 子级字段名
13
13
  * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
14
- * @returns {object[]}
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' }]}];
17
17
  *
@@ -4,10 +4,10 @@
4
4
  * @static
5
5
  * @alias module:Tree.findTreeNode
6
6
  * @since 4.14.0
7
- * @param {object[]} tree 树结构数据
7
+ * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,将返回该节点
9
9
  * @param {string} [childrenField='children'] 子级字段名
10
- * @returns {object|undefined}
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' }]}];
13
13
  *
@@ -4,10 +4,10 @@
4
4
  * @static
5
5
  * @alias module:Tree.findTreeNodes
6
6
  * @since 4.15.0
7
- * @param {object[]} tree 树结构数据
7
+ * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,返回结果将包含该节点
9
9
  * @param {string} [childrenField='children'] 子级字段名
10
- * @returns {object[]}
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' }]}];
13
13
  *
@@ -4,10 +4,10 @@
4
4
  * @static
5
5
  * @alias module:Tree.findTreeSelect
6
6
  * @since 4.14.0
7
- * @param {object[]} tree 树结构数据
7
+ * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
9
9
  * @param {string} [childrenField='children'] 子级字段名
10
- * @returns {object[]}
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' }]}];
13
13
  *
@@ -10,7 +10,7 @@ type Options = {
10
10
  * @alias module:Processor.formatMobile
11
11
  * @since 4.5.0
12
12
  * @param {string} mobileNo 手机号码
13
- * @param {object} [options] 配置项
13
+ * @param {Object} [options] 配置项
14
14
  * @param {string} [options.spaceMark=' '] 间隔字符
15
15
  * @returns {string} 格式化后的手机号码
16
16
  * @example
@@ -14,7 +14,7 @@ type Options = {
14
14
  * @param {*} value 要检测的值
15
15
  * @param {Object} [options] 配置项
16
16
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
17
- * @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-F。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
17
+ * @param {boolean} [options.useExtend=false] 使用统一表意文字扩展A-I。注意:如果不支持 `RegExp.prototype.unicode`,扩展字符集将自动不生效,如IE浏览器。
18
18
  * @returns {boolean} 值是否为中文
19
19
  * @example
20
20
  *
@@ -12,14 +12,14 @@ type Options = {
12
12
  * @static
13
13
  * @alias module:Tree.listToTree
14
14
  * @since 4.14.0
15
- * @param {object[]} list 列表数据
16
- * @param {object} [options] 配置项
15
+ * @param {Object[]} list 列表数据
16
+ * @param {Object} [options] 配置项
17
17
  * @param {string} [options.keyField='id'] 当前数据的键值字段名称
18
18
  * @param {string} [options.parentField='pid'] 当前数据的父级字段名称
19
19
  * @param {string} [options.childrenField='children'] 子级字段名称
20
20
  * @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
21
21
  * @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
22
- * @returns {object[]} 树结构
22
+ * @returns {Object[]} 树结构
23
23
  * @example
24
24
  *
25
25
  * const menus = [
@@ -9,11 +9,11 @@ type TransformFieldNames<D extends any, F extends Record<string, any>, C extends
9
9
  * @static
10
10
  * @alias module:Tree.transformFieldNames
11
11
  * @since 4.14.0
12
- * @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
13
- * @param {function} fieldNames 字段名映射
12
+ * @param {Object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
13
+ * @param {Object} fieldNames 字段名映射
14
14
  * @param {string} [childrenField] 子级数据字段名
15
15
  * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
16
- * @returns {object[]}
16
+ * @returns {Object[]}
17
17
  * @example
18
18
  *
19
19
  * const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
@@ -4,9 +4,9 @@
4
4
  * @static
5
5
  * @alias module:Tree.treeToList
6
6
  * @since 4.14.0
7
- * @param {object[]} tree 树结构数据
7
+ * @param {Object[]} tree 树结构数据
8
8
  * @param {string} childrenField 子级字段名称
9
- * @returns {object[]} 列表数据
9
+ * @returns {Object[]} 列表数据
10
10
  * @example
11
11
  * 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' }]}];
12
12
  *
@@ -2,5 +2,11 @@ export declare const objectKeys: {
2
2
  (o: object): string[];
3
3
  (o: {}): string[];
4
4
  };
5
+ export declare const objectValues: {
6
+ <T>(o: {
7
+ [s: string]: T;
8
+ } | ArrayLike<T>): T[];
9
+ (o: {}): any[];
10
+ };
5
11
  export declare const createObjectURL: (obj: Blob | MediaSource) => string;
6
12
  export declare const revokeObjectURL: (url: string) => void;