MCPcopy
hub / github.com/axios/axios / toJSONObject

Function toJSONObject

lib/utils.js:833–867  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

831 * @returns {Object} The JSON-compatible object.
832 */
833const 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.

Callers

nothing calls this directly

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected