more convenient constructor
...allow inputing strings or buffers in the constructor.
This commit is contained in:
parent
40ea68a3ff
commit
78ef76eb2f
|
@ -4,8 +4,15 @@ var sha256sha256 = require('./hash').sha256sha256;
|
|||
var Base58Check = function Base58Check(obj) {
|
||||
if (!(this instanceof Base58Check))
|
||||
return new Base58Check(obj);
|
||||
if (obj)
|
||||
if (Buffer.isBuffer(obj)) {
|
||||
var buf = obj;
|
||||
this.fromBuffer(buf);
|
||||
} else if (typeof obj === 'string') {
|
||||
var str = obj;
|
||||
this.fromString(str);
|
||||
} else if (obj) {
|
||||
this.set(obj);
|
||||
}
|
||||
};
|
||||
|
||||
Base58Check.prototype.set = function(obj) {
|
||||
|
|
|
@ -16,6 +16,11 @@ describe('Base58Check', function() {
|
|||
should.exist(b58);
|
||||
});
|
||||
|
||||
it('should allow this handy syntax', function() {
|
||||
Base58Check(buf).toString().should.equal(enc);
|
||||
Base58Check(enc).toBuffer().toString('hex').should.equal(buf.toString('hex'));
|
||||
});
|
||||
|
||||
describe('#set', function() {
|
||||
|
||||
it('should set a buf', function() {
|
||||
|
|
Loading…
Reference in New Issue