ut2 1.15.0 → 1.16.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 +7 -0
- package/dist/ut2.js +131 -3
- package/dist/ut2.js.map +1 -1
- package/dist/ut2.min.js +1 -1
- package/dist/ut2.min.js.map +1 -1
- package/es/fromPathPairs.js +25 -0
- package/es/get.js +20 -0
- package/es/guard.js +2 -1
- package/es/index.js +6 -0
- package/es/internals/helpers.js +1 -1
- package/es/internals/isIndex.js +12 -0
- package/es/internals/stringToPath.js +15 -0
- package/es/merge.js +1 -1
- package/es/pathPairs.js +25 -0
- package/es/set.js +33 -0
- package/es/toPath.js +20 -0
- package/es/unset.js +15 -0
- package/lib/fromPathPairs.js +27 -0
- package/lib/get.js +22 -0
- package/lib/guard.js +2 -1
- package/lib/index.js +12 -0
- package/lib/internals/helpers.js +1 -1
- package/lib/internals/isIndex.js +14 -0
- package/lib/internals/stringToPath.js +17 -0
- package/lib/merge.js +1 -1
- package/lib/pathPairs.js +27 -0
- package/lib/set.js +35 -0
- package/lib/toPath.js +22 -0
- package/lib/unset.js +17 -0
- package/package.json +3 -5
- package/types/camelCase.d.ts +1 -1
- package/types/ceil.d.ts +1 -1
- package/types/compact.d.ts +1 -1
- package/types/eq.d.ts +1 -1
- package/types/escape.d.ts +1 -1
- package/types/escapeRegExp.d.ts +1 -1
- package/types/floor.d.ts +1 -1
- package/types/fromPathPairs.d.ts +42 -0
- package/types/get.d.ts +21 -0
- package/types/index.d.ts +6 -0
- package/types/internals/isIndex.d.ts +17 -0
- package/types/internals/native.d.ts +3 -3
- package/types/internals/root.d.ts +1 -1
- package/types/internals/stringToPath.d.ts +9 -0
- package/types/internals/types.d.ts +1 -0
- package/types/invert.d.ts +1 -1
- package/types/isBlob.d.ts +2 -2
- package/types/isFile.d.ts +1 -1
- package/types/isLength.d.ts +1 -1
- package/types/isObject.d.ts +1 -1
- package/types/isTypedArray.d.ts +1 -1
- package/types/kebabCase.d.ts +1 -1
- package/types/merge.d.ts +1 -1
- package/types/mergeObject.d.ts +1 -1
- package/types/move.d.ts +1 -1
- package/types/omitBy.d.ts +1 -1
- package/types/orderBy.d.ts +1 -1
- package/types/partition.d.ts +2 -2
- package/types/pascalCase.d.ts +1 -1
- package/types/pathPairs.d.ts +30 -0
- package/types/pickBy.d.ts +1 -1
- package/types/round.d.ts +1 -1
- package/types/set.d.ts +24 -0
- package/types/snakeCase.d.ts +1 -1
- package/types/toLength.d.ts +1 -1
- package/types/toPath.d.ts +17 -0
- package/types/unset.d.ts +20 -0
- package/types/words.d.ts +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { __read } from 'tslib';
|
|
2
|
+
import isIndex from './internals/isIndex.js';
|
|
3
|
+
import { nativeUndefined } from './internals/native.js';
|
|
4
|
+
import isArray from './isArray.js';
|
|
5
|
+
import isObject from './isObject.js';
|
|
6
|
+
import set from './set.js';
|
|
7
|
+
|
|
8
|
+
function fromPathPairs(value, customizer) {
|
|
9
|
+
var valueIsArray = isArray(value);
|
|
10
|
+
var firstPairPath = valueIsArray && isArray(value[0]) && isArray(value[0][0]) ? value[0][0] : [];
|
|
11
|
+
var firstNode = customizer ? customizer(nativeUndefined, firstPairPath[0], nativeUndefined) : nativeUndefined;
|
|
12
|
+
var result = isObject(firstNode) ? firstNode : isIndex(firstPairPath[0]) ? [] : {};
|
|
13
|
+
var length = valueIsArray ? value.length : 0;
|
|
14
|
+
var index = -1;
|
|
15
|
+
while (++index < length) {
|
|
16
|
+
var pathPair = value[index];
|
|
17
|
+
if (isArray(pathPair)) {
|
|
18
|
+
var _a = __read(pathPair, 2), paths = _a[0], val = _a[1];
|
|
19
|
+
set(result, paths, val, customizer);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { fromPathPairs as default };
|
package/es/get.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { nativeUndefined } from './internals/native.js';
|
|
2
|
+
import isNil from './isNil.js';
|
|
3
|
+
import isUndefined from './isUndefined.js';
|
|
4
|
+
import toPath from './toPath.js';
|
|
5
|
+
|
|
6
|
+
function baseGet(object, key) {
|
|
7
|
+
var paths = toPath(key, object);
|
|
8
|
+
var length = paths.length;
|
|
9
|
+
var index = 0;
|
|
10
|
+
while (!isNil(object) && index < length) {
|
|
11
|
+
object = object[paths[index++]];
|
|
12
|
+
}
|
|
13
|
+
return index && index === length ? object : nativeUndefined;
|
|
14
|
+
}
|
|
15
|
+
function get(object, key, defaultValue) {
|
|
16
|
+
var result = isNil(object) ? nativeUndefined : baseGet(object, key);
|
|
17
|
+
return isUndefined(result) ? defaultValue : result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { get as default };
|
package/es/guard.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nativeUndefined } from './internals/native.js';
|
|
1
2
|
import isPromiseLike from './isPromiseLike.js';
|
|
2
3
|
|
|
3
4
|
var guard = function (fn, shouldGuard) {
|
|
@@ -5,7 +6,7 @@ var guard = function (fn, shouldGuard) {
|
|
|
5
6
|
if (shouldGuard && !shouldGuard(err)) {
|
|
6
7
|
throw err;
|
|
7
8
|
}
|
|
8
|
-
return
|
|
9
|
+
return nativeUndefined;
|
|
9
10
|
};
|
|
10
11
|
try {
|
|
11
12
|
var result = fn();
|
package/es/index.js
CHANGED
|
@@ -86,6 +86,8 @@ export { default as randomInt } from './randomInt.js';
|
|
|
86
86
|
export { default as allKeys } from './allKeys.js';
|
|
87
87
|
export { default as allKeysIn } from './allKeysIn.js';
|
|
88
88
|
export { default as findKey } from './findKey.js';
|
|
89
|
+
export { default as fromPathPairs } from './fromPathPairs.js';
|
|
90
|
+
export { default as get } from './get.js';
|
|
89
91
|
export { default as invert } from './invert.js';
|
|
90
92
|
export { default as keys } from './keys.js';
|
|
91
93
|
export { default as keysIn } from './keysIn.js';
|
|
@@ -95,6 +97,9 @@ export { default as omit } from './omit.js';
|
|
|
95
97
|
export { default as omitBy } from './omitBy.js';
|
|
96
98
|
export { default as pick } from './pick.js';
|
|
97
99
|
export { default as pickBy } from './pickBy.js';
|
|
100
|
+
export { default as pathPairs } from './pathPairs.js';
|
|
101
|
+
export { default as set } from './set.js';
|
|
102
|
+
export { default as unset } from './unset.js';
|
|
98
103
|
export { default as camelCase } from './camelCase.js';
|
|
99
104
|
export { default as capitalize } from './capitalize.js';
|
|
100
105
|
export { default as escape } from './escape.js';
|
|
@@ -131,6 +136,7 @@ export { default as toFinite } from './toFinite.js';
|
|
|
131
136
|
export { default as toInteger } from './toInteger.js';
|
|
132
137
|
export { default as toLength } from './toLength.js';
|
|
133
138
|
export { default as toNumber } from './toNumber.js';
|
|
139
|
+
export { default as toPath } from './toPath.js';
|
|
134
140
|
export { default as toSafeInteger } from './toSafeInteger.js';
|
|
135
141
|
export { default as toString } from './toString.js';
|
|
136
142
|
export { default as tryit } from './tryit.js';
|
package/es/internals/helpers.js
CHANGED
|
@@ -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.
|
|
5
|
+
var VERSION = "1.16.0";
|
|
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';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import isLength from '../isLength.js';
|
|
2
|
+
import toNumber from '../toNumber.js';
|
|
3
|
+
|
|
4
|
+
function isIndex(value) {
|
|
5
|
+
var type = typeof value;
|
|
6
|
+
if (type === 'string' && value) {
|
|
7
|
+
value = toNumber(value);
|
|
8
|
+
}
|
|
9
|
+
return isLength(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { isIndex as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var reEscapeChar = /\\(\\)?/g;
|
|
2
|
+
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
3
|
+
function stringToPath(value) {
|
|
4
|
+
var result = [];
|
|
5
|
+
if (value.charCodeAt(0) === 46) {
|
|
6
|
+
result.push('');
|
|
7
|
+
}
|
|
8
|
+
value.replace(rePropName, function (match, number, quote, subString) {
|
|
9
|
+
result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
|
|
10
|
+
return match;
|
|
11
|
+
});
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { stringToPath as default };
|
package/es/merge.js
CHANGED
|
@@ -51,6 +51,6 @@ function merge(object, source, customizer, getKeys) {
|
|
|
51
51
|
if (getKeys === void 0) { getKeys = allKeys; }
|
|
52
52
|
return baseMerge(object, source, getKeys, customizer);
|
|
53
53
|
}
|
|
54
|
-
merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue :
|
|
54
|
+
merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue : nativeUndefined); };
|
|
55
55
|
|
|
56
56
|
export { merge as default };
|
package/es/pathPairs.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { __spreadArray, __read } from 'tslib';
|
|
2
|
+
import forEach from './forEach.js';
|
|
3
|
+
import isObjectLike from './isObjectLike.js';
|
|
4
|
+
|
|
5
|
+
function basePathPairs(object, parentPath) {
|
|
6
|
+
if (parentPath === void 0) { parentPath = []; }
|
|
7
|
+
var result = [];
|
|
8
|
+
if (isObjectLike(object)) {
|
|
9
|
+
forEach(object, function (v, k) {
|
|
10
|
+
var currentPath = parentPath.concat([k]);
|
|
11
|
+
if (isObjectLike(v)) {
|
|
12
|
+
result.push.apply(result, __spreadArray([], __read(basePathPairs(v, currentPath)), false));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
result.push([currentPath, v]);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function pathPairs(object) {
|
|
22
|
+
return basePathPairs(object);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { pathPairs as default };
|
package/es/set.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import isIndex from './internals/isIndex.js';
|
|
2
|
+
import { nativeUndefined } from './internals/native.js';
|
|
3
|
+
import isObject from './isObject.js';
|
|
4
|
+
import toPath from './toPath.js';
|
|
5
|
+
|
|
6
|
+
function set(object, path, value, customizer) {
|
|
7
|
+
if (!isObject(object)) {
|
|
8
|
+
return object;
|
|
9
|
+
}
|
|
10
|
+
var paths = toPath(path, object);
|
|
11
|
+
var length = paths.length;
|
|
12
|
+
var lastIndex = length - 1;
|
|
13
|
+
var index = -1;
|
|
14
|
+
var nested = object;
|
|
15
|
+
while (++index < length) {
|
|
16
|
+
var key = paths[index];
|
|
17
|
+
if (index === lastIndex) {
|
|
18
|
+
nested[key] = value;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
var objValue = nested[key];
|
|
22
|
+
var newValue = customizer ? customizer(objValue, key, nested) : nativeUndefined;
|
|
23
|
+
if (!isObject(newValue)) {
|
|
24
|
+
newValue = isObject(objValue) ? objValue : isIndex(paths[index + 1]) ? [] : {};
|
|
25
|
+
}
|
|
26
|
+
nested[key] = newValue;
|
|
27
|
+
nested = nested[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return object;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { set as default };
|
package/es/toPath.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import stringToPath from './internals/stringToPath.js';
|
|
2
|
+
import isArray from './isArray.js';
|
|
3
|
+
import isObject from './isObject.js';
|
|
4
|
+
import isSymbol from './isSymbol.js';
|
|
5
|
+
import toString from './toString.js';
|
|
6
|
+
|
|
7
|
+
function toKey(value) {
|
|
8
|
+
return isSymbol(value) ? value : toString(value);
|
|
9
|
+
}
|
|
10
|
+
function toPath(value, object) {
|
|
11
|
+
if (isArray(value)) {
|
|
12
|
+
return value.map(toKey);
|
|
13
|
+
}
|
|
14
|
+
if (isSymbol(value) || (typeof value === 'string' && isObject(object) && value in object)) {
|
|
15
|
+
return [value];
|
|
16
|
+
}
|
|
17
|
+
return stringToPath(toString(value));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { toPath as default };
|
package/es/unset.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import get from './get.js';
|
|
2
|
+
import isNil from './isNil.js';
|
|
3
|
+
import nth from './nth.js';
|
|
4
|
+
import toPath from './toPath.js';
|
|
5
|
+
|
|
6
|
+
function unset(object, path) {
|
|
7
|
+
if (isNil(object)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
var paths = toPath(path, object);
|
|
11
|
+
var parent = paths.length < 2 ? object : get(object, paths.slice(0, -1));
|
|
12
|
+
return isNil(parent) ? true : delete parent[nth(paths, -1)];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { unset as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var isIndex = require('./internals/isIndex.js');
|
|
5
|
+
var native = require('./internals/native.js');
|
|
6
|
+
var isArray = require('./isArray.js');
|
|
7
|
+
var isObject = require('./isObject.js');
|
|
8
|
+
var set = require('./set.js');
|
|
9
|
+
|
|
10
|
+
function fromPathPairs(value, customizer) {
|
|
11
|
+
var valueIsArray = isArray(value);
|
|
12
|
+
var firstPairPath = valueIsArray && isArray(value[0]) && isArray(value[0][0]) ? value[0][0] : [];
|
|
13
|
+
var firstNode = customizer ? customizer(native.nativeUndefined, firstPairPath[0], native.nativeUndefined) : native.nativeUndefined;
|
|
14
|
+
var result = isObject(firstNode) ? firstNode : isIndex(firstPairPath[0]) ? [] : {};
|
|
15
|
+
var length = valueIsArray ? value.length : 0;
|
|
16
|
+
var index = -1;
|
|
17
|
+
while (++index < length) {
|
|
18
|
+
var pathPair = value[index];
|
|
19
|
+
if (isArray(pathPair)) {
|
|
20
|
+
var _a = tslib.__read(pathPair, 2), paths = _a[0], val = _a[1];
|
|
21
|
+
set(result, paths, val, customizer);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = fromPathPairs;
|
package/lib/get.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var native = require('./internals/native.js');
|
|
4
|
+
var isNil = require('./isNil.js');
|
|
5
|
+
var isUndefined = require('./isUndefined.js');
|
|
6
|
+
var toPath = require('./toPath.js');
|
|
7
|
+
|
|
8
|
+
function baseGet(object, key) {
|
|
9
|
+
var paths = toPath(key, object);
|
|
10
|
+
var length = paths.length;
|
|
11
|
+
var index = 0;
|
|
12
|
+
while (!isNil(object) && index < length) {
|
|
13
|
+
object = object[paths[index++]];
|
|
14
|
+
}
|
|
15
|
+
return index && index === length ? object : native.nativeUndefined;
|
|
16
|
+
}
|
|
17
|
+
function get(object, key, defaultValue) {
|
|
18
|
+
var result = isNil(object) ? native.nativeUndefined : baseGet(object, key);
|
|
19
|
+
return isUndefined(result) ? defaultValue : result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = get;
|
package/lib/guard.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var native = require('./internals/native.js');
|
|
3
4
|
var isPromiseLike = require('./isPromiseLike.js');
|
|
4
5
|
|
|
5
6
|
var guard = function (fn, shouldGuard) {
|
|
@@ -7,7 +8,7 @@ var guard = function (fn, shouldGuard) {
|
|
|
7
8
|
if (shouldGuard && !shouldGuard(err)) {
|
|
8
9
|
throw err;
|
|
9
10
|
}
|
|
10
|
-
return
|
|
11
|
+
return native.nativeUndefined;
|
|
11
12
|
};
|
|
12
13
|
try {
|
|
13
14
|
var result = fn();
|
package/lib/index.js
CHANGED
|
@@ -88,6 +88,8 @@ var randomInt = require('./randomInt.js');
|
|
|
88
88
|
var allKeys = require('./allKeys.js');
|
|
89
89
|
var allKeysIn = require('./allKeysIn.js');
|
|
90
90
|
var findKey = require('./findKey.js');
|
|
91
|
+
var fromPathPairs = require('./fromPathPairs.js');
|
|
92
|
+
var get = require('./get.js');
|
|
91
93
|
var invert = require('./invert.js');
|
|
92
94
|
var keys = require('./keys.js');
|
|
93
95
|
var keysIn = require('./keysIn.js');
|
|
@@ -97,6 +99,9 @@ var omit = require('./omit.js');
|
|
|
97
99
|
var omitBy = require('./omitBy.js');
|
|
98
100
|
var pick = require('./pick.js');
|
|
99
101
|
var pickBy = require('./pickBy.js');
|
|
102
|
+
var pathPairs = require('./pathPairs.js');
|
|
103
|
+
var set = require('./set.js');
|
|
104
|
+
var unset = require('./unset.js');
|
|
100
105
|
var camelCase = require('./camelCase.js');
|
|
101
106
|
var capitalize = require('./capitalize.js');
|
|
102
107
|
var escape = require('./escape.js');
|
|
@@ -133,6 +138,7 @@ var toFinite = require('./toFinite.js');
|
|
|
133
138
|
var toInteger = require('./toInteger.js');
|
|
134
139
|
var toLength = require('./toLength.js');
|
|
135
140
|
var toNumber = require('./toNumber.js');
|
|
141
|
+
var toPath = require('./toPath.js');
|
|
136
142
|
var toSafeInteger = require('./toSafeInteger.js');
|
|
137
143
|
var toString = require('./toString.js');
|
|
138
144
|
var tryit = require('./tryit.js');
|
|
@@ -231,6 +237,8 @@ exports.randomInt = randomInt;
|
|
|
231
237
|
exports.allKeys = allKeys;
|
|
232
238
|
exports.allKeysIn = allKeysIn;
|
|
233
239
|
exports.findKey = findKey;
|
|
240
|
+
exports.fromPathPairs = fromPathPairs;
|
|
241
|
+
exports.get = get;
|
|
234
242
|
exports.invert = invert;
|
|
235
243
|
exports.keys = keys;
|
|
236
244
|
exports.keysIn = keysIn;
|
|
@@ -240,6 +248,9 @@ exports.omit = omit;
|
|
|
240
248
|
exports.omitBy = omitBy;
|
|
241
249
|
exports.pick = pick;
|
|
242
250
|
exports.pickBy = pickBy;
|
|
251
|
+
exports.pathPairs = pathPairs;
|
|
252
|
+
exports.set = set;
|
|
253
|
+
exports.unset = unset;
|
|
243
254
|
exports.camelCase = camelCase;
|
|
244
255
|
exports.capitalize = capitalize;
|
|
245
256
|
exports.escape = escape;
|
|
@@ -276,6 +287,7 @@ exports.toFinite = toFinite;
|
|
|
276
287
|
exports.toInteger = toInteger;
|
|
277
288
|
exports.toLength = toLength;
|
|
278
289
|
exports.toNumber = toNumber;
|
|
290
|
+
exports.toPath = toPath;
|
|
279
291
|
exports.toSafeInteger = toSafeInteger;
|
|
280
292
|
exports.toString = toString;
|
|
281
293
|
exports.tryit = tryit;
|
package/lib/internals/helpers.js
CHANGED
|
@@ -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.
|
|
7
|
+
var VERSION = "1.16.0";
|
|
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';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isLength = require('../isLength.js');
|
|
4
|
+
var toNumber = require('../toNumber.js');
|
|
5
|
+
|
|
6
|
+
function isIndex(value) {
|
|
7
|
+
var type = typeof value;
|
|
8
|
+
if (type === 'string' && value) {
|
|
9
|
+
value = toNumber(value);
|
|
10
|
+
}
|
|
11
|
+
return isLength(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = isIndex;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reEscapeChar = /\\(\\)?/g;
|
|
4
|
+
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
5
|
+
function stringToPath(value) {
|
|
6
|
+
var result = [];
|
|
7
|
+
if (value.charCodeAt(0) === 46) {
|
|
8
|
+
result.push('');
|
|
9
|
+
}
|
|
10
|
+
value.replace(rePropName, function (match, number, quote, subString) {
|
|
11
|
+
result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
|
|
12
|
+
return match;
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = stringToPath;
|
package/lib/merge.js
CHANGED
|
@@ -53,6 +53,6 @@ function merge(object, source, customizer, getKeys) {
|
|
|
53
53
|
if (getKeys === void 0) { getKeys = allKeys; }
|
|
54
54
|
return baseMerge(object, source, getKeys, customizer);
|
|
55
55
|
}
|
|
56
|
-
merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue :
|
|
56
|
+
merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue : native.nativeUndefined); };
|
|
57
57
|
|
|
58
58
|
module.exports = merge;
|
package/lib/pathPairs.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var forEach = require('./forEach.js');
|
|
5
|
+
var isObjectLike = require('./isObjectLike.js');
|
|
6
|
+
|
|
7
|
+
function basePathPairs(object, parentPath) {
|
|
8
|
+
if (parentPath === void 0) { parentPath = []; }
|
|
9
|
+
var result = [];
|
|
10
|
+
if (isObjectLike(object)) {
|
|
11
|
+
forEach(object, function (v, k) {
|
|
12
|
+
var currentPath = parentPath.concat([k]);
|
|
13
|
+
if (isObjectLike(v)) {
|
|
14
|
+
result.push.apply(result, tslib.__spreadArray([], tslib.__read(basePathPairs(v, currentPath)), false));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
result.push([currentPath, v]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function pathPairs(object) {
|
|
24
|
+
return basePathPairs(object);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = pathPairs;
|
package/lib/set.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isIndex = require('./internals/isIndex.js');
|
|
4
|
+
var native = require('./internals/native.js');
|
|
5
|
+
var isObject = require('./isObject.js');
|
|
6
|
+
var toPath = require('./toPath.js');
|
|
7
|
+
|
|
8
|
+
function set(object, path, value, customizer) {
|
|
9
|
+
if (!isObject(object)) {
|
|
10
|
+
return object;
|
|
11
|
+
}
|
|
12
|
+
var paths = toPath(path, object);
|
|
13
|
+
var length = paths.length;
|
|
14
|
+
var lastIndex = length - 1;
|
|
15
|
+
var index = -1;
|
|
16
|
+
var nested = object;
|
|
17
|
+
while (++index < length) {
|
|
18
|
+
var key = paths[index];
|
|
19
|
+
if (index === lastIndex) {
|
|
20
|
+
nested[key] = value;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
var objValue = nested[key];
|
|
24
|
+
var newValue = customizer ? customizer(objValue, key, nested) : native.nativeUndefined;
|
|
25
|
+
if (!isObject(newValue)) {
|
|
26
|
+
newValue = isObject(objValue) ? objValue : isIndex(paths[index + 1]) ? [] : {};
|
|
27
|
+
}
|
|
28
|
+
nested[key] = newValue;
|
|
29
|
+
nested = nested[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return object;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = set;
|
package/lib/toPath.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stringToPath = require('./internals/stringToPath.js');
|
|
4
|
+
var isArray = require('./isArray.js');
|
|
5
|
+
var isObject = require('./isObject.js');
|
|
6
|
+
var isSymbol = require('./isSymbol.js');
|
|
7
|
+
var toString = require('./toString.js');
|
|
8
|
+
|
|
9
|
+
function toKey(value) {
|
|
10
|
+
return isSymbol(value) ? value : toString(value);
|
|
11
|
+
}
|
|
12
|
+
function toPath(value, object) {
|
|
13
|
+
if (isArray(value)) {
|
|
14
|
+
return value.map(toKey);
|
|
15
|
+
}
|
|
16
|
+
if (isSymbol(value) || (typeof value === 'string' && isObject(object) && value in object)) {
|
|
17
|
+
return [value];
|
|
18
|
+
}
|
|
19
|
+
return stringToPath(toString(value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = toPath;
|
package/lib/unset.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var get = require('./get.js');
|
|
4
|
+
var isNil = require('./isNil.js');
|
|
5
|
+
var nth = require('./nth.js');
|
|
6
|
+
var toPath = require('./toPath.js');
|
|
7
|
+
|
|
8
|
+
function unset(object, path) {
|
|
9
|
+
if (isNil(object)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
var paths = toPath(path, object);
|
|
13
|
+
var parent = paths.length < 2 ? object : get(object, paths.slice(0, -1));
|
|
14
|
+
return isNil(parent) ? true : delete parent[nth(paths, -1)];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = unset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ut2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"author": "caijf",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -13,16 +13,14 @@
|
|
|
13
13
|
"test:coverage": "jest --coverage",
|
|
14
14
|
"test:coverage:local": "cross-env COVERAGE_LOCAL=1 jest --coverage --detectOpenHandles && open ./coverage/lcov-report/index.html",
|
|
15
15
|
"benchmark": "node benchmark/node.js",
|
|
16
|
-
"build": "
|
|
17
|
-
"build:module": "rm -rf es && rm -rf lib && rollup -c rollup.module.config.mjs",
|
|
18
|
-
"build:umd": "rm -rf dist && rollup -c rollup.umd.config.mjs",
|
|
16
|
+
"build": "rm -rf es lib dist && rollup -c && npm run build:types",
|
|
19
17
|
"build:types": "rm -rf types && tsc -p tsconfig.build.json -d --outDir types --emitDeclarationOnly",
|
|
20
18
|
"build:doc": "npm run doc",
|
|
21
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",
|
|
22
20
|
"doc:open": "open ./docs/index.html",
|
|
23
21
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
24
22
|
"lint:fix": "npm run lint:js -- --fix",
|
|
25
|
-
"prettier": "prettier
|
|
23
|
+
"prettier": "prettier -w **/*",
|
|
26
24
|
"commit": "cz",
|
|
27
25
|
"prepublishOnly": "npm test && npm run build",
|
|
28
26
|
"tsc": "tsc --noEmit",
|
package/types/camelCase.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @alias module:String.camelCase
|
|
5
5
|
* @since 1.0.0
|
|
6
|
-
* @see {@link https://en.wikipedia.org/wiki/Camel_case
|
|
6
|
+
* @see {@link https://en.wikipedia.org/wiki/Camel_case Camel_case}
|
|
7
7
|
* @param {string} string 要转换的字符串。
|
|
8
8
|
* @param {RegExp | string} [pattern] 拆分词组的匹配模式。
|
|
9
9
|
* @returns {string} 驼峰写法的字符串。
|
package/types/ceil.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @alias module:Math.ceil
|
|
7
7
|
* @since 1.0.0
|
|
8
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/round#小数舍入
|
|
8
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/round#小数舍入 小数舍入}
|
|
9
9
|
* @param {number} number 要向上舍入的值。
|
|
10
10
|
* @param {number} [precision=0] 向上舍入的精度。默认 `0`。
|
|
11
11
|
* @returns {number} 向上舍入的值。
|
package/types/compact.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @alias module:Array.compact
|
|
7
7
|
* @since 1.0.0
|
|
8
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy
|
|
8
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy Falsy}
|
|
9
9
|
* @param {Array} array 待处理的数组。
|
|
10
10
|
* @returns {Array} 过滤掉假值的新数组。
|
|
11
11
|
* @example
|
package/types/eq.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @alias module:Util.eq
|
|
7
7
|
* @since 1.0.0
|
|
8
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Equality_comparisons_and_sameness
|
|
8
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Equality_comparisons_and_sameness JavaScript 中的相等性判断}
|
|
9
9
|
* @param {*} value 要比较的值。
|
|
10
10
|
* @param {*} other 另一个要比较的值。
|
|
11
11
|
* @param {boolean} [strictCheck=false] 严格比较,区分 `0` `-0`。默认 `false`。
|
package/types/escape.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @alias module:String.escape
|
|
11
11
|
* @since 1.0.0
|
|
12
|
-
* @see {@link https://mathiasbynens.be/notes/ambiguous-ampersands
|
|
12
|
+
* @see {@link https://mathiasbynens.be/notes/ambiguous-ampersands ambiguous-ampersands}
|
|
13
13
|
* @param {string} string 要转义的字符串。
|
|
14
14
|
* @returns {string} 转义后的字符串。
|
|
15
15
|
* @example
|
package/types/escapeRegExp.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @alias module:String.escapeRegExp
|
|
5
5
|
* @since 1.0.0
|
|
6
|
-
* @see {@link https://tc39.es/ecma262/multipage/text-processing.html#sec-patterns
|
|
6
|
+
* @see {@link https://tc39.es/ecma262/multipage/text-processing.html#sec-patterns syntax characters}
|
|
7
7
|
* @param {string} string 要转义的字符串。
|
|
8
8
|
* @returns {string} 转义后的字符串。
|
|
9
9
|
* @example
|
package/types/floor.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @alias module:Math.floor
|
|
7
7
|
* @since 1.0.0
|
|
8
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/round#小数舍入
|
|
8
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/round#小数舍入 小数舍入}
|
|
9
9
|
* @param {number} number 要向下舍入的值。
|
|
10
10
|
* @param {number} [precision=0] 向下舍入的精度。默认 `0`。
|
|
11
11
|
* @returns {number} 向下舍入的值。
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import set from './set';
|
|
2
|
+
/**
|
|
3
|
+
* 将属性路径/值对的数组转为对象。与 [`pathPairs`](#.pathPairs) 相反。
|
|
4
|
+
*
|
|
5
|
+
* 如果属性路径为有效索引数字(数字或字符串)且没有值时,将创建数组,否则创建对象。例如:
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* fromPathPairs([[[0], 42], [["foo"], "baz"]]);
|
|
9
|
+
* // [42, foo: 'baz']
|
|
10
|
+
*
|
|
11
|
+
* // 调整顺序后
|
|
12
|
+
* fromPathPairs([[["foo"], "baz"], [[0], 42]]);
|
|
13
|
+
* // { foo: 'baz', '0': 42 }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @alias module:Object.fromPathPairs
|
|
17
|
+
* @since 1.16.0
|
|
18
|
+
* @param {Array} value 属性路径/值对的数组。
|
|
19
|
+
* @returns {Object | Array} 转换后的对象或数组。
|
|
20
|
+
* @param {Function} [customizer] 自定义指定值。
|
|
21
|
+
* @example
|
|
22
|
+
* fromPathPairs([
|
|
23
|
+
* [['date', 'start'], '2024-10-10'],
|
|
24
|
+
* [['date', 'end'], '2024-12-31']
|
|
25
|
+
* ]);
|
|
26
|
+
* // { date: { start: '2024-10-10', end: '2024-12-31' } }
|
|
27
|
+
*
|
|
28
|
+
* fromPathPairs([
|
|
29
|
+
* [['date', 0], '2024-10-10'],
|
|
30
|
+
* [['date', 1], '2024-12-31']
|
|
31
|
+
* ]);
|
|
32
|
+
* // { date: ['2024-10-10', '2024-12-31'] }
|
|
33
|
+
*
|
|
34
|
+
* fromPathPairs([
|
|
35
|
+
* [[0, 'date'], '2024-10-10'],
|
|
36
|
+
* [[1, 'date'], '2024-12-31']
|
|
37
|
+
* ]);
|
|
38
|
+
* // [{ date: '2024-10-10' }, { date: '2024-12-31' }]
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
declare function fromPathPairs(value: any[], customizer?: Parameters<typeof set>[3]): any;
|
|
42
|
+
export default fromPathPairs;
|