UNPKG

@aeternity/aepp-sdk

Version:
78 lines (63 loc) 4.2 kB
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys"; import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"; import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter"; import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"; import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each"; import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"; import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties"; import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property"; import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty"; import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray"; import _typeof from "@babel/runtime-corejs3/helpers/typeof"; function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; } import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce"; import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map"; import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries"; import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array"; import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat"; import JsonBig from '@aeternity/json-bigint'; import BigNumber from 'bignumber.js'; var jsonBig = JsonBig({ storeAsString: true }); var convertValuesToBigNumbers = function convertValuesToBigNumbers(value) { if (_typeof(value) === 'object' && value !== null && value.constructor === Object) { var _context, _context2; return _reduceInstanceProperty(_context = _mapInstanceProperty(_context2 = _Object$entries(value)).call(_context2, function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; return [key, convertValuesToBigNumbers(value)]; })).call(_context, function (p, _ref3) { var _ref4 = _slicedToArray(_ref3, 2), k = _ref4[0], v = _ref4[1]; return _objectSpread(_objectSpread({}, p), {}, _defineProperty({}, k, v)); }, {}); } if (_Array$isArray(value)) { return _mapInstanceProperty(value).call(value, function (item) { return convertValuesToBigNumbers(item); }); } if (typeof value === 'string' && BigNumber(value).toString(10) === value) { var bn = BigNumber(value); bn.toJSON = function () { return bn.toString(10); }; return bn; } return value; }; export default { stringify: function stringify(object) { var _context3; for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } return jsonBig.stringify.apply(jsonBig, _concatInstanceProperty(_context3 = [convertValuesToBigNumbers(object)]).call(_context3, args)); }, parse: jsonBig.parse }; //# sourceMappingURL=json-big.js.map