mirror of
https://github.com/jimeh/node-base58.git
synced 2026-02-18 23:26:40 +00:00
Ensure encode throws an error if receiving anything else than a integer
This commit is contained in:
@@ -4,7 +4,7 @@ class Base58Builder
|
||||
@base = @alphabet.length
|
||||
|
||||
encode: (num) ->
|
||||
throw new Error('Value passed is not a number.') if typeof num != 'number'
|
||||
throw new Error('Value passed is not an integer.') unless /^\d+$/.test num
|
||||
str = ''
|
||||
while num >= @base
|
||||
mod = num % @base
|
||||
|
||||
@@ -10,9 +10,15 @@ describe 'Base58', ->
|
||||
for str, num of examples
|
||||
Base58.encode(num).should.eql(str)
|
||||
|
||||
describe 'when passed a float', ->
|
||||
it 'throws an error', ->
|
||||
(-> Base58.encode(3.14)).should
|
||||
.throw('Value passed is not an integer.')
|
||||
|
||||
describe 'when passed a non-number value', ->
|
||||
it 'throws an error', ->
|
||||
(-> Base58.encode('hi')).should.throw('Value passed is not a number.')
|
||||
(-> Base58.encode('hi')).should
|
||||
.throw('Value passed is not an integer.')
|
||||
|
||||
describe '.decode', ->
|
||||
it 'decodes Base58 string to number', ->
|
||||
|
||||
Reference in New Issue
Block a user