From 93a5b3f457c1211676296840c285759007a55500 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 Jan 2018 13:21:01 +0100 Subject: Fix prettier --- packages/utils/src/address_utils.ts | 56 ++++++++++++------------- packages/utils/src/class_utils.ts | 28 ++++++------- packages/utils/src/configured_bignumber.ts | 2 +- packages/utils/src/interval_utils.ts | 66 +++++++++++++++--------------- packages/utils/src/promisify.ts | 18 ++++---- 5 files changed, 85 insertions(+), 85 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts index f94985441..07042cb43 100644 --- a/packages/utils/src/address_utils.ts +++ b/packages/utils/src/address_utils.ts @@ -4,33 +4,33 @@ const BASIC_ADDRESS_REGEX = /^(0x)?[0-9a-f]{40}$/i; const SAME_CASE_ADDRESS_REGEX = /^(0x)?([0-9a-f]{40}|[0-9A-F]{40})$/; export const addressUtils = { - isChecksumAddress(address: string): boolean { - // Check each case - const unprefixedAddress = address.replace('0x', ''); - const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase()); + isChecksumAddress(address: string): boolean { + // Check each case + const unprefixedAddress = address.replace('0x', ''); + const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase()); - for (let i = 0; i < 40; i++) { - // The nth letter should be uppercase if the nth digit of casemap is 1 - if ( - (parseInt(addressHash[i], 16) > 7 && unprefixedAddress[i].toUpperCase() !== unprefixedAddress[i]) || - (parseInt(addressHash[i], 16) <= 7 && unprefixedAddress[i].toLowerCase() !== unprefixedAddress[i]) - ) { - return false; - } - } - return true; - }, - isAddress(address: string): boolean { - if (!BASIC_ADDRESS_REGEX.test(address)) { - // Check if it has the basic requirements of an address - return false; - } else if (SAME_CASE_ADDRESS_REGEX.test(address)) { - // If it's all small caps or all all caps, return true - return true; - } else { - // Otherwise check each case - const isValidChecksummedAddress = addressUtils.isChecksumAddress(address); - return isValidChecksummedAddress; - } - }, + for (let i = 0; i < 40; i++) { + // The nth letter should be uppercase if the nth digit of casemap is 1 + if ( + (parseInt(addressHash[i], 16) > 7 && unprefixedAddress[i].toUpperCase() !== unprefixedAddress[i]) || + (parseInt(addressHash[i], 16) <= 7 && unprefixedAddress[i].toLowerCase() !== unprefixedAddress[i]) + ) { + return false; + } + } + return true; + }, + isAddress(address: string): boolean { + if (!BASIC_ADDRESS_REGEX.test(address)) { + // Check if it has the basic requirements of an address + return false; + } else if (SAME_CASE_ADDRESS_REGEX.test(address)) { + // If it's all small caps or all all caps, return true + return true; + } else { + // Otherwise check each case + const isValidChecksummedAddress = addressUtils.isChecksumAddress(address); + return isValidChecksummedAddress; + } + }, }; diff --git a/packages/utils/src/class_utils.ts b/packages/utils/src/class_utils.ts index 04e60ee57..7fb011f91 100644 --- a/packages/utils/src/class_utils.ts +++ b/packages/utils/src/class_utils.ts @@ -1,18 +1,18 @@ import * as _ from 'lodash'; export const classUtils = { - // This is useful for classes that have nested methods. Nested methods don't get bound out of the box. - bindAll(self: any, exclude: string[] = ['contructor'], thisArg?: any): void { - for (const key of Object.getOwnPropertyNames(self)) { - const val = self[key]; - if (!_.includes(exclude, key)) { - if (_.isFunction(val)) { - self[key] = val.bind(thisArg || self); - } else if (_.isObject(val)) { - classUtils.bindAll(val, exclude, self); - } - } - } - return self; - }, + // This is useful for classes that have nested methods. Nested methods don't get bound out of the box. + bindAll(self: any, exclude: string[] = ['contructor'], thisArg?: any): void { + for (const key of Object.getOwnPropertyNames(self)) { + const val = self[key]; + if (!_.includes(exclude, key)) { + if (_.isFunction(val)) { + self[key] = val.bind(thisArg || self); + } else if (_.isObject(val)) { + classUtils.bindAll(val, exclude, self); + } + } + } + return self; + }, }; diff --git a/packages/utils/src/configured_bignumber.ts b/packages/utils/src/configured_bignumber.ts index e44c062c2..d819e9365 100644 --- a/packages/utils/src/configured_bignumber.ts +++ b/packages/utils/src/configured_bignumber.ts @@ -3,7 +3,7 @@ import { BigNumber } from 'bignumber.js'; // By default BigNumber's `toString` method converts to exponential notation if the value has // more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number BigNumber.config({ - EXPONENTIAL_AT: 1000, + EXPONENTIAL_AT: 1000, }); export { BigNumber }; diff --git a/packages/utils/src/interval_utils.ts b/packages/utils/src/interval_utils.ts index ebecc7015..65e51677b 100644 --- a/packages/utils/src/interval_utils.ts +++ b/packages/utils/src/interval_utils.ts @@ -1,37 +1,37 @@ import * as _ from 'lodash'; export const intervalUtils = { - setAsyncExcludingInterval(fn: () => Promise, intervalMs: number, onError: (err: Error) => void) { - let locked = false; - const intervalId = setInterval(async () => { - if (locked) { - return; - } else { - locked = true; - try { - await fn(); - } catch (err) { - onError(err); - } - locked = false; - } - }, intervalMs); - return intervalId; - }, - clearAsyncExcludingInterval(intervalId: NodeJS.Timer): void { - clearInterval(intervalId); - }, - setInterval(fn: () => void, intervalMs: number, onError: (err: Error) => void) { - const intervalId = setInterval(() => { - try { - fn(); - } catch (err) { - onError(err); - } - }, intervalMs); - return intervalId; - }, - clearInterval(intervalId: NodeJS.Timer): void { - clearInterval(intervalId); - }, + setAsyncExcludingInterval(fn: () => Promise, intervalMs: number, onError: (err: Error) => void) { + let locked = false; + const intervalId = setInterval(async () => { + if (locked) { + return; + } else { + locked = true; + try { + await fn(); + } catch (err) { + onError(err); + } + locked = false; + } + }, intervalMs); + return intervalId; + }, + clearAsyncExcludingInterval(intervalId: NodeJS.Timer): void { + clearInterval(intervalId); + }, + setInterval(fn: () => void, intervalMs: number, onError: (err: Error) => void) { + const intervalId = setInterval(() => { + try { + fn(); + } catch (err) { + onError(err); + } + }, intervalMs); + return intervalId; + }, + clearInterval(intervalId: NodeJS.Timer): void { + clearInterval(intervalId); + }, }; diff --git a/packages/utils/src/promisify.ts b/packages/utils/src/promisify.ts index 29d626b61..6b29664f9 100644 --- a/packages/utils/src/promisify.ts +++ b/packages/utils/src/promisify.ts @@ -7,13 +7,13 @@ import * as _ from 'lodash'; */ // HACK: This can't be properly typed without variadic kinds https://github.com/Microsoft/TypeScript/issues/5453 export function promisify(originalFn: (...args: any[]) => void, thisArg?: any): (...callArgs: any[]) => Promise { - const promisifiedFunction = async (...callArgs: any[]): Promise => { - return new Promise((resolve, reject) => { - const callback = (err: Error | null, data?: T) => { - _.isNull(err) ? resolve(data) : reject(err); - }; - originalFn.apply(thisArg, [...callArgs, callback]); - }); - }; - return promisifiedFunction; + const promisifiedFunction = async (...callArgs: any[]): Promise => { + return new Promise((resolve, reject) => { + const callback = (err: Error | null, data?: T) => { + _.isNull(err) ? resolve(data) : reject(err); + }; + originalFn.apply(thisArg, [...callArgs, callback]); + }); + }; + return promisifiedFunction; } -- cgit v1.2.3