Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,7 @@ | ||
# 0.0.2 -- ethjs-unit | ||
1. More test coverage | ||
2. Config | ||
3. More docs | ||
# 0.0.1 -- ethjs-unit | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "ethjs-unit", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A simple module for handling Ethereum units (e.g. 'ether', 'wei', etc...)", | ||
@@ -15,7 +15,29 @@ "main": "./src/index.js", | ||
"lint:staged": "lint-staged", | ||
"coveralls": "cat ./coverage/lcov/lcov.info | coveralls" | ||
"test-travis": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- src/tests/**/*.js -R spec --timeout 2000000", | ||
"coveralls": "npm run test-travis && cat ./coverage/lcov.info | coveralls" | ||
}, | ||
"engines": { | ||
"npm": ">=3", | ||
"node": ">=6.5.0" | ||
}, | ||
"dependencies": { | ||
"bignumber.js": "^3.0.1" | ||
"bignumber.js": "3.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "7.1.0", | ||
"chai": "3.5.0", | ||
"coveralls": "2.11.9", | ||
"eslint": "2.10.1", | ||
"istanbul": "0.4.5", | ||
"eslint-config-airbnb": "9.0.1", | ||
"eslint-import-resolver-webpack": "0.2.4", | ||
"eslint-plugin-import": "1.8.0", | ||
"eslint-plugin-jsx-a11y": "1.2.0", | ||
"eslint-plugin-react": "5.1.1", | ||
"eventsource-polyfill": "0.9.6", | ||
"lint-staged": "1.0.1", | ||
"mocha": "3.1.2", | ||
"pre-commit": "1.1.3", | ||
"web3": "0.17.0-beta" | ||
}, | ||
"keywords": [ | ||
@@ -56,21 +78,5 @@ "ethereum", | ||
"type": "git", | ||
"url": "git://github.com/silentcicero/ethjs-unit" | ||
"url": "git://github.com/ethjs/ethjs-unit" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-eslint": "7.1.0", | ||
"chai": "^3.5.0", | ||
"coveralls": "2.11.9", | ||
"eslint": "2.10.1", | ||
"eslint-config-airbnb": "9.0.1", | ||
"eslint-import-resolver-webpack": "0.2.4", | ||
"eslint-plugin-import": "1.8.0", | ||
"eslint-plugin-jsx-a11y": "1.2.0", | ||
"eslint-plugin-react": "5.1.1", | ||
"eventsource-polyfill": "0.9.6", | ||
"lint-staged": "1.0.1", | ||
"mocha": "^3.1.2", | ||
"pre-commit": "1.1.3", | ||
"web3": "^0.17.0-beta" | ||
}, | ||
"babel": { | ||
@@ -77,0 +83,0 @@ "presets": [ |
@@ -5,4 +5,4 @@ ## ethjs-unit | ||
<!-- Dependency Status --> | ||
<a href="https://david-dm.org/SilentCicero/ethjs-unit"> | ||
<img src="https://david-dm.org/SilentCicero/ethjs-unit.svg" | ||
<a href="https://david-dm.org/ethjs/ethjs-unit"> | ||
<img src="https://david-dm.org/ethjs/ethjs-unit.svg" | ||
alt="Dependency Status" /> | ||
@@ -12,9 +12,9 @@ </a> | ||
<!-- devDependency Status --> | ||
<a href="https://david-dm.org/SilentCicero/ethjs-unit#info=devDependencies"> | ||
<img src="https://david-dm.org/SilentCicero/ethjs-unit/dev-status.svg" alt="devDependency Status" /> | ||
<a href="https://david-dm.org/ethjs/ethjs-unit#info=devDependencies"> | ||
<img src="https://david-dm.org/ethjs/ethjs-unit/dev-status.svg" alt="devDependency Status" /> | ||
</a> | ||
<!-- Build Status --> | ||
<a href="https://travis-ci.org/SilentCicero/ethjs-unit"> | ||
<img src="https://travis-ci.org/SilentCicero/ethjs-unit.svg" | ||
<a href="https://travis-ci.org/ethjs/ethjs-unit"> | ||
<img src="https://travis-ci.org/ethjs/ethjs-unit.svg" | ||
alt="Build Status" /> | ||
@@ -29,2 +29,7 @@ </a> | ||
<!-- Test Coverage --> | ||
<a href="https://coveralls.io/r/ethjs/ethjs-unit"> | ||
<img src="https://coveralls.io/repos/github/ethjs/ethjs-unit/badge.svg" alt="Test Coverage" /> | ||
</a> | ||
<!-- Javascript Style --> | ||
@@ -73,3 +78,2 @@ <a href="http://airbnb.io/javascript/"> | ||
fromWei <Function (value, unit) : (BigNumber)> | ||
getValueOfUnit <Function (value) : (BigNumber)> | ||
``` | ||
@@ -135,3 +139,3 @@ | ||
We communicate via [issues](https://github.com/SilentCicero/ethjs-unit/issues) and [pull requests](https://github.com/SilentCicero/ethjs-unit/pulls). | ||
We communicate via [issues](https://github.com/ethjs/ethjs-unit/issues) and [pull requests](https://github.com/ethjs/ethjs-unit/pulls). | ||
@@ -142,3 +146,3 @@ ## Important documents | ||
- [Code of Conduct](CODE_OF_CONDUCT.md) | ||
- [License](https://raw.githubusercontent.com/SilentCicero/ethjs-unit/master/LICENSE) | ||
- [License](https://raw.githubusercontent.com/ethjs/ethjs-unit/master/LICENSE) | ||
@@ -145,0 +149,0 @@ ## Licence |
@@ -146,3 +146,2 @@ const BigNumber = require('bignumber.js'); | ||
fromWei, | ||
getValueOfUnit, | ||
}; |
@@ -7,10 +7,10 @@ const units = require('../index.js'); // eslint-disable-line | ||
function testRandomUnitAndNumber() { | ||
function testRandomunitsAndNumber() { | ||
const stringTestValue = String(Math.floor((Math.random() * 1000000000000000) + 1)); | ||
const testValue = new BigNumber(stringTestValue); | ||
const totalTypes = Object.keys(units.unitMap).length; | ||
const randomUnitType = Object.keys(units.unitMap)[Math.floor((Math.random() * (totalTypes - 1)) + 1)]; | ||
const randomunitsType = Object.keys(units.unitMap)[Math.floor((Math.random() * (totalTypes - 1)) + 1)]; | ||
assert.equal(units.toWei(testValue, randomUnitType).toString(10), web3.toWei(testValue, randomUnitType).toString(10)); | ||
assert.equal(units.fromWei(testValue, randomUnitType).toString(10), web3.fromWei(testValue, randomUnitType).toString(10)); | ||
assert.equal(units.toWei(testValue, randomunitsType).toString(10), web3.toWei(testValue, randomunitsType).toString(10)); | ||
assert.equal(units.fromWei(testValue, randomunitsType).toString(10), web3.fromWei(testValue, randomunitsType).toString(10)); | ||
} | ||
@@ -22,3 +22,3 @@ | ||
for (var i = 0; i < 100000; i++) { // eslint-disable-line | ||
testRandomUnitAndNumber(); | ||
testRandomunitsAndNumber(); | ||
} | ||
@@ -28,1 +28,108 @@ }); | ||
}); | ||
describe('fromWei', () => { | ||
it('should return the correct value', () => { | ||
assert.equal(units.fromWei(1000000000000000000, 'wei').toString(10), '1000000000000000000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'kwei').toString(10), '1000000000000000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'mwei').toString(10), '1000000000000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'gwei').toString(10), '1000000000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'szabo').toString(10), '1000000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'finney').toString(10), '1000'); | ||
assert.equal(units.fromWei(1000000000000000000, 'ether').toString(10), '1'); | ||
assert.equal(units.fromWei(1000000000000000000, 'kether').toString(10), '0.001'); | ||
assert.equal(units.fromWei(1000000000000000000, 'grand').toString(10), '0.001'); | ||
assert.equal(units.fromWei(1000000000000000000, 'mether').toString(10), '0.000001'); | ||
assert.equal(units.fromWei(1000000000000000000, 'gether').toString(10), '0.000000001'); | ||
assert.equal(units.fromWei(1000000000000000000, 'tether').toString(10), '0.000000000001'); | ||
}); | ||
}); | ||
describe('toWei', () => { | ||
it('should return the correct value', () => { | ||
assert.equal(units.toWei(1, 'wei').toString(10), '1'); | ||
assert.equal(units.toWei(1, 'kwei').toString(10), '1000'); | ||
assert.equal(units.toWei(1, 'Kwei').toString(10), '1000'); | ||
assert.equal(units.toWei(1, 'babbage').toString(10), '1000'); | ||
assert.equal(units.toWei(1, 'mwei').toString(10), '1000000'); | ||
assert.equal(units.toWei(1, 'Mwei').toString(10), '1000000'); | ||
assert.equal(units.toWei(1, 'lovelace').toString(10), '1000000'); | ||
assert.equal(units.toWei(1, 'gwei').toString(10), '1000000000'); | ||
assert.equal(units.toWei(1, 'Gwei').toString(10), '1000000000'); | ||
assert.equal(units.toWei(1, 'shannon').toString(10), '1000000000'); | ||
assert.equal(units.toWei(1, 'szabo').toString(10), '1000000000000'); | ||
assert.equal(units.toWei(1, 'finney').toString(10), '1000000000000000'); | ||
assert.equal(units.toWei(1, 'ether').toString(10), '1000000000000000000'); | ||
assert.equal(units.toWei(1, 'kether').toString(10), '1000000000000000000000'); | ||
assert.equal(units.toWei(1, 'grand').toString(10), '1000000000000000000000'); | ||
assert.equal(units.toWei(1, 'mether').toString(10), '1000000000000000000000000'); | ||
assert.equal(units.toWei(1, 'gether').toString(10), '1000000000000000000000000000'); | ||
assert.equal(units.toWei(1, 'tether').toString(10), '1000000000000000000000000000000'); | ||
assert.equal(units.toWei(1, 'kwei').toString(10), units.toWei(1, 'femtoether').toString(10)); | ||
assert.equal(units.toWei(1, 'szabo').toString(10), units.toWei(1, 'microether').toString(10)); | ||
assert.equal(units.toWei(1, 'finney').toString(10), units.toWei(1, 'milliether').toString(10)); | ||
assert.equal(units.toWei(1, 'milli').toString(10), units.toWei(1, 'milliether').toString(10)); | ||
assert.equal(units.toWei(1, 'milli').toString(10), units.toWei(1000, 'micro').toString(10)); | ||
assert.throws(() => { units.toWei(1, 'wei1'); }, Error); | ||
}); | ||
}); | ||
const tests = [ | ||
{ value: function () {}, is: false }, // eslint-disable-line | ||
{ value: new Function(), is: false }, // eslint-disable-line | ||
{ value: 'function', is: false }, | ||
{ value: {}, is: false }, | ||
{ value: new String('hello'), is: false }, // eslint-disable-line | ||
{ value: new BigNumber(0), is: true }, | ||
{ value: 132, is: false }, | ||
{ value: '0x12', is: false }, | ||
]; | ||
describe('isBigNumber', () => { | ||
tests.forEach((test) => { | ||
it(`shoud test if value ${test.value} is BigNumber: ${test.is}`, () => { | ||
assert.equal(units.isBigNumber(test.value), test.is); | ||
}); | ||
}); | ||
}); | ||
const toBigNumberTests = [ | ||
{ value: 1, expected: '1' }, | ||
{ value: '1', expected: '1' }, | ||
{ value: '0x1', expected: '1' }, | ||
{ value: '0x01', expected: '1' }, | ||
{ value: 15, expected: '15' }, | ||
{ value: '15', expected: '15' }, | ||
{ value: '0xf', expected: '15' }, | ||
{ value: '0x0f', expected: '15' }, | ||
{ value: new BigNumber('f', 16), expected: '15' }, | ||
{ value: -1, expected: '-1' }, | ||
{ value: '-1', expected: '-1' }, | ||
{ value: '-0x1', expected: '-1' }, | ||
{ value: '-0x01', expected: '-1' }, | ||
{ value: -15, expected: '-15' }, | ||
{ value: '-15', expected: '-15' }, | ||
{ value: '-0xf', expected: '-15' }, | ||
{ value: '-0x0f', expected: '-15' }, | ||
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935' }, | ||
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933' }, | ||
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935' }, | ||
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933' }, | ||
{ value: 0, expected: '0' }, | ||
{ value: '0', expected: '0' }, | ||
{ value: '0x0', expected: '0' }, | ||
{ value: -0, expected: '0' }, | ||
{ value: '-0', expected: '0' }, | ||
{ value: '-0x0', expected: '0' }, | ||
{ value: new BigNumber(0), expected: '0' }, | ||
]; | ||
describe('toBigNumber', () => { | ||
toBigNumberTests.forEach((test) => { | ||
it(`should turn ${test.value} to 4 ${test.expected}`, () => { | ||
assert.equal(units.toBigNumber(test.value).toString(10), test.expected); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
32894
14
252
174
15
1
+ Addedbignumber.js@3.0.1(transitive)
- Removedbignumber.js@3.1.2(transitive)
Updatedbignumber.js@3.0.1