Swap-Aggregator-Subgraph/node_modules/yaml/browser/dist/toJSON.js
Richa-iitr d211083153 Revert "Revert "added handler""
This reverts commit c36ee8c5ca.
2022-07-03 07:30:05 +05:30

19 lines
577 B
JavaScript

export function toJSON(value, arg, ctx) {
if (Array.isArray(value)) return value.map(function (v, i) {
return toJSON(v, String(i), ctx);
});
if (value && typeof value.toJSON === 'function') {
var anchor = ctx && ctx.anchors && ctx.anchors.get(value);
if (anchor) ctx.onCreate = function (res) {
anchor.res = res;
delete ctx.onCreate;
};
var 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;
}