Skip to content

Commit

Permalink
fix: hex1byte mod 256, narrow return type
Browse files Browse the repository at this point in the history
  • Loading branch information
hugojosefson committed Feb 6, 2024
1 parent b0eff92 commit adbb85a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ export function omit<T extends Partial<Record<K, unknown>>, K extends keyof T>(
return result as Omit<T, K>;
}

export function hex1byte(byte: number): string {
return byte.toString(16).padStart(2, "0");
type HexNibble =
| "0"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "a"
| "b"
| "c"
| "d"
| "e"
| "f";
export function hex1byte(byte: number): `${HexNibble}${HexNibble}` {
return (byte & 0xFF).toString(16).padStart(
2,
"0",
) as `${HexNibble}${HexNibble}`;
}

0 comments on commit adbb85a

Please sign in to comment.