IF Commons GitHub

logical/format

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-cli-logical FR-005

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--"

Source: commons/anyfs-cli/src/logical/format.ts

5 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

humanSizefunction
function humanSize(bytes: number): string

A size in bytes as ls -h writes it: bytes below 1024, then K, M, G, T with one decimal where it is not whole.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

modeTextfunction
function modeText(type: "dir" | "file", mode: number): string

The nine permission characters of a mode, with the leading type character.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

tablefunction
function table(rows: readonly (readonly string[])[]): string

A table: each row's cells padded to the width of the widest of their column, the last column left as it is.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

TreeNodetypeno test imports it
type TreeNode = { readonly name: string; readonly children: readonly TreeNode[] };

A node of a tree to draw.

drawTreefunction
function drawTree(root: TreeNode): readonly string[]

The lines of a tree drawn with branches, its root first.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

countedfunction
function counted(n: number, one: string, many?: string): string

1 file or 2 files.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.