biggystring
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -188,2 +188,5 @@ "use strict"; | ||
let out = typeof n === 'number' ? n.toString() : n.replace(/^\s+|\s+$/g, ''); | ||
if (out === '') { | ||
out = '0'; | ||
} | ||
// Handle scientific notation | ||
@@ -437,3 +440,3 @@ const match = out.match(SCI_NOTATION_REGEX); | ||
} | ||
if (/[^\d.\-x]/.test(arg)) { | ||
if (!/^-?(?:0x[0-9A-Fa-f]+|(?:\d+(?:\.\d*)?|\.\d+))$/.test(arg)) { | ||
throw new Error(`Invalid number: non-number characters '${arg}'`); | ||
@@ -440,0 +443,0 @@ } |
@@ -45,2 +45,11 @@ "use strict"; | ||
}); | ||
it('add hex numbers 0xadef0983 + 0xABF09876 = 0x159dfa1f9', function () { | ||
chai_1.assert.equal(index_1.add('0xadef0983', '0xABF09876', 16), '0x159dfa1f9'); | ||
}); | ||
it(`convert hex to decimal using add: 0xadef0983 + 0 = 2918123907`, function () { | ||
chai_1.assert.equal(index_1.add('0xadef0983', '0', 10), '2918123907'); | ||
}); | ||
it(`convert decimal to hex using add: 2918123907 + 0 = 0xadef0983`, function () { | ||
chai_1.assert.equal(index_1.add('2918123907', '0', 16), '0xadef0983'); | ||
}); | ||
}); | ||
@@ -89,2 +98,11 @@ describe('sub', function () { | ||
}); | ||
it('multiply hex numbers 0xadef0983 * 0xABF09876 = 0x74d2230985a42a62', function () { | ||
chai_1.assert.equal(index_1.mul('0xadef0983', '0xABF09876', 16), '0x74d2230985a42a62'); | ||
}); | ||
it('convert hex to decimal using mul: 0xadef0983 * 1 = 2918123907', function () { | ||
chai_1.assert.equal(index_1.mul('0xadef0983', '1', 10), '2918123907'); | ||
}); | ||
it('convert decimal to hex using mul: 2918123907 * 1 = 0xadef0983', function () { | ||
chai_1.assert.equal(index_1.mul('2918123907', '1', 16), '0xadef0983'); | ||
}); | ||
}); | ||
@@ -142,6 +160,6 @@ describe('div', function () { | ||
it('spaces', function () { | ||
chai_1.assert.equal(index_1.toBns(' '), ''); | ||
chai_1.assert.equal(index_1.toBns(' '), '0'); | ||
}); | ||
it('2 spaces', function () { | ||
chai_1.assert.equal(index_1.toBns(' '), ''); | ||
chai_1.assert.equal(index_1.toBns(' '), '0'); | ||
}); | ||
@@ -148,0 +166,0 @@ it('scientific notation: regular numbers', function () { |
{ | ||
"name": "biggystring", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Full floating point big number library using regular Javascript string", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
106931
10
1513
1