]> git.codecow.com Git - libnemo.git/commitdiff
Check data type of input to convert functions.
authorChris Duncan <chris@zoso.dev>
Wed, 9 Jul 2025 20:31:41 +0000 (13:31 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 9 Jul 2025 20:31:41 +0000 (13:31 -0700)
src/lib/convert.ts

index a1d5733f1aa79edf8b6dee33aa6e978b293d28a4..abea692690039f8cda5989dae4ed4aee825e051d 100644 (file)
@@ -199,6 +199,9 @@ export class dec {
        * @returns {Uint8Array} Byte array representation of the input decimal\r
        */\r
        static toBytes (decimal: bigint | number | string, padding: number = 0): Uint8Array {\r
+               if (decimal == null) {\r
+                       throw new TypeError(`Failed to convert '${decimal}' from decimal to bytes`)\r
+               }\r
                if (typeof padding !== 'number') {\r
                        throw new TypeError('Invalid padding')\r
                }\r
@@ -222,6 +225,9 @@ export class dec {
        * @returns {string} Hexadecimal string representation of the input decimal\r
        */\r
        static toHex (decimal: bigint | number | string, padding: number = 0): string {\r
+               if (decimal == null) {\r
+                       throw new TypeError(`Failed to convert '${decimal}' from decimal to hex`)\r
+               }\r
                if (typeof padding !== 'number') {\r
                        throw new TypeError('Invalid padding')\r
                }\r