src/encoding.ts
27 lines and 9 functions in DrDustinEdwards/capsid, at commit daa875b on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| bytesToHex | 3 to 6 | 2 | 100% | OkCRAP 2 | No data: mutation testing has not run on this repo yet |
| <anonymous:5> | 5 to 5 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| binaryFromBytes | 8 to 12 | 2 | 100% | OkCRAP 2 | No data: mutation testing has not run on this repo yet |
| b64urlFromBytes | 14 to 16 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| b64urlEncode | 18 to 20 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| b64urlDecode | 22 to 24 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| base64Encode | 27 to 29 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| base64Decode | 32 to 34 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| <anonymous:33> | 33 to 33 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
Imports
It imports no other module of this repo. Imported by src/access-login.ts, src/agents-schema.ts, src/auth.ts, src/bench-run-key.ts, src/bench.ts, src/controls-token.ts, src/github/client.ts, src/github/contents.ts, src/github/search.ts, src/jobs-schema.ts, src/maintenance-releases.ts, src/namespace-delete-token.ts, src/operator-key.ts, src/portal-auth.ts, src/resources.ts, src/routes.ts, src/shared-code.ts, src/site-key.ts, src/skills-refresh.ts.
Source
import { base64url } from "jose";
export function bytesToHex(bytes: ArrayBuffer | Uint8Array): string {
const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
return [...view].map((b) => b.toString(16).padStart(2, "0")).join("");
}
function binaryFromBytes(bytes: Uint8Array): string {
let binary = "";
for (const b of bytes) binary += String.fromCharCode(b);
return binary;
}
export function b64urlFromBytes(bytes: Uint8Array): string {
return base64url.encode(bytes);
}
export function b64urlEncode(text: string): string {
return b64urlFromBytes(new TextEncoder().encode(text));
}
export function b64urlDecode(encoded: string): string {
return new TextDecoder().decode(base64url.decode(encoded));
}
// Plain base64, not url-safe: GitHub's contents API encoding.
export function base64Encode(text: string): string {
return btoa(binaryFromBytes(new TextEncoder().encode(text)));
}
// GitHub wraps base64 across lines; atob rejects the whitespace.
export function base64Decode(b64: string): string {
return new TextDecoder().decode(Uint8Array.from(atob(b64.replace(/\s+/g, "")), (c) => c.charCodeAt(0)));
}