Skip to content

Commit

Permalink
Fix for Bug base62#57
Browse files Browse the repository at this point in the history
Fixes If the input string starts with 0 then that 0 is lost during encoding.
  • Loading branch information
tejzpr authored Jan 25, 2018
1 parent e3bdf6d commit 167a424
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base62.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ module.exports = (function (Base62) {
Base62.encode = function(integer){
if (integer === 0) {return '0';}
var s = '';
while (integer > 0) {
while (integer >= 0) {
s = Base62.characterSet[integer % 62] + s;
if (integer === 0)
{
break;
}
integer = Math.floor(integer/62);
}
return s;
Expand Down

0 comments on commit 167a424

Please sign in to comment.