Skip to content

Commit

Permalink
version 1.2.0 -- negative number fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentCicero committed Dec 7, 2016
1 parent 685017f commit 44dfa6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.0 -- decimal number fix

1. now throws under decimal number

# 1.1.0 -- es5 support

1. es5 support
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "number-to-bn",
"version": "1.1.0",
"version": "1.2.0",
"description": "A simple method that will convert a string integer, hex, BN or bignumber.js object into a BN.js object.",
"main": "src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function numberToBN(arg) {
} else {
throw errorMessage;
}
} else if (typeof arg === 'number') {
} else if (typeof arg === 'number' && String(arg).match(/^-?[0-9]+$/)) {
return new BN(String(arg));
} else if (typeof arg === 'object'
&& arg.toString
Expand Down
4 changes: 4 additions & 0 deletions src/tests/test.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe("numberToBN", () => {
assert.deepEqual(numberToBN(new BigNumber(1000)).toNumber(10), 1000);
});

it('should convert a negative 1.1 throws', () => {
assert.throws(() => numberToBN(1.1).toNumber(10), Error);
});

it('should convert a negative BigNumber', () => {
assert.deepEqual(numberToBN(new BigNumber(-1)).toNumber(10), -1);
});
Expand Down

0 comments on commit 44dfa6f

Please sign in to comment.