From: Chris Duncan Date: Tue, 30 Jun 2026 22:05:35 +0000 (-0700) Subject: Delete unused conversion functions. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6fa42e70d83d52e3e8abde7d01abaef00460664a;p=libnemo.git Delete unused conversion functions. --- diff --git a/src/lib/convert/base32.ts b/src/lib/convert/base32.ts index f4bbc9e..0896f39 100644 --- a/src/lib/convert/base32.ts +++ b/src/lib/convert/base32.ts @@ -4,16 +4,6 @@ import { ALPHABET } from '../constants' export const base32 = Object.freeze({ - /** - * Convert a base32 string to an ArrayBuffer. - * - * @param {string} base32 - String to convert - * @returns {Uint8Array} Byte array representation of the input string - */ - toBuffer (base32: string): ArrayBuffer { - return this.toBytes(base32).buffer - }, - /** * Convert a base32 string to a Uint8Array of bytes. * diff --git a/src/lib/convert/bin.ts b/src/lib/convert/bin.ts deleted file mode 100644 index 6da5275..0000000 --- a/src/lib/convert/bin.ts +++ /dev/null @@ -1,27 +0,0 @@ -//! SPDX-FileCopyrightText: 2025 Chris Duncan -//! SPDX-License-Identifier: GPL-3.0-or-later - -export const bin = Object.freeze({ - /** - * Convert a binary string to a Uint8Array of bytes. - * - * @param {string} bin - String to convert - * @returns {Uint8Array} Byte array representation of the input string - */ - toBytes (bin: string, padding: number = 1): Uint8Array { - if (typeof bin !== 'string' || !/^[01]+$/i.test(bin)) { - throw new TypeError('Invalid string when converting bin to bytes', { cause: bin }) - } - if (typeof padding !== 'number' || padding < 1 || padding > 0xffffffff) { - throw new TypeError('Invalid padding when converting bin to bytes', { cause: padding }) - } - const pad = bin.length & 7 - if (pad) bin = bin.padStart(bin.length + 8 - pad, '0') - const byteLength = bin.length >> 3 - const diff = padding - byteLength - const offset = diff & ~(diff >> 31) - const bytes = new Uint8Array(byteLength + offset) - bytes.set(bin.match(/.{8}/g)?.map(b => parseInt(b, 2)) ?? [], offset) - return bytes - }, -}) diff --git a/src/lib/convert/bytes.ts b/src/lib/convert/bytes.ts index 9fd87e0..af27d45 100644 --- a/src/lib/convert/bytes.ts +++ b/src/lib/convert/bytes.ts @@ -49,16 +49,6 @@ export const bytes = Object.freeze({ return output }, - /** - * Convert a Uint8Array of bytes to a binary string. - * - * @param {Uint8Array} bytes - Byte array to convert - * @returns {string} Binary string representation of the input value - */ - toBin (bytes: Uint8Array): string { - return [...bytes].map(b => b.toString(2).padStart(8, '0')).join('') - }, - /** * 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. diff --git a/src/lib/convert/dec.ts b/src/lib/convert/dec.ts index b7e5bf3..575a929 100644 --- a/src/lib/convert/dec.ts +++ b/src/lib/convert/dec.ts @@ -2,26 +2,6 @@ //! SPDX-License-Identifier: GPL-3.0-or-later export const dec = Object.freeze({ - /** - * Convert a decimal integer to a binary string. - * - * @param {bigint|number|string} decimal - Integer to convert - * @param {number} [padding=0] - Minimum length of the resulting string padded as necessary with starting zeroes - * @returns {string} Binary string representation of the input decimal - */ - toBin (decimal: bigint | number | string, padding: number = 0): string { - if (typeof padding !== 'number') { - throw new TypeError('Invalid padding') - } - try { - return BigInt(decimal) - .toString(2) - .padStart(padding, '0') - } catch (err) { - throw new RangeError('Invalid decimal integer') - } - }, - /** * Convert a decimal integer to a Uint8Array of bytes. Fractional part is truncated. * diff --git a/src/lib/convert/index.ts b/src/lib/convert/index.ts index 0034c62..3803528 100644 --- a/src/lib/convert/index.ts +++ b/src/lib/convert/index.ts @@ -2,8 +2,8 @@ //! SPDX-License-Identifier: GPL-3.0-or-later export { base32 } from './base32' -export { bin } from './bin' export { bytes } from './bytes' export { dec } from './dec' export { hex } from './hex' export { utf8 } from './utf8' +