more convenient Base58 constructor
This commit is contained in:
parent
ac85264a28
commit
40ea68a3ff
|
@ -3,8 +3,15 @@ var bs58 = require('bs58');
|
|||
var Base58 = function Base58(obj) {
|
||||
if (!(this instanceof Base58))
|
||||
return new Base58(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);
|
||||
}
|
||||
};
|
||||
|
||||
Base58.prototype.set = function(obj) {
|
||||
|
|
|
@ -15,6 +15,11 @@ describe('Base58', function() {
|
|||
should.exist(b58);
|
||||
});
|
||||
|
||||
it('should allow this handy syntax', function() {
|
||||
Base58(buf).toString().should.equal(enc);
|
||||
Base58(enc).toBuffer().toString('hex').should.equal(buf.toString('hex'))
|
||||
});
|
||||
|
||||
describe('#set', function() {
|
||||
|
||||
it('should set a blank buffer', function() {
|
||||
|
|
Loading…
Reference in New Issue