Mirror of https://github.com/wereHamster/bytestring
fork

Configure Feed

Select the types of activity you want to include in your feed.

Biome (#171)

authored by caurea.org and committed by

GitHub c382cd04 6b7a59a0

+22 -8
+1
.github/workflows/prv.yml
··· 18 18 - uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21 19 19 - run: nix run github:nicknovitski/nix-develop .#workflow 20 20 21 + - run: biome ci 21 22 - run: ./node_modules/.bin/tsc --build tsconfig.json 22 23 - run: node --test
+5 -5
base58/index.test.js
··· 1 - import { test } from "node:test"; 2 1 import assert from "node:assert/strict"; 2 + import { test } from "node:test"; 3 3 import * as fc from "fast-check"; 4 4 import { decode, encode } from "./index.js"; 5 5 ··· 39 39 ], 40 40 ]; 41 41 42 - test("base58: encode", (t) => { 42 + test("base58: encode", () => { 43 43 for (const [string, expected] of stringTestVectors) { 44 44 const input = new TextEncoder().encode(string); 45 45 assert.equal(encode(input), expected, string); ··· 53 53 } 54 54 }); 55 55 56 - test("base58: decode", (t) => { 56 + test("base58: decode", () => { 57 57 for (const [expected, input] of stringTestVectors) { 58 58 const string = new TextDecoder().decode(decode(input)); 59 59 assert.equal(string, expected, input); ··· 67 67 } 68 68 }); 69 69 70 - test("base58: roundtrip (decode . encode === id)", (t) => { 70 + test("base58: roundtrip (decode . encode === id)", () => { 71 71 function roundtrip(bs) { 72 72 assert.deepEqual(new Uint8Array(bs), decode(encode(bs))); 73 73 } ··· 80 80 fc.assert(fc.property(fc.array(fc.constant(0xff)), roundtrip)); 81 81 }); 82 82 83 - test("base58: roundtrip (encode . decode === id)", (t) => { 83 + test("base58: roundtrip (encode . decode === id)", () => { 84 84 const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 85 85 const arbInput = fc.string({ unit: fc.constantFrom(...alphabet.split("")) }); 86 86
+3 -3
base58/index.ts
··· 1 1 const bytesToHex = (() => { 2 2 const s = Array.from({ length: 256 }).map((_, i) => 3 - i.toString(16).padStart(2, "0") 3 + i.toString(16).padStart(2, "0"), 4 4 ); 5 5 return (uint8a: Uint8Array) => [...uint8a].map((o) => s[o]).join(""); 6 6 })(); ··· 13 13 } 14 14 15 15 // Uint8Array -> BigInt (Big Endian) 16 - let x = BigInt("0x" + bytesToHex(input)); 16 + let x = BigInt(`0x${bytesToHex(input)}`); 17 17 18 18 const output = []; 19 19 while (x > 0n) { ··· 40 40 const value = letters.indexOf(char); 41 41 if (value === undefined) { 42 42 throw new Error( 43 - `base58.decode received invalid input. Character '${char}' is not in the base58 alphabet.` 43 + `base58.decode received invalid input. Character '${char}' is not in the base58 alphabet.`, 44 44 ); 45 45 } 46 46 for (let j = 0; j < bytes.length; j++) {
+11
biome.json
··· 1 + { 2 + "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json", 3 + 4 + "files": { 5 + "includes": ["**", "!**/.direnv", "!**/node_modules"] 6 + }, 7 + 8 + "formatter": { 9 + "indentStyle": "space" 10 + } 11 + }
+2
flake.nix
··· 16 16 buildInputs = [ 17 17 pkgs.nodejs 18 18 pkgs.pnpm 19 + pkgs.biome 19 20 ]; 20 21 }; 21 22 ··· 23 24 buildInputs = [ 24 25 pkgs.nodejs 25 26 pkgs.pnpm 27 + pkgs.biome 26 28 ]; 27 29 28 30 shellHook = ''