Updated the files.
This commit is contained in:
parent
1553e6b971
commit
753967d4f5
23418 changed files with 3784666 additions and 0 deletions
48
my-app/node_modules/copy-anything/dist/index.es.js
generated
vendored
Executable file
48
my-app/node_modules/copy-anything/dist/index.es.js
generated
vendored
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
import { isArray, isPlainObject } from 'is-what';
|
||||
|
||||
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
||||
const propType = {}.propertyIsEnumerable.call(originalObject, key)
|
||||
? 'enumerable'
|
||||
: 'nonenumerable';
|
||||
if (propType === 'enumerable')
|
||||
carry[key] = newVal;
|
||||
if (includeNonenumerable && propType === 'nonenumerable') {
|
||||
Object.defineProperty(carry, key, {
|
||||
value: newVal,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy (clone) an object and all its props recursively to get rid of any prop referenced of the original object. Arrays are also cloned, however objects inside arrays are still linked.
|
||||
*
|
||||
* @export
|
||||
* @template T
|
||||
* @param {T} target Target can be anything
|
||||
* @param {Options} [options = {}] Options can be `props` or `nonenumerable`
|
||||
* @returns {T} the target with replaced values
|
||||
* @export
|
||||
*/
|
||||
function copy(target, options = {}) {
|
||||
if (isArray(target)) {
|
||||
return target.map((item) => copy(item, options));
|
||||
}
|
||||
if (!isPlainObject(target)) {
|
||||
return target;
|
||||
}
|
||||
const props = Object.getOwnPropertyNames(target);
|
||||
const symbols = Object.getOwnPropertySymbols(target);
|
||||
return [...props, ...symbols].reduce((carry, key) => {
|
||||
if (isArray(options.props) && !options.props.includes(key)) {
|
||||
return carry;
|
||||
}
|
||||
const val = target[key];
|
||||
const newVal = copy(val, options);
|
||||
assignProp(carry, key, newVal, target, options.nonenumerable);
|
||||
return carry;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export { copy };
|
||||
Loading…
Add table
Add a link
Reference in a new issue