ut2 1.19.1 → 1.20.1

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/es/has.js ADDED
@@ -0,0 +1,12 @@
1
+ import hasPath from './internals/hasPath.js';
2
+ import { objectProtoHasOwnProperty } from './internals/native.js';
3
+ import isNil from './isNil.js';
4
+
5
+ function baseHas(object, key) {
6
+ return objectProtoHasOwnProperty.call(object, key);
7
+ }
8
+ function has(object, key) {
9
+ return !isNil(object) && hasPath(object, key, baseHas);
10
+ }
11
+
12
+ export { has as default };
package/es/hasIn.js ADDED
@@ -0,0 +1,11 @@
1
+ import hasPath from './internals/hasPath.js';
2
+ import isNil from './isNil.js';
3
+
4
+ function baseHasIn(object, key) {
5
+ return key in Object(object);
6
+ }
7
+ function hasIn(object, key) {
8
+ return !isNil(object) && hasPath(object, key, baseHasIn);
9
+ }
10
+
11
+ export { hasIn as default };
package/es/index.js CHANGED
@@ -93,6 +93,8 @@ export { default as get } from './get.js';
93
93
  export { default as invert } from './invert.js';
94
94
  export { default as keys } from './keys.js';
95
95
  export { default as keysIn } from './keysIn.js';
96
+ export { default as has } from './has.js';
97
+ export { default as hasIn } from './hasIn.js';
96
98
  export { default as merge } from './merge.js';
97
99
  export { default as mergeObject } from './mergeObject.js';
98
100
  export { default as omit } from './omit.js';
@@ -63,9 +63,7 @@ function baseDebounce(func, wait, immediate, __throttle__) {
63
63
  if (timer !== nativeUndefined) {
64
64
  clearTimeout(timer);
65
65
  timer = nativeUndefined;
66
- if (lastArgs) {
67
- return invokeFunc(Date.now());
68
- }
66
+ return invokeFunc(Date.now());
69
67
  }
70
68
  return result;
71
69
  }
@@ -0,0 +1,21 @@
1
+ import isNil from '../isNil.js';
2
+ import toPath from '../toPath.js';
3
+
4
+ function hasPath(object, key, hasFunc) {
5
+ var paths = toPath(key, object);
6
+ var length = paths.length;
7
+ var index = 0;
8
+ var result = true;
9
+ while (!isNil(object) && index < length) {
10
+ var key_1 = paths[index];
11
+ result = hasFunc(object, key_1);
12
+ if (!result) {
13
+ break;
14
+ }
15
+ object = object[key_1];
16
+ index++;
17
+ }
18
+ return !!index && index === length && result;
19
+ }
20
+
21
+ export { hasPath as default };
@@ -2,7 +2,7 @@ import isObjectLike from '../isObjectLike.js';
2
2
  import getTag from './getTag.js';
3
3
  import { argumentsTag, functionProtoToString, stringUndefined } from './native.js';
4
4
 
5
- var VERSION = "1.19.1";
5
+ var VERSION = "1.20.1";
6
6
  var isBrowser = typeof window !== stringUndefined && isObjectLike(window) && typeof document !== stringUndefined && isObjectLike(document) && window.document === document;
7
7
  var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
8
8
  var FUNC_ERROR_TEXT = 'Expected a function';
