/** * Every number an interface draws, in the language somebody chose. * * One home, because a figure is not a string until a locale has been applied to * it, and a surface that lets each screen apply its own ends up with fourteen * answers. `842` is `842` in English and `842` in French; `4,210,000` is * `4 210 000` there and `42.1 lakh` in Hindi; `$1.28M` is `1,28 M $` in * Canadian French and `128万ドル` in Japanese. Every one of those is a fact * about a reader, and `toLocaleString('en-US')` pins them all to one reader * while the language menu says otherwise. * * Nothing here rolls its own arithmetic either. A K/M/B ladder is an English * convention: CLDR gives Japanese 万 and 億 at four and eight digits rather * than three and six, and Spanish says `mil`. `Intl.NumberFormat` knows the * whole table and it is already in the browser. * * Which currency an amount can honestly be drawn in is the caller's fact and * not this module's — relabelling a dollar figure as euros is a conversion at a * rate nobody stated. So the reading arrives from outside, and everything here * is a pure function of it. */ /** Who is reading, which is the whole of what decides how a figure is written. */ export interface Reading { /** The language tag `Intl` resolves against — `en-US`, `fr-CA`, `ja`. */ locale: string; /** What the amounts are stated in, as an ISO 4217 code. */ currency: string; } /** The mark a cell carries where there is nothing to draw. Not a zero: a zero * is a figure, and this is the absence of one. */ export declare const NONE = "\u2014"; /** Every way this reader's figures are written. */ export interface Figures { /** A number, at a resolution that suits its size. */ count(n: number | bigint): string; /** A figure worked out from others, at the places the arithmetic carries. */ precise(n: number): string; /** The same number, short enough to sit on one line of a tile. */ brief(n: number): string; /** An amount, exact. */ money(n: number): string; /** * The same amount in two pieces: what is read at full strength, and the * fraction set back behind it. * * Split by `Intl` rather than at a character, because which character * separates the two — and whether the fraction leads or trails — is a * property of the reader's language. Where there is no fraction the second * piece is empty and the caller draws one span. */ parted(n: number): readonly [string, string]; /** A round sum a person is offered, in the currency the field is in. */ offered(n: number, of?: string): string; /** An amount, short enough for a tile. */ worth(n: number): string; /** A proportion drawn as a percentage. Takes the proportion, not the * percentage: `0.1` is ten per cent, which is what `moved` returns. */ percent(of: number): string; /** A rate, as the percentage it is stated at. Takes the proportion, so a * quarter of a per cent arrives as `0.0025`. */ rate(of: number): string; /** A moment, in the reader's own calendar. */ day(at: Date | number): string; /** The time of day alone, for a figure re-read on a timer. */ clock(at: Date | number): string; /** The same moment with the time on it. */ moment(at: Date | number): string; /** * How long, in the shortest form a language has for the unit. * * English writes `10s` and `1d`; French writes `10min` and `1j`; Russian * writes `10 мин` with the space it puts there. CLDR holds all of that and * `Intl` already carries CLDR, so there is no sentence for anyone to * translate and no four-way table for anyone to get wrong. */ span(n: number, of: 'second' | 'minute' | 'hour' | 'day'): string; /** * The symbol a currency is written with, out of the same source as the * figures. * * Asked of `Intl` by formatting nothing and reading back the part that is not * a digit, because there is no other way to get at it: `Intl.NumberFormat` * holds the table and does not publish it. A list of currencies draws this * beside each code, so the mark and the figures it explains cannot disagree. */ sign(of?: string): string; } /** How this reader's figures are written. Kept, so a table builds one set. */ export declare function figures(of: Reading): Figures; /** * What a field holding a figure keeps of what was typed into it. * * Digits, at most one point, and no more places after it than the unit the * field is in carries. A field that takes more than its unit can hold has to * account for it afterwards, and an account of a keystroke is a sentence on a * screen where the honest answer is simply not to take the character. * * @param typed what arrived from the control * @param places how many decimal places the unit carries, where the field is * in a unit that says — a figure in no stated unit keeps them all */ export declare function digits(typed: string, places?: number): string; /** * What one figure did against the one before it, as a proportion. * * A proportion rather than a percentage, because multiplying by a hundred is a * thing a reader's language does and `Intl` does it as part of drawing the * number. Arithmetic here, presentation there. * * Null rather than zero where there is nothing to compare against, and null * where the earlier figure is zero: a rise from nothing is not a proportion, * and rendering it as one puts Infinity on the screen. */ export declare function moved(now: number | null, before: number | null): number | null; //# sourceMappingURL=figure.d.ts.map