Ensure encode throws an error if receiving anything else than a integer

This commit is contained in:
2012-04-19 23:09:10 +01:00
parent 04918a627c
commit 0dbaf8676d
2 changed files with 8 additions and 2 deletions

View File

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