]> git.codecow.com Git - libnemo.git/commitdiff
Delete unused conversion functions.
authorChris Duncan <chris@codecow.com>
Tue, 30 Jun 2026 22:05:35 +0000 (15:05 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 30 Jun 2026 22:05:35 +0000 (15:05 -0700)
src/lib/convert/base32.ts
src/lib/convert/bin.ts [deleted file]
src/lib/convert/bytes.ts
src/lib/convert/dec.ts
src/lib/convert/index.ts

index f4bbc9ec22e3aee102734f38df2be674834649da..0896f39ef15722baa77a31aafaac6a35c7367ccd 100644 (file)
@@ -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 (file)
index 6da5275..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
-//! 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<ArrayBuffer> {
-               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
-       },
-})
index 9fd87e038030d0b53c22e40375f3696ef755ebb8..af27d45cc44b14e215f0b05ac8e7c578c9017bd2 100644 (file)
@@ -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<ArrayBuffer>): 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.
index b7e5bf3f2aebc3a82bb3fc61bb57273d410528ce..575a929eb69e1848dc7ef1ec59425eca9a124848 100644 (file)
@@ -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.
         *
index 0034c6212604e13249d6992e73369f0e16196eb7..3803528e3e683a8ca4938ed254a23bc07b7f971c 100644 (file)
@@ -2,8 +2,8 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later\r
 \r
 export { base32 } from './base32'\r
-export { bin } from './bin'\r
 export { bytes } from './bytes'\r
 export { dec } from './dec'\r
 export { hex } from './hex'\r
 export { utf8 } from './utf8'\r
+\r