From 421ebfab649b7e614119a4bc7e463b07ecf0a819 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 21 Nov 2024 10:25:41 +0000 Subject: [PATCH] utils.bytesToHex: small change --- src/utils.ts | 6 +++--- test/utils.test.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index e584db6..ba76713 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -68,11 +68,11 @@ export function bytesToHex(bytes: Uint8Array): string { } // We use optimized technique to convert hex string to byte array -const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const; +const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const; function asciiToBase16(ch: number): number | undefined { if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48 - if (ch >= asciis._A && ch <= asciis._F) return ch - (asciis._A - 10); // 'B' => 66-(65-10) - if (ch >= asciis._a && ch <= asciis._f) return ch - (asciis._a - 10); // 'b' => 98-(97-10) + if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10) + if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10) return; } diff --git a/test/utils.test.js b/test/utils.test.js index d5509f8..614983f 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -3,7 +3,15 @@ const fc = require('fast-check'); const { describe, should } = require('micro-should'); const { optional, integer, gen } = require('./generator'); const { TYPE_TEST } = require('./utils'); -const { byteSwap, byteSwapIfBE, byteSwap32, isLE, bytesToHex, concatBytes, hexToBytes } = require('../utils'); +const { + byteSwap, + byteSwapIfBE, + byteSwap32, + isLE, + bytesToHex, + concatBytes, + hexToBytes, +} = require('../utils'); describe('utils', () => { const staticHexVectors = [