utilities library
Small utilities with no platform dependency: cooperative cancellation, one
SHA-256, slugs, text decoding that keeps the encoding and BOM, globs and
.gitignore matching, protected-value copying with auto-clear, a bounded
output transcript, and YAML
writing — canonical emission, single-key
emission in hand-edited files' style, and surgical edits of existing text.
Reaches no dart:io and no HTTP client, so a web-linkable package can take
it without the rest of tom_basics (whose barrel reaches http).
Classes
- TomCancellationSource
- The write side of a cancellation.
- TomCancellationToken
- The read side of a cancellation.
- TomClipboardPort
- The platform clipboard as the protected-copy service needs it.
- TomClipboardReceipt
- What a binding placed: enough to recognise it later.
- TomDecodedText
- A file's decoded text and the encoding it came from.
- TomGitignore
-
The rules of one
.gitignorefile, in the folder base (relative to the root,''for the root itself). - TomGitignoreSet
-
Several
.gitignorefiles, as git reads them together: each speaks for the paths under its own folder, and a later file's verdict overrides an earlier one's. Add the files root first, so a deeper file wins. - TomGlob
- A compiled glob.
- TomOutputLine
- One line of output.
- TomOutputRecorder
- Collects lines up to a bound and counts the rest.
- TomOutputTranscript
- A program's output, bounded.
- TomProtectedClipboard
- Copies protected values and clears them again.
- TomProtectedClipboardState
- What the clipboard service holds right now — what a countdown chip shows.
- TomProtectedCopy
- What TomProtectedClipboard.copy did.
- TomYamlConfigWriter
- The single sanctioned path for mutating YAML config text while preserving its on-disk layout.
Enums
- TomOutputStream
- Which stream a line came from.
- TomTextEncoding
- How a file's text is stored.
Functions
-
tomDecodeTextBytes(
List< int> bytes) → TomDecodedText -
Decodes
bytesas the file's own encoding: UTF-16 behind its mark, else UTF-8 (a UTF-8 mark noted and dropped from the text), else Latin-1. -
tomDeepSortKeys(
Object? value) → Object? -
Recursively re-orders every mapping in
valueby key. -
tomEmitCanonicalFragment(
Object? value) → String -
Emits
valueas a canonical fragment: rule 1 with every key sorted. -
tomEmitLiteralBlock(
String value, int keyIndent) → String? -
The canonical literal-block emission of
valueunder a key written atkeyIndentspaces: the text that followskey:— header and content lines — or null whenvaluehas no canonical block form and is emitted by rule 4 instead. -
tomEmitYamlDocument(
Object? value, {List< String> ? blockScalarPath}) → String -
Emits
value(a map or list) as a YAML document string. -
tomEncodeText(
String text, TomTextEncoding encoding) → Uint8List -
textasencoding's bytes, mark included. -
tomNewlineOf(
String text) → String - The newline a file uses: CRLF when most of its line breaks are CRLF.
-
tomOrderedMapping(
Map< Object?, Object?> mapping, List<String> known, {Map<String, Object? Function(Object?)> nested = const {}}) → Map<String, Object?> -
knownkeys first in their listed order, then the rest sorted by code point;nestedrewrites a named key's value. Keys that are not strings are dropped — a fragment's keys are strings, and a mapping that is not string-keyed has no canonical form to give. -
tomSha256Hex(
List< int> bytes) → String -
The lowercase hex SHA-256 of
bytes— 64 characters. -
tomSha256OfText(
String text) → String -
tomSha256Hex over the UTF-8 encoding of
text. -
tomShortId(
String uuid) → String -
The first 8 hex characters of a canonical UUID (
7f3c9e21-…→7f3c9e21). -
tomSlugify(
String text, {String fallback = 'section'}) → String -
Lowercase ASCII slug of
text: runs of anything buta-z0-9become one-, with none leading or trailing. An empty result becomesfallback. -
tomSortedById(
List< Object?> items, {String key = 'id'}) → List<Object?> -
itemsordered by the string underkey, code point order; an item without one keeps its relative position after every item that has one. -
tomSortedRemainder(
Iterable< String> all, List<String> known) → List<String> -
The keys of
allthatknowndoes not name, sorted by code point — the rule for an open key set. -
tomYamlEntry(
String key, Object? value, int indent, String nl) → String -
The text of
key: value, at columnindent, ending innl. -
tomYamlListItem(
Object? item, int indent, String nl) → String -
One
- itemof a block sequence whose dashes sit at columnindent. -
tomYamlScalar(
String value) → String -
valueas a one-line YAML scalar: plain when that reads back as the same string in YAML 1.1 and 1.2, double-quoted otherwise. -
tomYamlSchemaRefOf(
String text) → String? -
The schema
textnames in a# yaml-language-server: $schema=comment, or null when it names none. The reference is returned as written, to be resolved against the file's own folder. -
tomYamlToPlain(
Object? node) → Object? -
Converts a value
package:yamlproduced into plain Dart: everyYamlMapbecomes aMap<String, Object?>(keys by theirtoString), everyYamlListaList<Object?>, recursively; scalars pass through.
Typedefs
- TomTimerFactory = Timer Function(Duration delay, void callback())
- Arms a timer. A parameter so a test can run the clock itself.
Exceptions / Errors
- TomOperationCancelled
- Thrown by work that noticed its token was cancelled, naming what stopped.