Getting started
utils is a library of small TypeScript functions for the Angular UIs that show live values: gauges and synoptics. It has no dependency and runs in any browser. It is never published: its code is copied into the projects.
Two ways to copy it
- Copy a folder:
pnpm transfer src/mathpacks a theme, with the themes it imports, into one text file (see Transfer folders). - Copy a file: every export lives in its own file. Its page lists the other files it needs, under Source, and shows the code with a copy button.
Find a function
- Press Ctrl K (or ⌘ K) and type a name or a need: decimals, rotate, anchor, gauge.
- Or browse the API by category.
Conventions
- Angles are in degrees, 0° up and clockwise, everywhere.
- Defaults in the signature for the settings:
formatNumber(value),svgRotateBy(15). Nonull: passvalue ?? undefinedto get a default. - Inputs are trusted: no argument validation; a
parse…function throws a singleTypeErrorwhen its text does not match the expected format. - Arguments are never mutated: functions return new arrays and objects.
Example
ts
import { formatNumber, remap } from 'utils';
label.textContent = `${formatNumber(speed, '1.1-1')} kn`;
const angle = remap(speed, 0, 40, -135, 135, true); // the needle angle, stopped at the ends