ut2 1.9.5 → 1.10.0
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/README.md +9 -0
- package/dist/ut2.js +16 -1
- package/dist/ut2.js.map +1 -1
- package/dist/ut2.min.js +1 -1
- package/dist/ut2.min.js.map +1 -1
- package/es/index.js +4 -1
- package/es/internals/helpers.js +5 -3
- package/es/internals/native.js +2 -1
- package/es/isWindow.js +9 -0
- package/es/move.js +6 -0
- package/lib/index.js +7 -0
- package/lib/internals/helpers.js +4 -1
- package/lib/internals/native.js +2 -0
- package/lib/isWindow.js +11 -0
- package/lib/move.js +8 -0
- package/package.json +1 -1
- package/types/index.d.ts +4 -1
- package/types/internals/helpers.d.ts +7 -0
- package/types/internals/native.d.ts +1 -0
- package/types/internals/root.d.ts +12 -0
- package/types/isWindow.d.ts +21 -0
- package/types/move.d.ts +23 -0
package/es/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as compact } from './compact.js';
|
|
|
3
3
|
export { default as difference } from './difference.js';
|
|
4
4
|
export { default as fromPairs } from './fromPairs.js';
|
|
5
5
|
export { default as intersection } from './intersection.js';
|
|
6
|
+
export { default as move } from './move.js';
|
|
6
7
|
export { default as nth } from './nth.js';
|
|
7
8
|
export { default as shuffle } from './shuffle.js';
|
|
8
9
|
export { default as union } from './union.js';
|
|
@@ -71,6 +72,7 @@ export { default as isTypedArray } from './isTypedArray.js';
|
|
|
71
72
|
export { default as isUndefined } from './isUndefined.js';
|
|
72
73
|
export { default as isWeakMap } from './isWeakMap.js';
|
|
73
74
|
export { default as isWeakSet } from './isWeakSet.js';
|
|
75
|
+
export { default as isWindow } from './isWindow.js';
|
|
74
76
|
export { default as ceil } from './ceil.js';
|
|
75
77
|
export { default as floor } from './floor.js';
|
|
76
78
|
export { default as max } from './max.js';
|
|
@@ -127,4 +129,5 @@ export { default as toSafeInteger } from './toSafeInteger.js';
|
|
|
127
129
|
export { default as toString } from './toString.js';
|
|
128
130
|
export { default as uniqueId } from './uniqueId.js';
|
|
129
131
|
export { MAX_ARRAY_LENGTH, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from './internals/native.js';
|
|
130
|
-
export { VERSION } from './internals/helpers.js';
|
|
132
|
+
export { VERSION, isBrowser } from './internals/helpers.js';
|
|
133
|
+
export { default as root } from './internals/root.js';
|
package/es/internals/helpers.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import isObjectLike from '../isObjectLike.js';
|
|
1
2
|
import getTag from './getTag.js';
|
|
2
|
-
import { argumentsTag, functionProtoToString } from './native.js';
|
|
3
|
+
import { argumentsTag, stringUndefined, functionProtoToString } from './native.js';
|
|
3
4
|
|
|
4
|
-
var VERSION = "1.
|
|
5
|
+
var VERSION = "1.10.0";
|
|
6
|
+
var isBrowser = typeof window !== stringUndefined && isObjectLike(window) && typeof document !== stringUndefined && isObjectLike(document) && window.document === document;
|
|
5
7
|
var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
|
|
6
8
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
7
9
|
function toSource(func) {
|
|
@@ -22,4 +24,4 @@ function toSource(func) {
|
|
|
22
24
|
var stubFlase = function () { return false; };
|
|
23
25
|
var stubTrue = function () { return true; };
|
|
24
26
|
|
|
25
|
-
export { FUNC_ERROR_TEXT, VERSION, stubFlase, stubTrue, supportedArgumentsType, toSource };
|
|
27
|
+
export { FUNC_ERROR_TEXT, VERSION, isBrowser, stubFlase, stubTrue, supportedArgumentsType, toSource };
|
package/es/internals/native.js
CHANGED
|
@@ -50,5 +50,6 @@ var mapTag = '[object Map]';
|
|
|
50
50
|
var promiseTag = '[object Promise]';
|
|
51
51
|
var setTag = '[object Set]';
|
|
52
52
|
var weakMapTag = '[object WeakMap]';
|
|
53
|
+
var windowTag = '[object Window]';
|
|
53
54
|
|
|
54
|
-
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 };
|
|
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 };
|
package/es/isWindow.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getTag from './internals/getTag.js';
|
|
2
|
+
import { windowTag } from './internals/native.js';
|
|
3
|
+
import isObjectLike from './isObjectLike.js';
|
|
4
|
+
|
|
5
|
+
function isWindow(value) {
|
|
6
|
+
return isObjectLike(value) && getTag(value) === windowTag;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { isWindow as default };
|
package/es/move.js
ADDED
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var compact = require('./compact.js');
|
|
|
5
5
|
var difference = require('./difference.js');
|
|
6
6
|
var fromPairs = require('./fromPairs.js');
|
|
7
7
|
var intersection = require('./intersection.js');
|
|
8
|
+
var move = require('./move.js');
|
|
8
9
|
var nth = require('./nth.js');
|
|
9
10
|
var shuffle = require('./shuffle.js');
|
|
10
11
|
var union = require('./union.js');
|
|
@@ -73,6 +74,7 @@ var isTypedArray = require('./isTypedArray.js');
|
|
|
73
74
|
var isUndefined = require('./isUndefined.js');
|
|
74
75
|
var isWeakMap = require('./isWeakMap.js');
|
|
75
76
|
var isWeakSet = require('./isWeakSet.js');
|
|
77
|
+
var isWindow = require('./isWindow.js');
|
|
76
78
|
var ceil = require('./ceil.js');
|
|
77
79
|
var floor = require('./floor.js');
|
|
78
80
|
var max = require('./max.js');
|
|
@@ -130,6 +132,7 @@ var toString = require('./toString.js');
|
|
|
130
132
|
var uniqueId = require('./uniqueId.js');
|
|
131
133
|
var native = require('./internals/native.js');
|
|
132
134
|
var helpers = require('./internals/helpers.js');
|
|
135
|
+
var root = require('./internals/root.js');
|
|
133
136
|
|
|
134
137
|
|
|
135
138
|
|
|
@@ -138,6 +141,7 @@ exports.compact = compact;
|
|
|
138
141
|
exports.difference = difference;
|
|
139
142
|
exports.fromPairs = fromPairs;
|
|
140
143
|
exports.intersection = intersection;
|
|
144
|
+
exports.move = move;
|
|
141
145
|
exports.nth = nth;
|
|
142
146
|
exports.shuffle = shuffle;
|
|
143
147
|
exports.union = union;
|
|
@@ -206,6 +210,7 @@ exports.isTypedArray = isTypedArray;
|
|
|
206
210
|
exports.isUndefined = isUndefined;
|
|
207
211
|
exports.isWeakMap = isWeakMap;
|
|
208
212
|
exports.isWeakSet = isWeakSet;
|
|
213
|
+
exports.isWindow = isWindow;
|
|
209
214
|
exports.ceil = ceil;
|
|
210
215
|
exports.floor = floor;
|
|
211
216
|
exports.max = max;
|
|
@@ -265,3 +270,5 @@ exports.MAX_ARRAY_LENGTH = native.MAX_ARRAY_LENGTH;
|
|
|
265
270
|
exports.MAX_SAFE_INTEGER = native.MAX_SAFE_INTEGER;
|
|
266
271
|
exports.MIN_SAFE_INTEGER = native.MIN_SAFE_INTEGER;
|
|
267
272
|
exports.VERSION = helpers.VERSION;
|
|
273
|
+
exports.isBrowser = helpers.isBrowser;
|
|
274
|
+
exports.root = root;
|
package/lib/internals/helpers.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var isObjectLike = require('../isObjectLike.js');
|
|
3
4
|
var getTag = require('./getTag.js');
|
|
4
5
|
var native = require('./native.js');
|
|
5
6
|
|
|
6
|
-
var VERSION = "1.
|
|
7
|
+
var VERSION = "1.10.0";
|
|
8
|
+
var isBrowser = typeof window !== native.stringUndefined && isObjectLike(window) && typeof document !== native.stringUndefined && isObjectLike(document) && window.document === document;
|
|
7
9
|
var supportedArgumentsType = getTag((function () { return arguments; })()) === native.argumentsTag;
|
|
8
10
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
9
11
|
function toSource(func) {
|
|
@@ -26,6 +28,7 @@ var stubTrue = function () { return true; };
|
|
|
26
28
|
|
|
27
29
|
exports.FUNC_ERROR_TEXT = FUNC_ERROR_TEXT;
|
|
28
30
|
exports.VERSION = VERSION;
|
|
31
|
+
exports.isBrowser = isBrowser;
|
|
29
32
|
exports.stubFlase = stubFlase;
|
|
30
33
|
exports.stubTrue = stubTrue;
|
|
31
34
|
exports.supportedArgumentsType = supportedArgumentsType;
|
package/lib/internals/native.js
CHANGED
|
@@ -52,6 +52,7 @@ var mapTag = '[object Map]';
|
|
|
52
52
|
var promiseTag = '[object Promise]';
|
|
53
53
|
var setTag = '[object Set]';
|
|
54
54
|
var weakMapTag = '[object WeakMap]';
|
|
55
|
+
var windowTag = '[object Window]';
|
|
55
56
|
|
|
56
57
|
exports.MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH;
|
|
57
58
|
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
|
@@ -104,3 +105,4 @@ exports.symbolProto = symbolProto;
|
|
|
104
105
|
exports.symbolTag = symbolTag;
|
|
105
106
|
exports.weakMapTag = weakMapTag;
|
|
106
107
|
exports.weakSetTag = weakSetTag;
|
|
108
|
+
exports.windowTag = windowTag;
|
package/lib/isWindow.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getTag = require('./internals/getTag.js');
|
|
4
|
+
var native = require('./internals/native.js');
|
|
5
|
+
var isObjectLike = require('./isObjectLike.js');
|
|
6
|
+
|
|
7
|
+
function isWindow(value) {
|
|
8
|
+
return isObjectLike(value) && getTag(value) === native.windowTag;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = isWindow;
|
package/lib/move.js
ADDED
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { default as compact } from './compact';
|
|
|
9
9
|
export { default as difference } from './difference';
|
|
10
10
|
export { default as fromPairs } from './fromPairs';
|
|
11
11
|
export { default as intersection } from './intersection';
|
|
12
|
+
export { default as move } from './move';
|
|
12
13
|
export { default as nth } from './nth';
|
|
13
14
|
export { default as shuffle } from './shuffle';
|
|
14
15
|
export { default as union } from './union';
|
|
@@ -95,6 +96,7 @@ export { default as isTypedArray } from './isTypedArray';
|
|
|
95
96
|
export { default as isUndefined } from './isUndefined';
|
|
96
97
|
export { default as isWeakMap } from './isWeakMap';
|
|
97
98
|
export { default as isWeakSet } from './isWeakSet';
|
|
99
|
+
export { default as isWindow } from './isWindow';
|
|
98
100
|
/**
|
|
99
101
|
* 数学
|
|
100
102
|
*
|
|
@@ -181,4 +183,5 @@ export { default as toSafeInteger } from './toSafeInteger';
|
|
|
181
183
|
export { default as toString } from './toString';
|
|
182
184
|
export { default as uniqueId } from './uniqueId';
|
|
183
185
|
export { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, MAX_ARRAY_LENGTH } from './internals/native';
|
|
184
|
-
export { VERSION } from './internals/helpers';
|
|
186
|
+
export { VERSION, isBrowser } from './internals/helpers';
|
|
187
|
+
export { default as root } from './internals/root';
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* @since 1.0.0
|
|
6
6
|
*/
|
|
7
7
|
export declare const VERSION: string;
|
|
8
|
+
/**
|
|
9
|
+
* 当前运行环境是否为浏览器
|
|
10
|
+
*
|
|
11
|
+
* @static
|
|
12
|
+
* @since 1.10.0
|
|
13
|
+
*/
|
|
14
|
+
export declare const isBrowser: boolean;
|
|
8
15
|
export declare const supportedArgumentsType: boolean;
|
|
9
16
|
export declare const FUNC_ERROR_TEXT = "Expected a function";
|
|
10
17
|
export declare function toSource(func: any): string;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 全局对象。
|
|
3
|
+
*
|
|
4
|
+
* 不同的 JavaScript 环境都可以获取到对应的全局对象:
|
|
5
|
+
* 1. Web 中等同于 `globalThis` / `window` / `self` / `frames` (兼容旧浏览器)
|
|
6
|
+
* 2. Node.js 中等同于 `globalThis` / `global` (兼容低版本 Node.js)
|
|
7
|
+
* 3. Web Workers 中等同于 `self`
|
|
8
|
+
*
|
|
9
|
+
* @static
|
|
10
|
+
* @since 1.10.0
|
|
11
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/globalThis globalThis}
|
|
12
|
+
*/
|
|
1
13
|
declare const root: typeof globalThis;
|
|
2
14
|
export default root;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查值是否为 `Window` 对象。
|
|
3
|
+
*
|
|
4
|
+
* @static
|
|
5
|
+
* @alias module:Language.isWindow
|
|
6
|
+
* @since 1.10.0
|
|
7
|
+
* @param {*} value 要检查的值。
|
|
8
|
+
* @returns {boolean} 如果值为 `Window` 对象,返回 `true`,否则返回 `false`。
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* isWindow({}); // false
|
|
12
|
+
*
|
|
13
|
+
* // 浏览器环境
|
|
14
|
+
* isWindow(globalThis); // true
|
|
15
|
+
* isWindow(window); // true
|
|
16
|
+
* isWindow(self); // true
|
|
17
|
+
* isWindow(frames); // true
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
declare function isWindow(value: any): value is Window & typeof globalThis;
|
|
21
|
+
export default isWindow;
|
package/types/move.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将数组 `from` 位置的元素移至 `to` 位置。
|
|
3
|
+
*
|
|
4
|
+
* @static
|
|
5
|
+
* @alias module:Array.move
|
|
6
|
+
* @since 1.10.0
|
|
7
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice splice}
|
|
8
|
+
* @param {Array} array 要处理的数组。
|
|
9
|
+
* @param {number} from 要移动的元素索引。
|
|
10
|
+
* @param {number} to 要移动目标位置的元素索引。
|
|
11
|
+
* @returns {*} 处理后的原数组。
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* const arr = ['a', 'b', 'c', 'd'];
|
|
15
|
+
*
|
|
16
|
+
* move(arr, 0, 1); // ['b', 'a', 'c', 'd']
|
|
17
|
+
*
|
|
18
|
+
* // 此时 arr 已经变为 ['b', 'a', 'c', 'd']
|
|
19
|
+
* move(arr, -2, 0); // ['c', 'b', 'a', 'd']
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare function move<T>(arr: T[], from: number, to: number): T[];
|
|
23
|
+
export default move;
|