diff --git a/.github/workflows/prv.yml b/.github/workflows/prv.yml index 87dd9c2..52e1281 100644 --- a/.github/workflows/prv.yml +++ b/.github/workflows/prv.yml @@ -18,5 +18,6 @@ jobs: - uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21 - run: nix run github:nicknovitski/nix-develop .#workflow + - run: biome ci - run: ./node_modules/.bin/tsc --build tsconfig.json - run: node --test diff --git a/base58/index.test.js b/base58/index.test.js index 7473af8..7a7aaae 100644 --- a/base58/index.test.js +++ b/base58/index.test.js @@ -1,5 +1,5 @@ -import { test } from "node:test"; import assert from "node:assert/strict"; +import { test } from "node:test"; import * as fc from "fast-check"; import { decode, encode } from "./index.js"; @@ -39,7 +39,7 @@ const hexTestVectors = [ ], ]; -test("base58: encode", (t) => { +test("base58: encode", () => { for (const [string, expected] of stringTestVectors) { const input = new TextEncoder().encode(string); assert.equal(encode(input), expected, string); @@ -53,7 +53,7 @@ test("base58: encode", (t) => { } }); -test("base58: decode", (t) => { +test("base58: decode", () => { for (const [expected, input] of stringTestVectors) { const string = new TextDecoder().decode(decode(input)); assert.equal(string, expected, input); @@ -67,7 +67,7 @@ test("base58: decode", (t) => { } }); -test("base58: roundtrip (decode . encode === id)", (t) => { +test("base58: roundtrip (decode . encode === id)", () => { function roundtrip(bs) { assert.deepEqual(new Uint8Array(bs), decode(encode(bs))); } @@ -80,7 +80,7 @@ test("base58: roundtrip (decode . encode === id)", (t) => { fc.assert(fc.property(fc.array(fc.constant(0xff)), roundtrip)); }); -test("base58: roundtrip (encode . decode === id)", (t) => { +test("base58: roundtrip (encode . decode === id)", () => { const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; const arbInput = fc.string({ unit: fc.constantFrom(...alphabet.split("")) }); diff --git a/base58/index.ts b/base58/index.ts index 0a1914c..8093ce2 100644 --- a/base58/index.ts +++ b/base58/index.ts @@ -1,6 +1,6 @@ const bytesToHex = (() => { const s = Array.from({ length: 256 }).map((_, i) => - i.toString(16).padStart(2, "0") + i.toString(16).padStart(2, "0"), ); return (uint8a: Uint8Array) => [...uint8a].map((o) => s[o]).join(""); })(); @@ -13,7 +13,7 @@ export function encode(input: Uint8Array): string { } // Uint8Array -> BigInt (Big Endian) - let x = BigInt("0x" + bytesToHex(input)); + let x = BigInt(`0x${bytesToHex(input)}`); const output = []; while (x > 0n) { @@ -40,7 +40,7 @@ export function decode(output: string): Uint8Array { const value = letters.indexOf(char); if (value === undefined) { throw new Error( - `base58.decode received invalid input. Character '${char}' is not in the base58 alphabet.` + `base58.decode received invalid input. Character '${char}' is not in the base58 alphabet.`, ); } for (let j = 0; j < bytes.length; j++) { diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..12a54f1 --- /dev/null +++ b/biome.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json", + + "files": { + "includes": ["**", "!**/.direnv", "!**/node_modules"] + }, + + "formatter": { + "indentStyle": "space" + } +} diff --git a/flake.nix b/flake.nix index 0ebed5c..0834eb8 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ buildInputs = [ pkgs.nodejs pkgs.pnpm + pkgs.biome ]; }; @@ -23,6 +24,7 @@ buildInputs = [ pkgs.nodejs pkgs.pnpm + pkgs.biome ]; shellHook = ''