mirror of
https://github.com/jimeh/node-base58.git
synced 2026-02-19 07:36:40 +00:00
Enable string value to be passed to Base58.encode()
This commit is contained in:
@@ -5,6 +5,7 @@ class Base58Builder
|
|||||||
|
|
||||||
encode: (num) ->
|
encode: (num) ->
|
||||||
throw new Error('Value passed is not an integer.') unless /^\d+$/.test num
|
throw new Error('Value passed is not an integer.') unless /^\d+$/.test num
|
||||||
|
num = parseInt(num) unless typeof num == 'number'
|
||||||
str = ''
|
str = ''
|
||||||
while num >= @base
|
while num >= @base
|
||||||
mod = num % @base
|
mod = num % @base
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ describe 'Base58', ->
|
|||||||
for str, num of examples
|
for str, num of examples
|
||||||
Base58.encode(num).should.eql(str)
|
Base58.encode(num).should.eql(str)
|
||||||
|
|
||||||
|
describe 'when passed a string only containing numbers', ->
|
||||||
|
it 'encodes string after first converting it to an integer', ->
|
||||||
|
for str, num of examples
|
||||||
|
Base58.encode(num.toString()).should.eql(str)
|
||||||
|
|
||||||
describe 'when passed a float', ->
|
describe 'when passed a float', ->
|
||||||
it 'throws an error', ->
|
it 'throws an error', ->
|
||||||
(-> Base58.encode(3.14)).should
|
(-> Base58.encode(3.14)).should
|
||||||
|
|||||||
Reference in New Issue
Block a user