diff --git a/src/index.js b/src/index.js index 11e1a13..3f4bcab 100644 --- a/src/index.js +++ b/src/index.js @@ -80,7 +80,7 @@ function base (ALPHABET) { var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up. var b256 = new Uint8Array(size) // Process the characters. - while (source[psz]) { + while (psz < source.length) { // Decode character var carry = BASE_MAP[source.charCodeAt(psz)] // Invalid character diff --git a/ts_src/index.ts b/ts_src/index.ts index 2e71501..8c91160 100644 --- a/ts_src/index.ts +++ b/ts_src/index.ts @@ -99,7 +99,7 @@ function base (ALPHABET: string): base.BaseConverter { const b256 = new Uint8Array(size) // Process the characters. - while (source[psz]) { + while (psz < source.length) { // Decode character let carry = BASE_MAP[source.charCodeAt(psz)]