\r
export class base32 {\r
/**\r
- * Converts a base32 string to a Uint8Array of bytes.\r
+ * Convert a base32 string to a Uint8Array of bytes.\r
*\r
* @param {string} base32 - String to convert\r
* @returns {Uint8Array} Byte array representation of the input string\r
}\r
\r
/**\r
- * Converts a base32 string to a hexadecimal string.\r
+ * Convert a base32 string to a hexadecimal string.\r
*\r
* @param {string} base32 - String to convert\r
* @returns {string} Hexadecimal representation of the input base32\r
}\r
\r
export class bytes {\r
+ static #decoder: TextDecoder = new TextDecoder()\r
+\r
/**\r
- * Writes zeroes to memory to erase bytes and then transfers the buffer to\r
+ * Write zeroes to memory to erase bytes and then transfers the buffer to\r
* render it inaccessible to any process.\r
*\r
* @param bytes - Buffer or bytes to erase\r
}\r
return byteArray\r
}\r
+\r
/**\r
- * Converts a Uint8Aarray of bytes to a base32 string.\r
+ * Convert a Uint8Aarray of bytes to a base32 string.\r
*\r
* @param {Uint8Array} bytes - Byte array to convert\r
* @returns {string} Base32 string representation of the input bytes\r
}\r
\r
/**\r
- * Sums an array of bytes to a decimal integer. If the result is larger than\r
+ * Sum an array of bytes to a decimal integer. If the result is larger than\r
* Number.MAX_SAFE_INTEGER, it will be returned as a bigint.\r
*\r
* @param {Uint8Array} bytes - Byte array to convert\r
}\r
\r
/**\r
- * Converts a Uint8Array of bytes to a hexadecimal string.\r
+ * Convert a Uint8Array of bytes to a hexadecimal string.\r
*\r
* @param {Uint8Array} bytes - Byte array to convert\r
* @returns {string} Hexadecimal string representation of the input bytes\r
}\r
\r
/**\r
- * Converts a Uint8Array of bytes to a UTF-8 text string.\r
+ * Convert a Uint8Array of bytes to a UTF-8 text string.\r
*\r
* @param {Uint8Array} bytes - Byte array to convert\r
* @returns {string} UTF-8 encoded text string\r
*/\r
static toUtf8 (bytes: Uint8Array<ArrayBuffer>): string {\r
- return new TextDecoder().decode(bytes)\r
+ return this.#decoder.decode(bytes)\r
}\r
}\r
\r
}\r
\r
export class utf8 {\r
+ static #encoder: TextEncoder = new TextEncoder()\r
+\r
/**\r
* Convert a UTF-8 text string to a Uint8Array of bytes.\r
*\r
* @returns {Uint8Array} Byte array representation of the input string\r
*/\r
static toBytes (utf8: string): Uint8Array<ArrayBuffer> {\r
- return new TextEncoder().encode(utf8) as Uint8Array<ArrayBuffer>\r
+ return this.#encoder.encode(utf8) as Uint8Array<ArrayBuffer>\r
}\r
\r
/**\r
}\r
\r
export default `\r
+ const ALPHABET = '${ALPHABET}'\r
const base32 = ${base32}\r
const bin = ${bin}\r
const bytes = ${bytes}\r