Browse Source

more convenient Base58 constructor

patch-2
Ryan X. Charles 10 years ago
parent
commit
40ea68a3ff
  1. 9
      lib/base58.js
  2. 5
      test/base58.js

9
lib/base58.js

@ -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) {

5
test/base58.js

@ -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…
Cancel
Save