( object: any, cleaned: Array<Array<string | number>>, unserializable: Array<Array<string | number>>, )
| 686 | } |
| 687 | |
| 688 | export function hydrate( |
| 689 | object: any, |
| 690 | cleaned: Array<Array<string | number>>, |
| 691 | unserializable: Array<Array<string | number>>, |
| 692 | ): Object { |
| 693 | cleaned.forEach((path: Array<string | number>) => { |
| 694 | const length = path.length; |
| 695 | const last = path[length - 1]; |
| 696 | const parent = getInObject(object, path.slice(0, length - 1)); |
| 697 | if (!parent || !parent.hasOwnProperty(last)) { |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | const value = parent[last]; |
| 702 | |
| 703 | if (!value) { |
| 704 | return; |
| 705 | } else if (value.type === 'infinity') { |
| 706 | parent[last] = Infinity; |
| 707 | } else if (value.type === 'nan') { |
| 708 | parent[last] = NaN; |
| 709 | } else if (value.type === 'undefined') { |
| 710 | parent[last] = undefined; |
| 711 | } else { |
| 712 | // Replace the string keys with Symbols so they're non-enumerable. |
| 713 | const replaced: {[key: symbol]: boolean | string} = {}; |
| 714 | replaced[meta.inspectable] = !!value.inspectable; |
| 715 | replaced[meta.inspected] = false; |
| 716 | replaced[meta.name] = value.name; |
| 717 | replaced[meta.preview_long] = value.preview_long; |
| 718 | replaced[meta.preview_short] = value.preview_short; |
| 719 | replaced[meta.size] = value.size; |
| 720 | replaced[meta.readonly] = !!value.readonly; |
| 721 | replaced[meta.type] = value.type; |
| 722 | |
| 723 | parent[last] = replaced; |
| 724 | } |
| 725 | }); |
| 726 | unserializable.forEach((path: Array<string | number>) => { |
| 727 | const length = path.length; |
| 728 | const last = path[length - 1]; |
| 729 | const parent = getInObject(object, path.slice(0, length - 1)); |
| 730 | if (!parent || !parent.hasOwnProperty(last)) { |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | const node = parent[last]; |
| 735 | |
| 736 | const replacement = { |
| 737 | ...node, |
| 738 | }; |
| 739 | |
| 740 | upgradeUnserializable(replacement, node); |
| 741 | |
| 742 | parent[last] = replacement; |
| 743 | }); |
| 744 | return object; |
| 745 | } |
no test coverage detected