UNPKG

@yoroi/common

Version:

The Common package of Yoroi SDK

26 lines (25 loc) 989 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.storageSerializer = void 0; var _bignumber = _interopRequireDefault(require("bignumber.js")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * 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. */ const storageSerializer = toStringify => { const replacer = (_, value) => { if (typeof value === 'bigint' || _bignumber.default.isBigNumber(value)) { return value.toString(); } return value; }; return JSON.stringify(toStringify, replacer); }; exports.storageSerializer = storageSerializer; //# sourceMappingURL=storage-serializer.js.map