ut2 1.10.1 → 1.11.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/index.js CHANGED
@@ -49,6 +49,7 @@ export { default as isElement } from './isElement.js';
49
49
  export { default as isEmpty } from './isEmpty.js';
50
50
  export { default as isEqual } from './isEqual.js';
51
51
  export { default as isError } from './isError.js';
52
+ export { default as isFile } from './isFile.js';
52
53
  export { default as isFinite } from './isFinite.js';
53
54
  export { default as isFunction } from './isFunction.js';
54
55
  export { default as isInteger } from './isInteger.js';
@@ -2,7 +2,7 @@ import isObjectLike from '../isObjectLike.js';
2
2
  import getTag from './getTag.js';
3
3
  import { argumentsTag, stringUndefined, functionProtoToString } from './native.js';
4
4
 
5
- var VERSION = "1.10.1";
5
+ var VERSION = "1.11.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';
@@ -43,6 +43,7 @@ var arrayTag = '[object Array]';
43
43
  var functionTags = ['Function', 'AsyncFunction', 'GeneratorFunction', 'Proxy'].map(function (item) { return '[object ' + item + ']'; });
44
44
  var weakSetTag = '[object WeakSet]';
45
45
  var blobTag = '[object Blob]';
46
+ var fileTag = '[object File]';
46
47
  var domExceptionTag = '[object DOMException]';
47
48
  var objectTag = '[object Object]';
48
49
  var dataViewTag = '[object DataView]';
@@ -52,4 +53,4 @@ var setTag = '[object Set]';
52
53
  var weakMapTag = '[object WeakMap]';
53
54
  var windowTag = '[object Window]';
54
55
 
