(x: JsInputValue)
| 44 | |
| 45 | // based on https://github.com/lukeed/klona/blob/v2.0.6/src/index.js |
| 46 | function deepCloneValue(x: JsInputValue): JsInputValue { |
| 47 | if (typeof x !== 'object' || x == null || isObjectEnumValue(x) || isFieldRef(x) || isSkip(x)) { |
| 48 | return x |
| 49 | } |
| 50 | |
| 51 | if (isDecimalJsLike(x)) { |
| 52 | return new Decimal(x.toFixed()) |
| 53 | } |
| 54 | |
| 55 | if (isDate(x)) { |
| 56 | return new Date(+x) |
| 57 | } |
| 58 | |
| 59 | if (ArrayBuffer.isView(x)) { |
| 60 | return x.slice(0) |
| 61 | } |
| 62 | |
| 63 | if (Array.isArray(x)) { |
| 64 | let k = x.length |
| 65 | let copy |
| 66 | for (copy = Array(k); k--; ) { |
| 67 | copy[k] = deepCloneValue(x[k]) |
| 68 | } |
| 69 | return copy |
| 70 | } |
| 71 | |
| 72 | if (typeof x === 'object') { |
| 73 | const copy = {} |
| 74 | for (const k in x) { |
| 75 | if (k === '__proto__') { |
| 76 | Object.defineProperty(copy, k, { |
| 77 | value: deepCloneValue(x[k]), |
| 78 | configurable: true, |
| 79 | enumerable: true, |
| 80 | writable: true, |
| 81 | }) |
| 82 | } else { |
| 83 | copy[k] = deepCloneValue(x[k]) |
| 84 | } |
| 85 | } |
| 86 | return copy |
| 87 | } |
| 88 | |
| 89 | assertNever(x, 'Unknown value') |
| 90 | } |
no test coverage detected