@yoroi/common
Version:
The Common package of Yoroi SDK
19 lines (18 loc) • 701 B
JavaScript
import BigNumber from 'bignumber.js';
/**
* Serializes the given object into a JSON string, with support for BigInt and BigNumber values.
* Since BigInt and BigNumber are not supported by JSON.stringify, it serialize them as strings.
*
* @param toStringify - The object to be serialized.
* @returns A stringfied JSON object with BigInt and BigNumber values serialized as strings.
*/
export const storageSerializer = toStringify => {
const replacer = (_, value) => {
if (typeof value === 'bigint' || BigNumber.isBigNumber(value)) {
return value.toString();
}
return value;
};
return JSON.stringify(toStringify, replacer);
};
//# sourceMappingURL=storage-serializer.js.map