aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/conversion.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-07-06 09:56:58 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-07-06 09:56:58 +0800
commit608442b2e80f64c1756e2c5125812c067e5ae1f3 (patch)
treee8997d7510488e8ead88a32f9e7b4e791c46ca18 /packages/utils/src/conversion.ts
parentaefc122cafc3e1b233450b07a1a4c70c2dc04ddd (diff)
downloaddexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar.gz
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar.bz2
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar.lz
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar.xz
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.tar.zst
dexon-sol-tools-608442b2e80f64c1756e2c5125812c067e5ae1f3.zip
Add to changelog, rename to formatUtils and lint
Diffstat (limited to 'packages/utils/src/conversion.ts')
-rw-r--r--packages/utils/src/conversion.ts59
1 files changed, 0 insertions, 59 deletions
diff --git a/packages/utils/src/conversion.ts b/packages/utils/src/conversion.ts
deleted file mode 100644
index f0eed9ee4..000000000
--- a/packages/utils/src/conversion.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import * as _ from 'lodash';
-
-import { BigNumber } from './configured_bignumber';
-
-export const conversion = {
- 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 = conversion.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 = conversion.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)
- );
- },
-};