Comparing version 1.0.0 to 1.0.1
@@ -13,3 +13,3 @@ const baseSize = 45; | ||
const result = new Array(resultSize); | ||
var resultIndex = 0; | ||
let resultIndex = 0; | ||
const wholeChunkLength = wholeChunkCount * chunkSize; | ||
@@ -19,4 +19,4 @@ for (let i = 0; i < wholeChunkLength;) { | ||
result[resultIndex++] = encoding[value % baseSize]; | ||
result[resultIndex++] = encoding[Math.trunc(value / baseSize) % baseSize]; | ||
result[resultIndex++] = encoding[Math.trunc(value / baseSizeSquared) % baseSize]; | ||
result[resultIndex++] = encoding[(value / baseSize | 0) % baseSize]; | ||
result[resultIndex++] = encoding[(value / baseSizeSquared | 0) % baseSize]; | ||
} | ||
@@ -28,3 +28,3 @@ if (byteArrayArg.length % chunkSize) { | ||
? encoding[0] | ||
: encoding[Math.trunc(byteArrayArg[byteArrayArg.length - 1] / baseSize) % baseSize]; | ||
: encoding[(byteArrayArg[byteArrayArg.length - 1] / baseSize | 0) % baseSize]; | ||
} | ||
@@ -37,3 +37,3 @@ return result.join(""); | ||
return new Uint8Array; | ||
var remainderSize = utf8StringArg.length % encodedChunkSize; | ||
const remainderSize = utf8StringArg.length % encodedChunkSize; | ||
if (remainderSize === 1) | ||
@@ -48,3 +48,3 @@ throw new Error("utf8StringArg has incorrect length."); | ||
} | ||
const wholeChunkCount = Math.trunc(buffer.length / encodedChunkSize); | ||
const wholeChunkCount = (buffer.length / encodedChunkSize | 0); | ||
const result = new Uint8Array(wholeChunkCount * chunkSize + (remainderSize === chunkSize ? 1 : 0)); | ||
@@ -55,8 +55,7 @@ let resultIndex = 0; | ||
const val = buffer[i++] + baseSize * buffer[i++] + baseSizeSquared * buffer[i++]; | ||
result[resultIndex++] = Math.trunc(val / byteSize); //result is always in the range 0-255 - % ByteSize omitted. | ||
result[resultIndex++] = (val / byteSize | 0); //result is always in the range 0-255 - % ByteSize omitted. | ||
result[resultIndex++] = val % byteSize; | ||
} | ||
if (remainderSize === 0) | ||
return result; | ||
result[result.length - 1] = buffer[buffer.length - 2] + baseSize * buffer[buffer.length - 1]; //result is always in the range 0-255 - % ByteSize omitted. | ||
if (remainderSize) | ||
result[result.length - 1] = buffer[buffer.length - 2] + baseSize * buffer[buffer.length - 1]; //result is always in the range 0-255 - % ByteSize omitted. | ||
return result; | ||
@@ -63,0 +62,0 @@ } |
@@ -7,3 +7,3 @@ { | ||
"types": "./lib/base45.d.ts", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/ehn-digital-green-development/base45-js", | ||
@@ -10,0 +10,0 @@ "author": { |
@@ -10,7 +10,8 @@ Simple typescript base45 (charset of Qr codes, alphanumeric mode) encoder/decoder. | ||
const e = b45.encode(Buffer.from('Hello!','utf-8')) | ||
const buffer : Uint8Array = new TextEncoder().encode('Hello!') | ||
const e : string = b45.encode(buffer); | ||
console.log(e); // Will output %69 VD92EX0" | ||
const d = b45.decode('%69 VD92EX0') | ||
console.log(d); // will output '[72, 101, 108, 108, 111, 33, 33]' | ||
console.log(d); // will output 'Uint8Array(7) [72, 101, 108, 108, 111, 33, 33]' | ||
@@ -17,0 +18,0 @@ const d = b45.decodeToUtf8String('%69 VD92EX0') |
@@ -16,3 +16,3 @@ const baseSize = 45; | ||
const result = new Array(resultSize); | ||
var resultIndex = 0; | ||
let resultIndex = 0; | ||
const wholeChunkLength = wholeChunkCount * chunkSize; | ||
@@ -22,4 +22,4 @@ for (let i = 0; i < wholeChunkLength;) { | ||
result[resultIndex++] = encoding[value % baseSize]; | ||
result[resultIndex++] = encoding[Math.trunc(value / baseSize) % baseSize]; | ||
result[resultIndex++] = encoding[Math.trunc(value / baseSizeSquared) % baseSize]; | ||
result[resultIndex++] = encoding[(value / baseSize | 0) % baseSize]; | ||
result[resultIndex++] = encoding[(value / baseSizeSquared | 0) % baseSize]; | ||
} | ||
@@ -32,5 +32,5 @@ | ||
? encoding[0] | ||
: encoding[Math.trunc(byteArrayArg[byteArrayArg.length - 1] / baseSize) % baseSize]; | ||
: encoding[(byteArrayArg[byteArrayArg.length - 1] / baseSize | 0) % baseSize]; | ||
} | ||
return result.join(""); | ||
@@ -42,3 +42,3 @@ }; | ||
var remainderSize = utf8StringArg.length % encodedChunkSize; | ||
const remainderSize = utf8StringArg.length % encodedChunkSize; | ||
if (remainderSize === 1) | ||
@@ -55,3 +55,3 @@ throw new Error("utf8StringArg has incorrect length."); | ||
const wholeChunkCount = Math.trunc(buffer.length / encodedChunkSize); | ||
const wholeChunkCount = (buffer.length / encodedChunkSize | 0); | ||
const result = new Uint8Array(wholeChunkCount * chunkSize + (remainderSize === chunkSize ? 1 : 0)); | ||
@@ -62,10 +62,9 @@ let resultIndex = 0; | ||
const val = buffer[i++] + baseSize * buffer[i++] + baseSizeSquared * buffer[i++]; | ||
result[resultIndex++] = Math.trunc(val / byteSize); //result is always in the range 0-255 - % ByteSize omitted. | ||
result[resultIndex++] = (val / byteSize | 0); //result is always in the range 0-255 - % ByteSize omitted. | ||
result[resultIndex++] = val % byteSize; | ||
} | ||
if (remainderSize === 0) | ||
return result; | ||
if (remainderSize) | ||
result[result.length - 1] = buffer[buffer.length - 2] + baseSize * buffer[buffer.length - 1]; //result is always in the range 0-255 - % ByteSize omitted. | ||
result[result.length - 1] = buffer[buffer.length - 2] + baseSize * buffer[buffer.length - 1]; //result is always in the range 0-255 - % ByteSize omitted. | ||
return result; | ||
@@ -72,0 +71,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
30186
10
20
184