mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
21 lines
583 B
JavaScript
21 lines
583 B
JavaScript
"use strict";
|
|
|
|
exports.toJSON = toJSON;
|
|
|
|
function toJSON(value, arg, ctx) {
|
|
if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
|
|
|
|
if (value && typeof value.toJSON === 'function') {
|
|
const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
|
|
if (anchor) ctx.onCreate = res => {
|
|
anchor.res = res;
|
|
delete ctx.onCreate;
|
|
};
|
|
const res = value.toJSON(arg, ctx);
|
|
if (anchor && ctx.onCreate) ctx.onCreate(res);
|
|
return res;
|
|
}
|
|
|
|
if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
|
|
return value;
|
|
} |