source: trip-planner-front/node_modules/copy-anything/dist/index.cjs.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var isWhat = require('is-what');
6
7/*! *****************************************************************************
8Copyright (c) Microsoft Corporation.
9
10Permission to use, copy, modify, and/or distribute this software for any
11purpose with or without fee is hereby granted.
12
13THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19PERFORMANCE OF THIS SOFTWARE.
20***************************************************************************** */
21
22function __spreadArrays() {
23 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
24 for (var r = Array(s), k = 0, i = 0; i < il; i++)
25 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
26 r[k] = a[j];
27 return r;
28}
29
30function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
31 var propType = {}.propertyIsEnumerable.call(originalObject, key)
32 ? 'enumerable'
33 : 'nonenumerable';
34 if (propType === 'enumerable')
35 carry[key] = newVal;
36 if (includeNonenumerable && propType === 'nonenumerable') {
37 Object.defineProperty(carry, key, {
38 value: newVal,
39 enumerable: false,
40 writable: true,
41 configurable: true,
42 });
43 }
44}
45/**
46 * 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.
47 *
48 * @export
49 * @template T
50 * @param {T} target Target can be anything
51 * @param {Options} [options = {}] Options can be `props` or `nonenumerable`
52 * @returns {T} the target with replaced values
53 * @export
54 */
55function copy(target, options) {
56 if (options === void 0) { options = {}; }
57 if (isWhat.isArray(target))
58 return target.map(function (item) { return copy(item, options); });
59 if (!isWhat.isPlainObject(target))
60 return target;
61 var props = Object.getOwnPropertyNames(target);
62 var symbols = Object.getOwnPropertySymbols(target);
63 return __spreadArrays(props, symbols).reduce(function (carry, key) {
64 if (isWhat.isArray(options.props) && !options.props.includes(key)) {
65 return carry;
66 }
67 var val = target[key];
68 var newVal = copy(val, options);
69 assignProp(carry, key, newVal, target, options.nonenumerable);
70 return carry;
71 }, {});
72}
73
74exports.copy = copy;
Note: See TracBrowser for help on using the repository browser.