Value accepted by formatting operations.
Bound specification type.
Exact value reported as rounded metadata.
ReadonlyresolutionCached successful resolution for spec.
ReadonlyspecDeeply frozen bound specification including the effective locale and any selected series scale.
Readonlykind: stringLiteral discriminator used to select a registered codec.
Readonlylocale: stringExplicit specification locale or the default captured during compilation.
Formats one value using the bound specification and locale.
Value accepted by the bound domain.
Localized text.
Formats and pads a column for monospaced text, measuring Unicode code points.
Values in row order.
Optionaloptions: ColumnFormatOptions
Alignment (decimal), fill (" "), and scale selection (shared).
Padded strings; use application-specific alignment for terminal cell widths.
Formats one value with tokens, resolution, and any available rounded value and scale.
Value to render and inspect.
Detailed output; optional metadata depends on the domain and presentation.
import { formatter } from "@neutrium/formatter";
const compact = formatter.compile({ kind: "number", compactExponent: 6, maximumFractionDigits: 2 });
const points = ["1234567", "2345678"].map(value => {
const result = compact.formatDetailed(value);
return {
value,
label: result.text,
tooltip: result.roundedValue === undefined ? "" :
`Label represents ${formatter.format(result.roundedValue, { kind: "number" })} visits`,
};
});
// First point: { value: "1234567", label: "1.23M", tooltip: "Label represents 1,230,000 visits" }
Formats several values, sharing an automatic compact or byte scale by default.
A fixed scale in spec, including one selected by compileSeries, takes
precedence over individual scale selection.
Values in output order.
Optionaloptions: SeriesFormatOptions
Scale selection, defaulting to shared.
One string per input; no values returns an empty array.
Formats several values into one semantic token array per value.
Values in output order.
Optionaloptions: SeriesFormatOptions
Shared or individual scale selection, as in formatSeries.
Ordered token arrays for each input row.
import { formatter } from "@neutrium/formatter";
const size = formatter.compile({ kind: "bytes" });
const cells = size.formatSeriesToParts([1024, 1536]).map(parts => {
const cell = document.createElement("td");
for (const part of parts) {
const span = document.createElement(part.type === "unit" ? "small" : "span");
span.textContent = part.value;
cell.append(span);
}
return cell;
});
// Append each cell to its file's table row: 1 KiB and 1.5 KiB, with smaller units.
Formats one value into semantic tokens, preserving localized literals.
Value accepted by the bound domain.
Tokens that render to the same text as format.
import { formatter } from "@neutrium/formatter";
const money = formatter.compile({ kind: "currency", currency: "USD" });
const price = document.createElement("span");
for (const part of money.formatToParts(12.5)) {
const span = document.createElement(part.type === "currency" ? "small" : "span");
span.textContent = part.value;
price.append(span);
}
document.body.append(price); // $12.50 with a smaller $.
Common operations on an immutable specification bound to a extensions!Formatter.
This type describes the common rendering operations. Prefer an inferred compiled result (or
typeofan existing result) to retain its exact range capabilities; unsupported methods are omitted automatically. All methods are bound and may be passed as callbacks. Obtain this object from extensions!Formatter.compile or extensions!Formatter.compileSeries; it has no parser methods. Use extensions-parse!Parser.compile on itsspecto create a matching parser.