diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-07-07 01:23:24 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-07-07 01:23:24 +0800 |
commit | acfbba5476d48645eee7f471ecaa4b1142709939 (patch) | |
tree | 8e62f46a85c50cf3685d3a02fe63bc56fd3d6028 /packages/utils/src | |
parent | 188bf000b784fe6d9e24e3758a30a72a2795bc58 (diff) | |
download | dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.gz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.bz2 dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.lz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.xz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.zst dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.zip |
Revert moving formatUtils into utils
Diffstat (limited to 'packages/utils/src')
-rw-r--r-- | packages/utils/src/format_utils.ts | 61 | ||||
-rw-r--r-- | packages/utils/src/index.ts | 1 |
2 files changed, 0 insertions, 62 deletions
diff --git a/packages/utils/src/format_utils.ts b/packages/utils/src/format_utils.ts deleted file mode 100644 index 101854926..000000000 --- a/packages/utils/src/format_utils.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as _ from 'lodash'; - -import { BigNumber } from './configured_bignumber'; - -// tslint:disable:restrict-plus-operands -export const formatUtils = { - isBigNumber(value: any): boolean { - const isBigNumber = _.isObject(value) && value.isBigNumber; - return isBigNumber; - }, - convertHexToNumber(value: string): number { - const valueBigNumber = new BigNumber(value); - const valueNumber = valueBigNumber.toNumber(); - return valueNumber; - }, - convertHexToNumberOrNull(hex: string | null): number | null { - if (_.isNull(hex)) { - return null; - } - const decimal = this.convertHexToNumber(hex); - return decimal; - }, - convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { - const num = value || 0; - const isBigNumber = formatUtils.isBigNumber(num); - if (isBigNumber) { - return num as BigNumber; - } - - if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { - return new BigNumber(num.replace('0x', ''), 16); - } - - const baseTen = 10; - return new BigNumber((num as number).toString(baseTen), baseTen); - }, - encodeAmountAsHexString(value: string | number | BigNumber): string { - const valueBigNumber = formatUtils.convertAmountToBigNumber(value); - const hexBase = 16; - const valueHex = valueBigNumber.toString(hexBase); - - return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; - }, - numberToHex(value: number): string { - if (!isFinite(value) && !this.isHexStrict(value)) { - throw new Error(`Given input ${value} is not a number.`); - } - - const valueBigNumber = new BigNumber(value); - const hexBase = 16; - const result = valueBigNumber.toString(hexBase); - - return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; - }, - isHexStrict(hex: string | number): boolean { - return ( - (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) - ); - }, -}; -// tslint:enable:restrict-plus-operands diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index cc8592400..fd102cecb 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,4 +8,3 @@ export { logUtils } from './log_utils'; export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; -export { formatUtils } from './format_utils'; |