UNPKG

@iexec/iexec-oracle-factory-wrapper

Version:
26 lines 853 B
/* eslint-disable @typescript-eslint/no-explicit-any */ import { Big } from 'big.js'; const sortObjKeys = (obj) => Object.keys(obj) .sort() .reduce((acc, curr) => { if (typeof obj[curr] === 'object') { acc[curr] = sortObjKeys(obj[curr]); } else { acc[curr] = obj[curr]; } return acc; }, {}); const formatParamsJson = (obj) => JSON.stringify(sortObjKeys(obj)); const formatOracleGetNumber = (resultBn) => { const resultBig = new Big(resultBn.toString()).times(new Big('1e-18')); try { resultBig.constructor.strict = true; return resultBig.toNumber(); } catch (e) { throw new Error(`Converting ${resultBig.toString()} to number will result in losing precision`); } }; export { sortObjKeys, formatParamsJson, formatOracleGetNumber }; //# sourceMappingURL=format.js.map