]> git.codecow.com Git - libnemo.git/commitdiff
Use type alias for byte arrays.
authorChris Duncan <chris@codecow.com>
Thu, 2 Jul 2026 15:41:30 +0000 (08:41 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 2 Jul 2026 15:41:30 +0000 (08:41 -0700)
src/lib/convert/bytes.ts

index 52e2d95f376f566afe748702c11f6abbdf54e3aa..955543c16f4f751d059ca3f7290b76d8a95314ed 100644 (file)
@@ -23,10 +23,10 @@ export const bytes = Object.freeze({
        /**
         * Convert a Uint8Aarray of bytes to a base32 string.
         *
-        * @param {Uint8Array} bytes - Byte array to convert
+        * @param {Bytes} bytes - Byte array to convert
         * @returns {string} Base32 string representation of the input bytes
         */
-       toBase32 (bytes: ArrayBuffer | Uint8Array): string {
+       toBase32 (bytes: ArrayBuffer | Bytes): string {
                if (bytes instanceof ArrayBuffer) bytes = new Uint8Array(bytes)
                const leftover = (bytes.length * 8) % 5
                const offset = leftover === 0
@@ -53,10 +53,10 @@ export const bytes = Object.freeze({
         * Sum an array of bytes to a decimal integer. If the result is larger than
         * Number.MAX_SAFE_INTEGER, it will be returned as a bigint.
         *
-        * @param {Uint8Array} bytes - Byte array to convert
+        * @param {Bytes} bytes - Byte array to convert
         * @returns {bigint|number} Decimal sum of the literal byte values
         */
-       toDec (bytes: Uint8Array): bigint | number {
+       toDec (bytes: Bytes): bigint | number {
                let decimal = 0n
                for (let i = bytes.byteLength; i > 0; i--) {
                        decimal += BigInt(bytes[i - 1]) << (BigInt(bytes.byteLength - i) * 8n)
@@ -71,10 +71,10 @@ export const bytes = Object.freeze({
        /**
         * Convert a Uint8Array of bytes to a hexadecimal string.
         *
-        * @param {Uint8Array} bytes - Byte array to convert
+        * @param {Bytes} bytes - Byte array to convert
         * @returns {string} Hexadecimal string representation of the input bytes
         */
-       toHex (bytes: ArrayBuffer | Uint8Array): string {
+       toHex (bytes: ArrayBuffer | Bytes): string {
                if (bytes instanceof ArrayBuffer) bytes = new Uint8Array(bytes)
                let hex: string = ''
                for (const byte of bytes) {
@@ -86,7 +86,7 @@ export const bytes = Object.freeze({
        /**
         * Convert a Uint8Array of bytes to a UTF-8 text string.
         *
-        * @param {Uint8Array} bytes - Byte array to convert
+        * @param {Bytes} bytes - Byte array to convert
         * @returns {string} UTF-8 encoded text string
         */
        toUtf8 (bytes: Bytes): string {