Address.isAddress
This commit is contained in:
parent
26da0b1d2f
commit
33432c6735
|
@ -37,13 +37,24 @@ function Address(opts) {
|
||||||
objectAssign(this, opts);
|
objectAssign(this, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if given object is an Address instance. NOTE: Implementation is
|
||||||
|
* just simple `instanceof` but it improves readability and consistent
|
||||||
|
* with `isArray`, `isBuffer`, etc.
|
||||||
|
* @param {Object} obj - Given object
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
Address.isAddress = function(obj) {
|
||||||
|
return obj instanceof Address;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse Bitmessage address into address object.
|
* Parse Bitmessage address into address object.
|
||||||
* @param {String} str - Address string (with or without `BM-` prefix)
|
* @param {String} str - Address string (with or without `BM-` prefix)
|
||||||
* @return {Address} Decoded address object.
|
* @return {Address} Decoded address object.
|
||||||
*/
|
*/
|
||||||
Address.decode = function(str) {
|
Address.decode = function(str) {
|
||||||
if (str instanceof Address) {
|
if (Address.isAddress(str)) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
test.js
7
test.js
|
@ -606,6 +606,13 @@ describe("High-level classes", function() {
|
||||||
expect(addr.getRipe({short: true}).toString("hex")).to.equal("69617ddb1946dc327cadffcf33889fed587fc1e7");
|
expect(addr.getRipe({short: true}).toString("hex")).to.equal("69617ddb1946dc327cadffcf33889fed587fc1e7");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should implement isAddress method", function() {
|
||||||
|
var addr = Address();
|
||||||
|
expect(Address.isAddress(addr)).to.be.true;
|
||||||
|
expect(Address.isAddress(null)).to.be.false;
|
||||||
|
expect(Address.isAddress({})).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
// FIXME(Kagami): Don't run it in browser currently because it's
|
// FIXME(Kagami): Don't run it in browser currently because it's
|
||||||
// very slow. This need to be fixed.
|
// very slow. This need to be fixed.
|
||||||
if (allTests && typeof window === "undefined") {
|
if (allTests && typeof window === "undefined") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user