IF Commons GitHub

logical/grep

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

The text search of grep, and the name and size tests of find (commons anyfs-cli 0003-anyfs-cli-logical FR-007): a literal text, never a pattern a caller wrote (so a search cannot be made to run for ever), with a case option; a wildcard of * and ? for names; and a size test written as +N, -N or N with the units K, M and G. Pure functions over text and numbers.

import { matchingLines, wildcard } from "./grep.ts";
matchingLines("a\nHello\n", "hello", true); // [{ line: 2, text: "Hello" }]
wildcard("*.ts", "a.ts"); // true

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

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

Hittypeno test imports it
type Hit = { readonly line: number; readonly text: string };

A line that holds the text.

looksLikeTextfunction
function looksLikeText(bytes: Uint8Array<ArrayBufferLike>): boolean

Whether bytes look like text: no NUL in the first 8 KiB.

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

matchingLinesfunction
function matchingLines(text: string, needle: string, ignoreCase: boolean): readonly Hit[]

The lines of a text that hold needle, with their numbers from 1.

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

wildcardfunction
function wildcard(pattern: string, name: string): boolean

Whether a name matches a wildcard: * is any run of characters but a slash, ? is one.

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

SizeTesttypeno test imports it
type SizeTest = { readonly kind: "over" | "under" | "equal"; readonly bytes: number };

A test of a size in bytes.

parseSizeTestfunction
function parseSizeTest(text: string): Result<SizeTest, string>

A size test from text: +10K is over ten KiB, -1M under a MiB, 512 exactly that many bytes.

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

sizePassesfunction
function sizePasses(test: SizeTest, size: number): boolean

Whether a size passes a test.

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

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