Skip to content

Commit

Permalink
Throw exception when encode is not passed a Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and dcousens committed Oct 4, 2018
1 parent 346f0d5 commit 6cbf08a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function base (ALPHABET) {
}

function encode (source) {
if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')

if (source.length === 0) return ''

var digits = [0]
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ tape.test('decode should return Buffer', function (t) {

t.end()
})

tape.test('encode throws on string', function (t) {
var base = bases.base58

t.throws(function () {
base.encode('a')
}, new RegExp('^TypeError: Expected Buffer$'))
t.end()
})

0 comments on commit 6cbf08a

Please sign in to comment.