@@ -11,12 +11,12 @@ function toSource(func) {
11
11
  try {
12
12
  return functionProtoToString.call(func);
13
13
  }
14
- catch (e) {
14
+ catch (err) {
15
15
  }
16
16
  try {
17
17
  return func + '';
18
18
  }
19
- catch (e) {
19
+ catch (err) {
20
20
  }
21
21
  }
22
22
  return '';
@@ -9,7 +9,7 @@ var nodeUtil = (function () {
9
9
  return types;
10
10
  }
11
11
  }
12
- catch (e) {
12
+ catch (err) {
13
13
  }
14
14
  })();
15
15
  var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer;
package/es/toPath.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import stringToPath from './internals/stringToPath.js';
2
2
  import isArray from './isArray.js';
3
+ import isNil from './isNil.js';
3
4
  import isObject from './isObject.js';
4
5
  import isSymbol from './isSymbol.js';
5
6
  import toString from './toString.js';
6
7
 
7
8
  function toKey(value) {
8
- return isSymbol(value) ? value : toString(value);
9
+ return isSymbol(value) ? value : isNil(value) ? value + '' : toString(value);
9
10
  }
10
11
  function toPath(value, object) {
11
12
  if (isArray(value)) {
package/es/words.js CHANGED
@@ -1,4 +1,4 @@
1
- var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
1
+ var reAsciiWord = /[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
2
2
  function words(string, pattern) {
3
3
  if (pattern === void 0) { pattern = reAsciiWord; }
4
4
  return string.match(pattern) || [];
package/lib/has.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var hasPath = require('./internals/hasPath.js');
4
+ var native = require('./internals/native.js');
5
+ var isNil = require('./isNil.js');
6
+
7
+ function baseHas(object, key) {
8
+ return native.objectProtoHasOwnProperty.call(object, key);
9
+ }
10
+ function has(object, key) {
11
+ return !isNil(object) && hasPath(object, key, baseHas);
12
+ }
13
+
14
+ module.exports = has;
package/lib/hasIn.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var hasPath = require('./internals/hasPath.js');
4
+ var isNil = require('./isNil.js');
5
+
6
+ function baseHasIn(object, key) {
7
+ return key in Object(object);
8
+ }
9
+ function hasIn(object, key) {
10
+ return !isNil(object) && hasPath(object, key, baseHasIn);
11
+ }
12
+
13
+ module.exports = hasIn;
package/lib/index.js CHANGED
@@ -95,6 +95,8 @@ var get = require('./get.js');
95
95
  var invert = require('./invert.js');
96
96
  var keys = require('./keys.js');
97
97
  var keysIn = require('./keysIn.js');
98
+ var has = require('./has.js');
99
+ var hasIn = require('./hasIn.js');
98
100
  var merge = require('./merge.js');
99
101
  var mergeObject = require('./mergeObject.js');
100
102
  var omit = require('./omit.js');
@@ -247,6 +249,8 @@ exports.get = get;
247
249
  exports.invert = invert;
248
250
  exports.keys = keys;
249
251
  exports.keysIn = keysIn;
252
+ exports.has = has;
253
+ exports.hasIn = hasIn;
250
254
  exports.merge = merge;
251
255
  exports.mergeObject = mergeObject;
252
256
  exports.omit = omit;
@@ -65,9 +65,7 @@ function baseDebounce(func, wait, immediate, __throttle__) {
65
65
  if (timer !== native.nativeUndefined) {
66
66
  clearTimeout(timer);
67
67
  timer = native.nativeUndefined;
68
- if (lastArgs) {
69
- return invokeFunc(Date.now());
70
- }
68
+ return invokeFunc(Date.now());
71
69
  }
72
70
  return result;
73
71
  }
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var isNil = require('../isNil.js');
4
+ var toPath = require('../toPath.js');
5
+
6
+ function hasPath(object, key, hasFunc) {
7
+ var paths = toPath(key, object);
8
+ var length = paths.length;
9
+ var index = 0;
10
+ var result = true;
11
+ while (!isNil(object) && index < length) {
12
+ var key_1 = paths[index];
13
+ result = hasFunc(object, key_1);
14
+ if (!result) {
15
+ break;
16
+ }
17
+ object = object[key_1];
18
+ index++;
19
+ }
20
+ return !!index && index === length && result;
21
+ }
22
+
23
+ module.exports = hasPath;
@@ -4,7 +4,7 @@ var isObjectLike = require('../isObjectLike.js');
4
4
  var getTag = require('./getTag.js');
5
5
  var native = require('./native.js');
6
6
 
7
- var VERSION = "1.19.1";
7
+ var VERSION = "1.20.1";
8
8
  var isBrowser = typeof window !== native.stringUndefined && isObjectLike(window) && typeof document !== native.stringUndefined && isObjectLike(document) && window.document === document;
9
9
  var supportedArgumentsType = getTag((function () { return arguments; })()) === native.argumentsTag;
10
10
  var FUNC_ERROR_TEXT = 'Expected a function';
@@ -13,12 +13,12 @@ function toSource(func) {
13
13
  try {
14
14
  return native.functionProtoToString.call(func);
15
15
  }
16
- catch (e) {
16
+ catch (err) {
17
17
  }
18
18
  try {
19
19
  return func + '';
20
20
  }
21
- catch (e) {
21
+ catch (err) {
22
22
  }
23
23
  }
24
24
  return '';
@@ -11,7 +11,7 @@ var nodeUtil = (function () {
11
11
  return types;
12
12
  }
13
13
  }
14
- catch (e) {
14
+ catch (err) {
15
15
  }
16
16
  })();
17
17
  var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer;
package/lib/toPath.js CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  var stringToPath = require('./internals/stringToPath.js');
4
4
  var isArray = require('./isArray.js');
5
+ var isNil = require('./isNil.js');
5
6
  var isObject = require('./isObject.js');
6
7
  var isSymbol = require('./isSymbol.js');
7
8
  var toString = require('./toString.js');
8
9
 
9
10
  function toKey(value) {
10
- return isSymbol(value) ? value : toString(value);
11
+ return isSymbol(value) ? value : isNil(value) ? value + '' : toString(value);
11
12
  }
12
13
  function toPath(value, object) {
13
14
  if (isArray(value)) {
package/lib/words.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
3
+ var reAsciiWord = /[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
4
4
  function words(string, pattern) {
5
5
  if (pattern === void 0) { pattern = reAsciiWord; }
6
6
  return string.match(pattern) || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ut2",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
4
4
  "author": "caijf",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -18,7 +18,7 @@
18
18
  "build:doc": "npm run doc",
19
19
  "doc": "rm -rf docs && rm -rf docs-src && tsc -p tsconfig.build.json -t esnext --outDir docs-src && jsdoc -c conf.json && rm -rf docs-src",
20
20
  "doc:open": "open ./docs/index.html",
21
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
21
+ "lint": "eslint .",
22
22
  "lint:fix": "npm run lint:js -- --fix",
23
23
  "prettier": "prettier -w **/*",
24
24
  "commit": "cz",
@@ -59,34 +59,35 @@
59
59
  "registry": "https://registry.npmjs.org/"
60
60
  },
61
61
  "devDependencies": {
62
- "@commitlint/cli": "^19.8.0",
63
- "@commitlint/config-conventional": "^19.8.0",
64
- "@commitlint/cz-commitlint": "^19.8.0",
65
- "@rollup/plugin-commonjs": "^28.0.3",
62
+ "@commitlint/cli": "^19.8.1",
63
+ "@commitlint/config-conventional": "^19.8.1",
64
+ "@commitlint/cz-commitlint": "^19.8.1",
65
+ "@eslint/js": "^9.31.0",
66
+ "@rollup/plugin-commonjs": "^28.0.6",
66
67
  "@rollup/plugin-node-resolve": "^16.0.1",
67
68
  "@rollup/plugin-replace": "^6.0.2",
68
69
  "@rollup/plugin-terser": "^0.4.4",
69
- "@rollup/plugin-typescript": "^12.1.2",
70
- "@types/jest": "^29.5.14",
71
- "@types/node": "^20.17.24",
72
- "@typescript-eslint/eslint-plugin": "^7.18.0",
73
- "@typescript-eslint/parser": "^7.18.0",
70
+ "@rollup/plugin-typescript": "^12.1.4",
71
+ "@types/jest": "^30.0.0",
72
+ "@types/node": "^20.19.9",
74
73
  "benchmark": "^2.1.4",
75
74
  "commitizen": "^4.3.1",
76
75
  "cross-env": "^7.0.3",
77
76
  "dayjs": "^1.11.13",
78
77
  "docdash": "^2.0.2",
79
- "eslint": "^8.57.1",
78
+ "eslint": "^9.31.0",
79
+ "globals": "^16.3.0",
80
80
  "husky": "^9.1.7",
81
- "jest": "^29.7.0",
82
- "jest-environment-jsdom": "^29.7.0",
81
+ "jest": "^30.0.5",
82
+ "jest-environment-jsdom": "^30.0.5",
83
83
  "jsdoc": "^4.0.4",
84
- "lint-staged": "^15.5.0",
84
+ "lint-staged": "^15.5.2",
85
85
  "lodash": "^4.17.21",
86
- "prettier": "^3.5.3",
87
- "rollup": "^4.35.0",
88
- "ts-jest": "^29.2.6",
89
- "typescript": "^5.8.2",
86
+ "prettier": "^3.6.2",
87
+ "rollup": "^4.45.1",
88
+ "ts-jest": "^29.4.0",
89
+ "typescript": "^5.8.3",
90
+ "typescript-eslint": "^8.38.0",
90
91
  "underscore": "^1.13.7"
91
92
  },
92
93
  "engines": {
package/types/clamp.d.ts CHANGED
@@ -5,12 +5,16 @@ interface Clamp {
5
5
  /**
6
6
  * 数字限制在 `lower` 和 `upper` 之间的值。
7
7
  *
8
+ * 特殊说明:
9
+ * - 如果只传入 1 个参数,直接返回该参数;
10
+ * - 如果只传入 2 个参数,`lower` 透传给 `upper`。
11
+ *
8
12
  * @function
9
13
  * @alias module:Number.clamp
10
14
  * @since 1.0.0
11
15
  * @param {number} number 被限制的值。
12
- * @param {number} [lower] 下限。默认 `0`。
13
- * @param {number} upper 上限。默认 `0`。
16
+ * @param {number} [lower] 下限。
17
+ * @param {number} upper 上限。
14
18
  * @returns {number} 限制后的值。
15
19
  * @example
16
20
  *
package/types/has.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { Many, TPath } from './internals/types';
2
+ /**
3
+ * 判断对象自身的属性是否包含路径属性。
4
+ *
5
+ * @alias module:Object.has
6
+ * @since 1.20.0
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty | hasOwnProperty}
8
+ * @param {*} object 要查询的对象。
9
+ * @param {string | number | symbol | Array} path 属性路径字符串或数组。
10
+ * @returns {boolean} 对象自身的属性是否包含路径属性。
11
+ * @example
12
+ * const obj = { a: [{ b: { c: 1 } }] };
13
+ *
14
+ * has(obj, 'a[0].b.c'); // true
15
+ *
16
+ * has(obj, 'a.0.b.c'); // true
17
+ *
18
+ * has(obj, ['a', '0', 'b', 'c']); // true
19
+ *
20
+ * has(obj, 'a.b.c'); // false
21
+ *
22
+ * has(obj, 'a.0.b.c.d'); // false
23
+ *
24
+ * // 不包含继承属性
25
+ * has(obj, 'toString'); // false
26
+ */
27
+ declare function has(object: any, key: Many<TPath>): boolean;
28
+ export default has;
@@ -0,0 +1,28 @@
1
+ import { Many, TPath } from './internals/types';
2
+ /**
3
+ * 判断对象自身及继承的属性是否包含路径属性。
4
+ *
5
+ * @alias module:Object.hasIn
6
+ * @since 1.20.0
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/in | in}
8
+ * @param {*} object 要查询的对象。
9
+ * @param {string | number | symbol | Array} path 属性路径字符串或数组。
10
+ * @returns {boolean} 对象自身及继承的属性是否包含路径属性。
11
+ * @example
12
+ * const obj = { a: [{ b: { c: 1 } }] };
13
+ *
14
+ * hasIn(obj, 'a[0].b.c'); // true
15
+ *
16
+ * hasIn(obj, 'a.0.b.c'); // true
17
+ *
18
+ * hasIn(obj, ['a', '0', 'b', 'c']); // true
19
+ *
20
+ * hasIn(obj, 'a.b.c'); // false
21
+ *
22
+ * hasIn(obj, 'a.0.b.c.d'); // false
23
+ *
24
+ * // 包含继承属性
25
+ * hasIn(obj, 'toString'); // true
26
+ */
27
+ declare function hasIn(object: any, key: Many<TPath>): boolean;
28
+ export default hasIn;
package/types/index.d.ts CHANGED
@@ -135,6 +135,8 @@ export { default as get } from './get';
135
135
  export { default as invert } from './invert';
136
136
  export { default as keys } from './keys';
137
137
  export { default as keysIn } from './keysIn';
138
+ export { default as has } from './has';
139
+ export { default as hasIn } from './hasIn';
138
140
  export { default as merge } from './merge';
139
141
  export { default as mergeObject } from './mergeObject';
140
142
  export { default as omit } from './omit';
@@ -0,0 +1,13 @@
1
+ import { Many, TPath } from './types';
2
+ type HasFunc = (object: object, key: TPath) => boolean;
3
+ /**
4
+ * 判断对象是否包含路径属性。
5
+ *
6
+ * @private
7
+ * @param {*} object 要查询的对象。
8
+ * @param {string | number | symbol | Array} path 属性路径字符串或数组。
9
+ * @param {Function} hasFunc 对象包含属性的函数。
10
+ * @returns {boolean} 对象是否包含路径属性。
11
+ */
12
+ declare function hasPath(object: object, key: Many<TPath>, hasFunc: HasFunc): boolean;
13
+ export default hasPath;
package/types/words.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @since 1.0.0
6
6
  * @see {@link https://zh.wikipedia.org/wiki/ASCII ASCII}
7
7
  * @param {string} string 要拆分的字符串。
8
- * @param {RegExp | string} [pattern=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g] 匹配模式。默认 `/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g`。
8
+ * @param {RegExp | string} [pattern=/[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+/g] 匹配模式。默认 `/[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+/g`。
9
9
  * @returns {string[]} 拆分后的数组。
10
10
  * @example
11
11
  *