refactor: custom json stringify not needed

This commit is contained in:
Derrick Hammer 2023-09-07 19:30:51 -04:00
parent 885aaadd4f
commit d83d4892cc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 0 additions and 21 deletions

View File

@ -1,21 +0,0 @@
import { addContextToErr } from "./err.js";
import { objAsString } from "./objAsString.js";
import { Err } from "./types.js";
// jsonStringify is a replacement for JSON.stringify that returns an error
// rather than throwing.
function jsonStringify(obj: any): [string, Err] {
try {
const str = JSON.stringify(obj, (_, v) => {
if (typeof v === "bigint") {
return Number(v);
}
return v;
});
return [str, null];
} catch (err) {
return ["", addContextToErr(objAsString(err), "unable to stringify object")];
}
}
export { jsonStringify };