diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-06-21 21:04:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-21 21:04:13 +0800 |
commit | 8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3 (patch) | |
tree | 15b9aa5b849d896248541722b7f2dfed6c458749 /src/utils | |
parent | ef96c58b7f7d0ce678e8eb4f662b2f6a31e8799a (diff) | |
parent | a1c363a8af3cbfa2d843aaf7ddd05390db7b8f9b (diff) | |
download | dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.gz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.bz2 dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.lz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.xz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.zst dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.zip |
Merge pull request #71 from 0xProject/lodash-tree-shake
Use different lodash import syntax which allows to include only used functions
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/assert.ts | 24 | ||||
-rw-r--r-- | src/utils/decorators.ts | 6 | ||||
-rw-r--r-- | src/utils/utils.ts | 9 |
3 files changed, 23 insertions, 16 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts index 94b119d5a..efc7ed366 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -1,4 +1,10 @@ -import * as _ from 'lodash'; +import uniq = require('lodash/uniq'); +import isEmpty = require('lodash/isEmpty'); +import isObject = require('lodash/isObject'); +import isFinite = require('lodash/isFinite'); +import isString = require('lodash/isString'); +import isBoolean = require('lodash/isBoolean'); +import isUndefined = require('lodash/isUndefined'); import * as BigNumber from 'bignumber.js'; import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; @@ -9,17 +15,17 @@ const HEX_REGEX = /^0x[0-9A-F]*$/i; export const assert = { isBigNumber(variableName: string, value: BigNumber.BigNumber): void { - const isBigNumber = _.isObject(value) && value.isBigNumber; + const isBigNumber = isObject(value) && value.isBigNumber; this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value)); }, isUndefined(value: any, variableName?: string): void { - this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value)); + this.assert(isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value)); }, isString(variableName: string, value: string): void { - this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value)); + this.assert(isString(value), this.typeAssertionMessage(variableName, 'string', value)); }, isHexString(variableName: string, value: string): void { - this.assert(_.isString(value) && HEX_REGEX.test(value), + this.assert(isString(value) && HEX_REGEX.test(value), this.typeAssertionMessage(variableName, 'HexString', value)); }, isETHAddressHex(variableName: string, value: string): void { @@ -36,19 +42,19 @@ export const assert = { }, async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> { const availableAddresses = await web3Wrapper.getAvailableAddressesAsync(); - this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance'); + this.assert(!isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance'); }, hasAtMostOneUniqueValue(value: any[], errMsg: string): void { - this.assert(_.uniq(value).length <= 1, errMsg); + this.assert(uniq(value).length <= 1, errMsg); }, isNumber(variableName: string, value: number): void { - this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value)); + this.assert(isFinite(value), this.typeAssertionMessage(variableName, 'number', value)); }, isValidOrderHash(variableName: string, value: string): void { this.assert(utils.isValidOrderHash(value), this.typeAssertionMessage(variableName, 'orderHash', value)); }, isBoolean(variableName: string, value: boolean): void { - this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); + this.assert(isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); }, doesConformToSchema(variableName: string, value: object, schema: Schema): void { const schemaValidator = new SchemaValidator(); diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts index a25f2cff5..b06e96747 100644 --- a/src/utils/decorators.ts +++ b/src/utils/decorators.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import includes = require('lodash/includes'); import {constants} from './constants'; import {AsyncMethod, ZeroExError} from '../types'; @@ -20,10 +20,10 @@ export const decorators = { const result = await originalMethod.apply(this, args); return result; } catch (error) { - if (_.includes(error.message, constants.INVALID_JUMP_PATTERN)) { + if (includes(error.message, constants.INVALID_JUMP_PATTERN)) { throw new Error(ZeroExError.INVALID_JUMP); } - if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) { + if (includes(error.message, constants.OUT_OF_GAS_PATTERN)) { throw new Error(ZeroExError.OUT_OF_GAS); } throw error; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index bad5b6498..2db611ccb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,4 +1,5 @@ -import * as _ from 'lodash'; +import map = require('lodash/map'); +import includes = require('lodash/includes'); import * as BN from 'bn.js'; import * as ethABI from 'ethereumjs-abi'; import * as ethUtil from 'ethereumjs-util'; @@ -20,7 +21,7 @@ export const utils = { console.log(message); }, isParityNode(nodeVersion: string): boolean { - return _.includes(nodeVersion, 'Parity'); + return includes(nodeVersion, 'Parity'); }, isValidOrderHash(orderHashHex: string): boolean { const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex); @@ -44,8 +45,8 @@ export const utils = { {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.uint256}, ]; - const types = _.map(orderParts, o => o.type); - const values = _.map(orderParts, o => o.value); + const types = map(orderParts, o => o.type); + const values = map(orderParts, o => o.value); const hashBuff = ethABI.soliditySHA3(types, values); const hashHex = ethUtil.bufferToHex(hashBuff); return hashHex; |