bignumberify
Advanced tools
Comparing version 0.0.2 to 0.0.3
12
index.js
@@ -10,6 +10,14 @@ const ethers = require("ethers"); | ||
}; | ||
const convert = (bn) => { | ||
try { | ||
bn = ethers.BigNumber.from(bn.hex); | ||
} catch(e) { | ||
// if it looks like a BigNumber but it is not | ||
} | ||
return bn; | ||
} | ||
const manage = (item, i) => { | ||
if (isObject(item[i])) { | ||
if (isBN(item[i])) { | ||
item[i] = ethers.BigNumber.from(item[i].hex); | ||
item[i] = convert(item[i]); | ||
} else { | ||
@@ -28,3 +36,3 @@ item[i] = bigNumberify(item[i]); | ||
if (isBN(obj)) { | ||
obj = ethers.BigNumber.from(obj.hex); | ||
obj = convert(obj); | ||
} else | ||
@@ -31,0 +39,0 @@ for (let i in obj) { |
{ | ||
"name": "bignumberify", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A parser to correctly recreate BigNumber items in a JSON", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/sullof/bignumberify#readme", |
@@ -43,2 +43,5 @@ # bigNumberify | ||
**0.0.3** | ||
- Ignore object that look like a BigNumber but they are not | ||
**0.0.2** | ||
@@ -45,0 +48,0 @@ - No real change. Just a better README |
@@ -53,2 +53,21 @@ const { assert } = require("chai"); | ||
}); | ||
it("should skip not-real BigNumber in the JSON", async function () { | ||
let jsonStr = JSON.stringify(obj); | ||
let bad = JSON.parse(jsonStr); | ||
bad.e[0] = { | ||
type: "BigNumber", | ||
hex: "some wrong stuff" | ||
} | ||
let good = bigNumberify(bad); | ||
assert.isTrue(ethers.BigNumber.isBigNumber(good.h)); | ||
assert.equal(good.b.c.toString(), "10"); | ||
assert.equal(good.e[0].hex, "some wrong stuff"); | ||
assert.equal(good.e[1].f.toString(), "30"); | ||
assert.equal(good.e[1].g[5].toString(), "40"); | ||
assert.equal(good.h.toString(), "50"); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13450
104
59