fix eslint errors

This commit is contained in:
Ivan Tivonenko
2015-09-17 19:49:46 +03:00
parent 20fa8bc953
commit 01752e5486
7 changed files with 49 additions and 39 deletions

View File

@@ -105,17 +105,17 @@ Amount.NaN = function() {
return result; // but let's be careful
};
Amount.createFast = function(value: Value, currency: Currency, issuer: UInt160,
isNative: boolean
Amount.from_components_unsafe = function(value: Value, currency: Currency,
issuer: UInt160, isNative: boolean
) {
const res = new Amount(value);
res._is_native = isNative;
res._currency = currency;
res._issuer = issuer;
const result = new Amount(value);
result._is_native = isNative;
result._currency = currency;
result._issuer = issuer;
res._value = value.isZero() && value.isNegative() ?
result._value = value.isZero() && value.isNegative() ?
value.negate() : value;
return res;
return result;
};
// be sure that _is_native is set properly BEFORE calling _set_value
@@ -749,6 +749,14 @@ Amount.prototype.to_number = function() {
return Number(this.to_text());
};
// this one is needed because Value.abs creates new BigNumber,
// and BigNumber constructor is very slow, so we want to
// call it only if absolutely necessary
function absValue(value: Value): Value {
return value.isNegative() ? value.abs() : value;
}
// Convert only value to JSON wire format.
Amount.prototype.to_text = function() {
if (!this.is_valid()) {
@@ -762,9 +770,8 @@ Amount.prototype.to_text = function() {
// not native
const offset = this._value.getExponent() - 15;
const sign = this._value.isNegative() ? '-' : '';
const mantissa = this._value.isNegative() ?
utils.getMantissa16FromString(this._value.abs().toString()) :
utils.getMantissa16FromString(this._value.toString());
const mantissa =
utils.getMantissa16FromString(absValue(this._value).toString());
if (offset !== 0 && (offset < -25 || offset > -4)) {
// Use e notation.
// XXX Clamp output.

View File

@@ -14,7 +14,8 @@ function normalize(digitArray) {
function divmod(digitArray, base, divisor) {
let remainder = 0;
let temp, divided;
let temp;
let divided;
let j = -1;
const length = digitArray.length;
@@ -31,7 +32,8 @@ function divmod(digitArray, base, divisor) {
function convertBase(digitArray, fromBase, toBase) {
const result = [];
let dividend = digitArray, qr;
let dividend = digitArray;
let qr;
while (dividend.length > 0) {
qr = divmod(dividend, fromBase, toBase);
result.unshift(qr.remainder);

View File

@@ -1207,7 +1207,8 @@ OrderBook.prototype.setOffers = function(offers) {
this.resetCache();
let i = -1, offer;
let i = -1;
let offer;
const l = offers.length;
while (++i < l) {

View File

@@ -32,7 +32,8 @@ function createAmount(value, currency_, counterparty_) {
counterparty_ :
UInt160.from_json(counterparty_);
return Amount.createFast(new IOUValue(value), currency, counterparty, false);
return Amount.from_components_unsafe(new IOUValue(value),
currency, counterparty, false);
}
/**
@@ -179,8 +180,8 @@ OrderBookUtils.ISSUER_ONE = UInt160.from_json(1);
*/
OrderBookUtils.normalizeAmount = function(value) {
return Amount.createFast(new IOUValue(value), OrderBookUtils.CURRENCY_ONE,
OrderBookUtils.ISSUER_ONE, false);
return Amount.from_components_unsafe(new IOUValue(value),
OrderBookUtils.CURRENCY_ONE, OrderBookUtils.ISSUER_ONE, false);
};
module.exports = OrderBookUtils;

View File

@@ -1,14 +1,14 @@
'use strict';
var utils = require('./utils');
var extend = require('extend');
var UInt = require('./uint').UInt;
const utils = require('./utils');
const extend = require('extend');
const UInt = require('./uint').UInt;
//
// UInt128 support
//
var UInt128 = extend(function() {
const UInt128 = extend(function() {
this._value = NaN;
}, UInt);
@@ -16,8 +16,8 @@ UInt128.width = 16;
UInt128.prototype = Object.create(extend({}, UInt.prototype));
UInt128.prototype.constructor = UInt128;
var HEX_ZERO = UInt128.HEX_ZERO = '00000000000000000000000000000000';
var HEX_ONE = UInt128.HEX_ONE = '00000000000000000000000000000000';
const HEX_ZERO = UInt128.HEX_ZERO = '00000000000000000000000000000000';
const HEX_ONE = UInt128.HEX_ONE = '00000000000000000000000000000000';
UInt128.STR_ZERO = utils.hexToString(HEX_ZERO);
UInt128.STR_ONE = utils.hexToString(HEX_ONE);

View File

@@ -1,16 +1,16 @@
'use strict';
var utils = require('./utils');
var extend = require('extend');
const utils = require('./utils');
const extend = require('extend');
var UInt = require('./uint').UInt;
var Base = require('./base').Base;
const UInt = require('./uint').UInt;
const Base = require('./base').Base;
//
// UInt160 support
//
var UInt160 = extend(function() {
const UInt160 = extend(function() {
this._value = NaN;
this._version_byte = undefined;
this._update();
@@ -20,8 +20,8 @@ UInt160.width = 20;
UInt160.prototype = Object.create(extend({}, UInt.prototype));
UInt160.prototype.constructor = UInt160;
var HEX_ZERO = UInt160.HEX_ZERO = '0000000000000000000000000000000000000000';
var HEX_ONE = UInt160.HEX_ONE = '0000000000000000000000000000000000000001';
const HEX_ZERO = UInt160.HEX_ZERO = '0000000000000000000000000000000000000000';
const HEX_ONE = UInt160.HEX_ONE = '0000000000000000000000000000000000000001';
UInt160.ACCOUNT_ZERO = 'rrrrrrrrrrrrrrrrrrrrrhoLvTp';
UInt160.ACCOUNT_ONE = 'rrrrrrrrrrrrrrrrrrrrBZbvji';
@@ -74,13 +74,12 @@ UInt160.prototype.parse_generic = function(j) {
};
// XXX Json form should allow 0 and 1, C++ doesn't currently allow it.
UInt160.prototype.to_json = function(opts) {
opts = opts || {};
UInt160.prototype.to_json = function(opts = {}) {
if (this.is_valid()) {
// If this value has a type, return a Base58 encoded string.
if (typeof this._version_byte === 'number') {
var output = Base.encode_check(this._version_byte, this.to_bytes());
let output = Base.encode_check(this._version_byte, this.to_bytes());
if (opts.gateways && output in opts.gateways) {
output = opts.gateways[output];

View File

@@ -1,14 +1,14 @@
'use strict';
var utils = require('./utils');
var extend = require('extend');
var UInt = require('./uint').UInt;
const utils = require('./utils');
const extend = require('extend');
const UInt = require('./uint').UInt;
//
// UInt256 support
//
var UInt256 = extend(function() {
const UInt256 = extend(function() {
this._value = NaN;
}, UInt);
@@ -16,10 +16,10 @@ UInt256.width = 32;
UInt256.prototype = Object.create(extend({}, UInt.prototype));
UInt256.prototype.constructor = UInt256;
var HEX_ZERO = UInt256.HEX_ZERO = '00000000000000000000000000000000' +
const HEX_ZERO = UInt256.HEX_ZERO = '00000000000000000000000000000000' +
'00000000000000000000000000000000';
var HEX_ONE = UInt256.HEX_ONE = '00000000000000000000000000000000' +
const HEX_ONE = UInt256.HEX_ONE = '00000000000000000000000000000000' +
'00000000000000000000000000000001';
UInt256.STR_ZERO = utils.hexToString(HEX_ZERO);