@sheinx/hooks 3.5.4-beta.15 → 3.5.4-beta.16
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/cjs/utils/object.d.ts +10 -0
- package/cjs/utils/object.d.ts.map +1 -1
- package/cjs/utils/object.js +24 -1
- package/esm/utils/object.d.ts +10 -0
- package/esm/utils/object.d.ts.map +1 -1
- package/esm/utils/object.js +24 -1
- package/package.json +1 -1
package/cjs/utils/object.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export declare const deepRemove: (target: ObjectType, path: string) => ObjectTyp
|
|
|
22
22
|
export declare const deepHas: (target: ObjectType, path: string) => boolean;
|
|
23
23
|
export declare const entries: (obj: ObjectType) => any[][];
|
|
24
24
|
export declare const removeProps: <T extends ObjectType, K extends ObjectType>(target: T, remove: K) => Omit<T, keyof K>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取数据对象的全量key路径
|
|
27
|
+
* @param obj 数据对象
|
|
28
|
+
* @param parentKey 父级key
|
|
29
|
+
* @returns 全量key路径
|
|
30
|
+
* @example
|
|
31
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
32
|
+
* const keys = getAllKeyPaths(obj);
|
|
33
|
+
* console.log(keys); // ['a.b.c', 'a.b', 'a']
|
|
34
|
+
*/
|
|
25
35
|
export declare const getAllKeyPaths: (obj: ObjectType, parentKey?: string) => string[];
|
|
26
36
|
export {};
|
|
27
37
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AASD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OA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,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD,eAAO,MAAM,YAAY,QAAS,UAAU,UAG3C,CAAC;AAGF,eAAO,MAAM,SAAS,2CAEZ,UAAU,YACT,WAAW,eAwBrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,+DA4BxC;AAED,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,OAAO,WACV,UAAU,QACZ,MAAM,SACL,GAAG,YACD,cAAc,eAiDxB,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAAW,WAAW,YAyB7E,CAAC;AAEF,eAAO,MAAM,UAAU,WAAY,UAAU,QAAQ,MAAM,eA0B1D,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAavD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,UAAU,YAItC,CAAC;AAEF,eAAO,MAAM,WAAW,wFAQvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QAAS,UAAU,cAAa,MAAM,KAAQ,MAAM,EAoB9E,CAAC"}
|
package/cjs/utils/object.js
CHANGED
|
@@ -9,6 +9,10 @@ exports.objectValues = void 0;
|
|
|
9
9
|
exports.pathGenerator = pathGenerator;
|
|
10
10
|
exports.removeProps = void 0;
|
|
11
11
|
var _is = require("./is");
|
|
12
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
15
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
16
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
17
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
18
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -270,12 +274,31 @@ var removeProps = exports.removeProps = function removeProps(target, remove) {
|
|
|
270
274
|
}
|
|
271
275
|
return a;
|
|
272
276
|
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 获取数据对象的全量key路径
|
|
280
|
+
* @param obj 数据对象
|
|
281
|
+
* @param parentKey 父级key
|
|
282
|
+
* @returns 全量key路径
|
|
283
|
+
* @example
|
|
284
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
285
|
+
* const keys = getAllKeyPaths(obj);
|
|
286
|
+
* console.log(keys); // ['a.b.c', 'a.b', 'a']
|
|
287
|
+
*/
|
|
273
288
|
var getAllKeyPaths = exports.getAllKeyPaths = function getAllKeyPaths(obj) {
|
|
274
289
|
var parentKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
275
290
|
return Object.keys(obj).reduce(function (keys, key) {
|
|
276
291
|
var newKey = parentKey ? "".concat(parentKey, ".").concat(key) : key;
|
|
277
292
|
if (Array.isArray(obj[key])) {
|
|
278
|
-
|
|
293
|
+
var childrenKeys = obj[key].map(function (item, index) {
|
|
294
|
+
if (item !== null && _typeof(item) === 'object') {
|
|
295
|
+
return getAllKeyPaths(item, "".concat(newKey, "[").concat(index, "]"));
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}).filter(function (item) {
|
|
299
|
+
return item !== null;
|
|
300
|
+
});
|
|
301
|
+
return keys.concat.apply(keys, _toConsumableArray(childrenKeys)).concat(newKey);
|
|
279
302
|
}
|
|
280
303
|
return keys.concat(obj[key] !== null && _typeof(obj[key]) === 'object' ? getAllKeyPaths(obj[key], newKey) : newKey);
|
|
281
304
|
}, []);
|
package/esm/utils/object.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export declare const deepRemove: (target: ObjectType, path: string) => ObjectTyp
|
|
|
22
22
|
export declare const deepHas: (target: ObjectType, path: string) => boolean;
|
|
23
23
|
export declare const entries: (obj: ObjectType) => any[][];
|
|
24
24
|
export declare const removeProps: <T extends ObjectType, K extends ObjectType>(target: T, remove: K) => Omit<T, keyof K>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取数据对象的全量key路径
|
|
27
|
+
* @param obj 数据对象
|
|
28
|
+
* @param parentKey 父级key
|
|
29
|
+
* @returns 全量key路径
|
|
30
|
+
* @example
|
|
31
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
32
|
+
* const keys = getAllKeyPaths(obj);
|
|
33
|
+
* console.log(keys); // ['a.b.c', 'a.b', 'a']
|
|
34
|
+
*/
|
|
25
35
|
export declare const getAllKeyPaths: (obj: ObjectType, parentKey?: string) => string[];
|
|
26
36
|
export {};
|
|
27
37
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AASD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAA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CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD,eAAO,MAAM,YAAY,QAAS,UAAU,UAG3C,CAAC;AAGF,eAAO,MAAM,SAAS,2CAEZ,UAAU,YACT,WAAW,eAwBrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,+DA4BxC;AAED,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,OAAO,WACV,UAAU,QACZ,MAAM,SACL,GAAG,YACD,cAAc,eAiDxB,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAAW,WAAW,YAyB7E,CAAC;AAEF,eAAO,MAAM,UAAU,WAAY,UAAU,QAAQ,MAAM,eA0B1D,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAavD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,UAAU,YAItC,CAAC;AAEF,eAAO,MAAM,WAAW,wFAQvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QAAS,UAAU,cAAa,MAAM,KAAQ,MAAM,EAoB9E,CAAC"}
|
package/esm/utils/object.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1
5
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
6
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
7
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -260,12 +264,31 @@ export var removeProps = function removeProps(target, remove) {
|
|
|
260
264
|
}
|
|
261
265
|
return a;
|
|
262
266
|
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 获取数据对象的全量key路径
|
|
270
|
+
* @param obj 数据对象
|
|
271
|
+
* @param parentKey 父级key
|
|
272
|
+
* @returns 全量key路径
|
|
273
|
+
* @example
|
|
274
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
275
|
+
* const keys = getAllKeyPaths(obj);
|
|
276
|
+
* console.log(keys); // ['a.b.c', 'a.b', 'a']
|
|
277
|
+
*/
|
|
263
278
|
export var getAllKeyPaths = function getAllKeyPaths(obj) {
|
|
264
279
|
var parentKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
265
280
|
return Object.keys(obj).reduce(function (keys, key) {
|
|
266
281
|
var newKey = parentKey ? "".concat(parentKey, ".").concat(key) : key;
|
|
267
282
|
if (Array.isArray(obj[key])) {
|
|
268
|
-
|
|
283
|
+
var childrenKeys = obj[key].map(function (item, index) {
|
|
284
|
+
if (item !== null && _typeof(item) === 'object') {
|
|
285
|
+
return getAllKeyPaths(item, "".concat(newKey, "[").concat(index, "]"));
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}).filter(function (item) {
|
|
289
|
+
return item !== null;
|
|
290
|
+
});
|
|
291
|
+
return keys.concat.apply(keys, _toConsumableArray(childrenKeys)).concat(newKey);
|
|
269
292
|
}
|
|
270
293
|
return keys.concat(obj[key] !== null && _typeof(obj[key]) === 'object' ? getAllKeyPaths(obj[key], newKey) : newKey);
|
|
271
294
|
}, []);
|