| 831 | * @returns {Object} The JSON-compatible object. |
| 832 | */ |
| 833 | const toJSONObject = (obj) => { |
| 834 | const visited = new WeakSet(); |
| 835 | |
| 836 | const visit = (source) => { |
| 837 | if (isObject(source)) { |
| 838 | if (visited.has(source)) { |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | //Buffer check |
| 843 | if (isBuffer(source)) { |
| 844 | return source; |
| 845 | } |
| 846 | |
| 847 | if (!('toJSON' in source)) { |
| 848 | // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230). |
| 849 | visited.add(source); |
| 850 | const target = isArray(source) ? [] : {}; |
| 851 | |
| 852 | forEach(source, (value, key) => { |
| 853 | const reducedValue = visit(value); |
| 854 | !isUndefined(reducedValue) && (target[key] = reducedValue); |
| 855 | }); |
| 856 | |
| 857 | visited.delete(source); |
| 858 | |
| 859 | return target; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | return source; |
| 864 | }; |
| 865 | |
| 866 | return visit(obj); |
| 867 | }; |
| 868 | |
| 869 | /** |
| 870 | * Determines if a value is an async function. |