55
- export { MAX_ARRAY_LENGTH, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, argumentsTag, arrayBufferTag, arrayProto, arrayProtoSlice, arrayTag, bigIntTag, blobTag, booleanTag, dataViewTag, dateTag, domExceptionTag, errorTag, functionProto, functionProtoToString, functionTags, globalExisted, globalThisExisted, mapTag, mathAbs, mathCeil, mathFloor, mathMax, mathMin, mathRandom, nativeUndefined, numberIsFinite, numberIsInteger, numberIsSafeInteger, numberTag, objectGetOwnPropertySymbols, objectGetPrototypeOf, objectKeys, objectProto, objectProtoHasOwnProperty, objectProtoPropertyIsEnumerable, objectProtoToString, objectTag, promiseTag, regExpTag, selfExisted, setTag, stringObject, stringTag, stringUndefined, symbolProto, symbolTag, weakMapTag, weakSetTag, windowTag };
56
+ export { MAX_ARRAY_LENGTH, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, argumentsTag, arrayBufferTag, arrayProto, arrayProtoSlice, arrayTag, bigIntTag, blobTag, booleanTag, dataViewTag, dateTag, domExceptionTag, errorTag, fileTag, functionProto, functionProtoToString, functionTags, globalExisted, globalThisExisted, mapTag, mathAbs, mathCeil, mathFloor, mathMax, mathMin, mathRandom, nativeUndefined, numberIsFinite, numberIsInteger, numberIsSafeInteger, numberTag, objectGetOwnPropertySymbols, objectGetPrototypeOf, objectKeys, objectProto, objectProtoHasOwnProperty, objectProtoPropertyIsEnumerable, objectProtoToString, objectTag, promiseTag, regExpTag, selfExisted, setTag, stringObject, stringTag, stringUndefined, symbolProto, symbolTag, weakMapTag, weakSetTag, windowTag };
package/es/isFile.js ADDED
@@ -0,0 +1,12 @@
1
+ import getTag from './internals/getTag.js';
2
+ import { fileTag, stringUndefined } from './internals/native.js';
3
+
4
+ var fileExisted = typeof File !== stringUndefined;
5
+ function isFile(value) {
6
+ if (fileExisted && value instanceof File) {
7
+ return true;
8
+ }
9
+ return getTag(value) === fileTag;
10
+ }
11
+
12
+ export { isFile as default };
package/es/move.js CHANGED
@@ -1,6 +1,7 @@
1
- function move(arr, from, to) {
2
- arr.splice(to, 0, arr.splice(from, 1)[0]);
3
- return arr;
1
+ function move(array, from, to) {
2
+ var copyArray = array.slice();
3
+ copyArray.splice(to, 0, copyArray.splice(from, 1)[0]);
4
+ return copyArray;
4
5
  }
5
6
 
6
7
  export { move as default };
package/lib/index.js CHANGED
@@ -51,6 +51,7 @@ var isElement = require('./isElement.js');
51
51
  var isEmpty = require('./isEmpty.js');
52
52
  var isEqual = require('./isEqual.js');
53
53
  var isError = require('./isError.js');
54
+ var isFile = require('./isFile.js');
54
55
  var isFinite = require('./isFinite.js');
55
56
  var isFunction = require('./isFunction.js');
56
57
  var isInteger = require('./isInteger.js');
@@ -187,6 +188,7 @@ exports.isElement = isElement;
187
188
  exports.isEmpty = isEmpty;
188
189
  exports.isEqual = isEqual;
189
190
  exports.isError = isError;
191
+ exports.isFile = isFile;
190
192
  exports.isFinite = isFinite;
191
193
  exports.isFunction = isFunction;
192
194
  exports.isInteger = isInteger;
@@ -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.10.1";
7
+ var VERSION = "1.11.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';
@@ -45,6 +45,7 @@ var arrayTag = '[object Array]';
45
45
  var functionTags = ['Function', 'AsyncFunction', 'GeneratorFunction', 'Proxy'].map(function (item) { return '[object ' + item + ']'; });
46
46
  var weakSetTag = '[object WeakSet]';
47
47
  var blobTag = '[object Blob]';
48
+ var fileTag = '[object File]';
48
49
  var domExceptionTag = '[object DOMException]';
49
50
  var objectTag = '[object Object]';
50
51
  var dataViewTag = '[object DataView]';
@@ -69,6 +70,7 @@ exports.dataViewTag = dataViewTag;
69
70
  exports.dateTag = dateTag;
70
71
  exports.domExceptionTag = domExceptionTag;
71
72
  exports.errorTag = errorTag;
73
+ exports.fileTag = fileTag;
72
74
  exports.functionProto = functionProto;
73
75
  exports.functionProtoToString = functionProtoToString;
74
76
  exports.functionTags = functionTags;
package/lib/isFile.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var getTag = require('./internals/getTag.js');
4
+ var native = require('./internals/native.js');
5
+
6
+ var fileExisted = typeof File !== native.stringUndefined;
7
+ function isFile(value) {
8
+ if (fileExisted && value instanceof File) {
9
+ return true;
10
+ }
11
+ return getTag(value) === native.fileTag;
12
+ }
13
+
14
+ module.exports = isFile;
package/lib/move.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- function move(arr, from, to) {
4
- arr.splice(to, 0, arr.splice(from, 1)[0]);
5
- return arr;
3
+ function move(array, from, to) {
4
+ var copyArray = array.slice();
5
+ copyArray.splice(to, 0, copyArray.splice(from, 1)[0]);
6
+ return copyArray;
6
7
  }
7
8
 
8
9
  module.exports = move;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ut2",
3
- "version": "1.10.1",
3
+ "version": "1.11.1",
4
4
  "author": "caijf",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
package/types/index.d.ts CHANGED
@@ -73,6 +73,7 @@ export { default as isElement } from './isElement';
73
73
  export { default as isEmpty } from './isEmpty';
74
74
  export { default as isEqual } from './isEqual';
75
75
  export { default as isError } from './isError';
76
+ export { default as isFile } from './isFile';
76
77
  export { default as isFinite } from './isFinite';
77
78
  export { default as isFunction } from './isFunction';
78
79
  export { default as isInteger } from './isInteger';
@@ -66,6 +66,7 @@ export declare const arrayTag = "[object Array]";
66
66
  export declare const functionTags: string[];
67
67
  export declare const weakSetTag = "[object WeakSet]";
68
68
  export declare const blobTag = "[object Blob]";
69
+ export declare const fileTag = "[object File]";
69
70
  export declare const domExceptionTag = "[object DOMException]";
70
71
  export declare const objectTag = "[object Object]";
71
72
  export declare const dataViewTag = "[object DataView]";
package/types/isBlob.d.ts CHANGED
@@ -14,6 +14,8 @@
14
14
  *
15
15
  * isBlob(new Blob(['a'])); // true
16
16
  *
17
+ * isBlob(new File([], 'test.txt')); // true
18
+ *
17
19
  * isBlob({}); // false
18
20
  *
19
21
  * isBlob('2012'); // false
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 检查值是否为 `File` 对象。
3
+ *
4
+ * 浏览器环境的 `File` 对象,或其他继承自 `File` 的实例,都将返回 `true`。
5
+ *
6
+ * @static
7
+ * @alias module:Language.isFile
8
+ * @since 1.11.0
9
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/File File}
10
+ * @param {*} value 要检查的值。
11
+ * @returns {boolean} 如果值为 `File` 对象,返回 `true`,否则返回 `false`。
12
+ * @example
13
+ *
14
+ * isFile(new File([], 'test.txt')); // true
15
+ *
16
+ * isBlob(new Blob(['a'])); // false
17
+ *
18
+ * isFile({}); // false
19
+ *
20
+ * isFile('2012'); // false
21
+ *
22
+ */
23
+ declare function isFile(value: any): value is File;
24
+ export default isFile;
@@ -1,8 +1,3 @@
1
- import { FunctionAny } from './internals/types';
2
- type PromiseLikeObject = {
3
- then: FunctionAny;
4
- [x: string]: any;
5
- };
6
1
  /**
7
2
  * 检测值是否类似 `Promise` 对象。
8
3
  *
@@ -22,5 +17,5 @@ type PromiseLikeObject = {
22
17
  * isPromiseLike([]); // false
23
18
  *
24
19
  */
25
- declare function isPromiseLike(value: any): value is Promise<any> | PromiseLikeObject;
20
+ declare function isPromiseLike(value: any): value is Promise<any> | PromiseLike<any>;
26
21
  export default isPromiseLike;
package/types/merge.d.ts CHANGED
@@ -5,7 +5,9 @@ type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: a
5
5
  *
6
6
  * 如果目标值存在,被解析为 `undefined` 的 `source` 来源对象属性将被跳过。数组和普通对象会递归合并,其他对象和值会被直接分配覆盖。
7
7
  *
8
- * 如果你需要合并继承的属性,第四个参数传入 {@link https://caijf.github.io/ut2/module-Object.html#.allKeysIn allKeysIn} 方法, `merge(object, source, undefined, allKeysIn)`。
8
+ * 如果不需要合并数组,第三个参数传入 `merge.NOT_MERGE_ARRAYS`
9
+ *
10
+ * 如果需要合并继承的属性,第四个参数传入 {@link https://caijf.github.io/ut2/module-Object.html#.allKeysIn allKeysIn} 方法, `merge(object, source, undefined, allKeysIn)`。
9
11
  *
10
12
  * @static
11
13
  * @alias module:Object.merge
package/types/move.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 将数组 `from` 位置的元素移至 `to` 位置。
2
+ * 将数组 `from` 位置的元素移至 `to` 位置,返回处理后的新数组。
3
3
  *
4
4
  * @static
5
5
  * @alias module:Array.move
@@ -8,16 +8,15 @@
8
8
  * @param {Array} array 要处理的数组。
9
9
  * @param {number} from 要移动的元素索引。
10
10
  * @param {number} to 要移动目标位置的元素索引。
11
- * @returns {*} 处理后的原数组。
11
+ * @returns {*} 处理后的新数组。
12
12
  * @example
13
13
  *
14
14
  * const arr = ['a', 'b', 'c', 'd'];
15
15
  *
16
16
  * move(arr, 0, 1); // ['b', 'a', 'c', 'd']
17
17
  *
18
- * // 此时 arr 已经变为 ['b', 'a', 'c', 'd']
19
- * move(arr, -2, 0); // ['c', 'b', 'a', 'd']
18
+ * move(arr, -2, 0); // ['c', 'a', 'b', 'd']
20
19
  *
21
20
  */
22
- declare function move<T>(arr: T[], from: number, to: number): T[];
21
+ declare function move<T>(array: T[], from: number, to: number): T[];
23
22
  export default move;
package/types/nth.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  interface Nth {
2
2
  (array: [], n?: number): undefined;
3
- <T>(array: T[], n?: number): T;
3
+ <T>(array: ArrayLike<T>, n?: number): T;
4
4
  }
5
5
  /**
6
- * 获取数组的第 `n` 个元素。如果 `n` 为负数,则返回从数组结尾开始的第 `n` 个元素。
6
+ * 获取类数组的第 `n` 个元素。如果 `n` 为负数,则返回从数组结尾开始的第 `n` 个元素。
7
7
  *
8
8
  * 同 `Array.prototype.at` 方法。
9
9
  *
10
10
  * @static
11
11
  * @alias module:Array.nth
12
12
  * @since 1.0.0
13
- * @param {Array} array 要查询的数组。
13
+ * @param {ArrayLike} array 要查询的类数组。
14
14
  * @param {number} [n=0] 要返回元素的索引值。默认 `0`。
15
- * @returns {*} 数组的第 `n` 个元素。
15
+ * @returns {*} 类数组的第 `n` 个元素。
16
16
  * @example
17
17
  *
18
18
  * const arr = ['a', 'b', 'c', 'd'];
@@ -21,6 +21,8 @@ interface Nth {
21
21
  *
22
22
  * nth(arr, -2); // 'c'
23
23
  *
24
+ * nth('abcd', 1); // 'b'
25
+ *
24
26
  */
25
27
  declare const nth: Nth;
26
28
  export default nth;