humanSizefunctionfunction humanSize(bytes: number): stringA size in bytes as ls -h writes it: bytes below 1024, then K, M, G, T with one decimal where it is not whole.
How the verbs write what they find (commons anyfs-cli 0003-anyfs-cli-logical FR-005): sizes for a person, the mode of a name as ls -l writes it, a table with its columns aligned, and a tree with its branches drawn. Pure functions of their arguments, so the same facts are the same text everywhere.
import { humanSize, modeText } from "./format.ts";
humanSize(1536); // "1.5K"
modeText("file", 0o644); // "-rw-r--r--"humanSizefunctionfunction humanSize(bytes: number): stringA size in bytes as ls -h writes it: bytes below 1024, then K, M, G, T with one decimal where it is not whole.
modeTextfunctionfunction modeText(type: "dir" | "file", mode: number): stringThe nine permission characters of a mode, with the leading type character.
tablefunctionfunction table(rows: readonly (readonly string[])[]): stringA table: each row's cells padded to the width of the widest of their column, the last column left as it is.
TreeNodetypeno test imports ittype TreeNode = { readonly name: string; readonly children: readonly TreeNode[] };A node of a tree to draw.
drawTreefunctionfunction drawTree(root: TreeNode): readonly string[]The lines of a tree drawn with branches, its root first.
countedfunctionfunction counted(n: number, one: string, many?: string): string1 file or 2 files.