From bacb03cc5d7f12839cbd67b97e3f1b30cbf468fa Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Fri, 22 May 2015 11:45:37 -0300 Subject: [PATCH 1/2] Rename Kwei to kwei, added support for some SI base units for ether --- lib/utils/config.js | 48 ++++++++++++++++++------------- lib/utils/utils.js | 70 ++++++++++++++++++++++++++------------------- test/utils.toWei.js | 8 ++++++ 3 files changed, 76 insertions(+), 50 deletions(-) diff --git a/lib/utils/config.js b/lib/utils/config.js index b5365cc..fdf4179 100644 --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -36,26 +36,34 @@ /// required to define ETH_BIGNUMBER_ROUNDING_MODE var BigNumber = require('bignumber.js'); -var ETH_UNITS = [ - 'wei', - 'Kwei', - 'Mwei', - 'Gwei', - 'szabo', - 'finney', - 'ether', - 'grand', - 'Mether', - 'Gether', - 'Tether', - 'Pether', - 'Eether', - 'Zether', - 'Yether', - 'Nether', - 'Dether', - 'Vether', - 'Uether' +var ETH_UNITS = [ + 'wei', + 'kwei', + 'Mwei', + 'Gwei', + 'szabo', + 'finney', + 'femtoether', + 'picoether', + 'nanoether', + 'microether', + 'miliether', + 'nano', + 'micro', + 'mili', + 'ether', + 'grand', + 'Mether', + 'Gether', + 'Tether', + 'Pether', + 'Eether', + 'Zether', + 'Yether', + 'Nether', + 'Dether', + 'Vether', + 'Uether' ]; module.exports = { diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 91964c3..fccfb90 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -36,22 +36,30 @@ var BigNumber = require('bignumber.js'); var unitMap = { - 'wei': '1', - 'kwei': '1000', - 'ada': '1000', - 'mwei': '1000000', - 'babbage': '1000000', - 'gwei': '1000000000', - 'shannon': '1000000000', - 'szabo': '1000000000000', - 'finney': '1000000000000000', - 'ether': '1000000000000000000', - 'kether': '1000000000000000000000', - 'grand': '1000000000000000000000', - 'einstein': '1000000000000000000000', - 'mether': '1000000000000000000000000', - 'gether': '1000000000000000000000000000', - 'tether': '1000000000000000000000000000000' + 'wei': '1', + 'kwei': '1000', + 'ada': '1000', + 'femtoether': '1000', + 'mwei': '1000000', + 'babbage': '1000000', + 'picoether': '1000000', + 'gwei': '1000000000', + 'shannon': '1000000000', + 'nanoether': '1000000000', + 'nano': '1000000000', + 'szabo': '1000000000000', + 'microether': '1000000000000', + 'micro': '1000000000000', + 'finney': '1000000000000000', + 'miliether': '1000000000000000', + 'mili': '1000000000000000', + 'ether': '1000000000000000000', + 'kether': '1000000000000000000000', + 'grand': '1000000000000000000000', + 'einstein': '1000000000000000000000', + 'mether': '1000000000000000000000000', + 'gether': '1000000000000000000000000000', + 'tether': '1000000000000000000000000000000' }; /** @@ -239,13 +247,14 @@ var getValueOfUnit = function (unit) { * Takes a number of wei and converts it to any other ether unit. * * Possible units are: - * - kwei/ada - * - mwei/babbage - * - gwei/shannon - * - szabo - * - finney - * - ether - * - kether/grand/einstein + * SI Short SI Full Effigy Other + * - kwei femtoether ada + * - mwei picoether babbage + * - gwei nanoether shannon nano + * - -- microether szabo micro + * - -- miliether finney mili + * - ether -- -- + * - kether einstein grand * - mether * - gether * - tether @@ -265,13 +274,14 @@ var fromWei = function(number, unit) { * Takes a number of a unit and converts it to wei. * * Possible units are: - * - kwei/ada - * - mwei/babbage - * - gwei/shannon - * - szabo - * - finney - * - ether - * - kether/grand/einstein + * SI Short SI Full Effigy Other + * - kwei femtoether ada + * - mwei picoether babbage + * - gwei nanoether shannon nano + * - -- microether szabo micro + * - -- miliether finney mili + * - ether -- -- + * - kether einstein grand * - mether * - gether * - tether diff --git a/test/utils.toWei.js b/test/utils.toWei.js index 3bb0997..e87315f 100644 --- a/test/utils.toWei.js +++ b/test/utils.toWei.js @@ -19,6 +19,14 @@ describe('lib/utils/utils', function () { assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); + assert.equal(utils.toWei(1, 'kwei'), utils.toWei(1, 'femtoether')); + assert.equal(utils.toWei(1, 'babbage'), utils.toWei(1, 'picoether')); + assert.equal(utils.toWei(1, 'shannon'), utils.toWei(1, 'nanoether')); + assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether')); + assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'miliether')); + assert.equal(utils.toWei(1, 'mili'), utils.toWei(1, 'miliether')); + assert.equal(utils.toWei(1, 'mili'), utils.toWei(1000, 'micro')); + assert.throws(function () {utils.toWei(1, 'wei1');}, Error); }); }); From 5866f0882a7149477fb07455e94a815cac15c17a Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Fri, 22 May 2015 12:04:06 -0300 Subject: [PATCH 2/2] milli should have two l's --- lib/utils/config.js | 4 ++-- lib/utils/utils.js | 8 ++++---- test/utils.toWei.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/utils/config.js b/lib/utils/config.js index fdf4179..d25b5d7 100644 --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -47,10 +47,10 @@ var ETH_UNITS = [ 'picoether', 'nanoether', 'microether', - 'miliether', + 'milliether', 'nano', 'micro', - 'mili', + 'milli', 'ether', 'grand', 'Mether', diff --git a/lib/utils/utils.js b/lib/utils/utils.js index fccfb90..1860a84 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -51,8 +51,8 @@ var unitMap = { 'microether': '1000000000000', 'micro': '1000000000000', 'finney': '1000000000000000', - 'miliether': '1000000000000000', - 'mili': '1000000000000000', + 'milliether': '1000000000000000', + 'milli': '1000000000000000', 'ether': '1000000000000000000', 'kether': '1000000000000000000000', 'grand': '1000000000000000000000', @@ -252,7 +252,7 @@ var getValueOfUnit = function (unit) { * - mwei picoether babbage * - gwei nanoether shannon nano * - -- microether szabo micro - * - -- miliether finney mili + * - -- milliether finney milli * - ether -- -- * - kether einstein grand * - mether @@ -279,7 +279,7 @@ var fromWei = function(number, unit) { * - mwei picoether babbage * - gwei nanoether shannon nano * - -- microether szabo micro - * - -- miliether finney mili + * - -- milliether finney milli * - ether -- -- * - kether einstein grand * - mether diff --git a/test/utils.toWei.js b/test/utils.toWei.js index e87315f..55b6c93 100644 --- a/test/utils.toWei.js +++ b/test/utils.toWei.js @@ -23,9 +23,9 @@ describe('lib/utils/utils', function () { assert.equal(utils.toWei(1, 'babbage'), utils.toWei(1, 'picoether')); assert.equal(utils.toWei(1, 'shannon'), utils.toWei(1, 'nanoether')); assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether')); - assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'miliether')); - assert.equal(utils.toWei(1, 'mili'), utils.toWei(1, 'miliether')); - assert.equal(utils.toWei(1, 'mili'), utils.toWei(1000, 'micro')); + assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'milliether')); + assert.equal(utils.toWei(1, 'milli'), utils.toWei(1, 'milliether')); + assert.equal(utils.toWei(1, 'milli'), utils.toWei(1000, 'micro')); assert.throws(function () {utils.toWei(1, 'wei1');}, Error); });