@types/d3-format

  • Version 3.0.4
  • Published
  • 18 kB
  • No dependencies
  • MIT license

Install

npm i @types/d3-format
yarn add @types/d3-format
pnpm add @types/d3-format

Overview

TypeScript definitions for d3-format

Index

Functions

function format

format: (specifier: string) => (n: number | { valueOf(): number }) => string;
  • Returns a new format function for the given string specifier. The returned function takes a number as the only argument, and returns a string representing the formatted number.

    Uses the current default locale.

    The general form of a specifier is [[fill]align][sign][symbol][0][width][,][.precision][~][type]. For reference, an explanation of the segments of the specifier string, refer to the FormatSpecifier interface properties.

    Parameter specifier

    A Specifier string.

    Throws

    Error on invalid format specifier.

function formatDefaultLocale

formatDefaultLocale: (
defaultLocale: FormatLocaleDefinition
) => FormatLocaleObject;
  • Create a new locale-based object which exposes format(...) and formatPrefix(...) methods for the specified locale definition. The specified locale definition will be set as the new default locale definition.

    Parameter defaultLocale

    A Format locale definition to be used as default.

function formatLocale

formatLocale: (locale: FormatLocaleDefinition) => FormatLocaleObject;
  • Create a new locale-based object which exposes format(...) and formatPrefix(...) methods for the specified locale.

    Parameter locale

    A Format locale definition.

function formatPrefix

formatPrefix: (
specifier: string,
value: number
) => (n: number | { valueOf(): number }) => string;
  • Returns a new format function for the given string specifier. The returned function takes a number as the only argument, and returns a string representing the formatted number. The returned function will convert values to the units of the appropriate SI prefix for the specified numeric reference value before formatting in fixed point notation.

    Uses the current default locale.

    The general form of a specifier is [[fill]align][sign][symbol][0][width][,][.precision][~][type]. For reference, an explanation of the segments of the specifier string, refer to the FormatSpecifier interface properties.

    Parameter specifier

    A Specifier string.

    Parameter value

    The reference value to determine the appropriate SI prefix.

    Throws

    Error on invalid format specifier.

function formatSpecifier

formatSpecifier: (specifier: string) => FormatSpecifier;
  • Parses the specified specifier, returning an object with exposed fields that correspond to the format specification mini-language and a toString method that reconstructs the specifier.

    The general form of a specifier is [[fill]align][sign][symbol][0][width][,][.precision][~][type]. For reference, an explanation of the segments of the specifier string, refer to the FormatSpecifier interface properties.

    Parameter specifier

    A specifier string.

    Throws

    Error on invalid format specifier.

function precisionFixed

precisionFixed: (step: number) => number;
  • Returns a suggested decimal precision for fixed point notation given the specified numeric step value.

    Parameter step

    The step represents the minimum absolute difference between values that will be formatted. (This assumes that the values to be formatted are also multiples of step.)

function precisionPrefix

precisionPrefix: (step: number, value: number) => number;
  • Returns a suggested decimal precision for use with locale.formatPrefix given the specified numeric step and reference value.

    Parameter step

    The step represents the minimum absolute difference between values that will be formatted. (This assumes that the values to be formatted are also multiples of step.)

    Parameter value

    Reference value determines which SI prefix will be used.

function precisionRound

precisionRound: (step: number, max: number) => number;
  • Returns a suggested decimal precision for format types that round to significant digits given the specified numeric step and max values.

    Parameter step

    The step represents the minimum absolute difference between values that will be formatted. (This assumes that the values to be formatted are also multiples of step.)

    Parameter max

    max represents the largest absolute value that will be formatted.

Classes

class FormatSpecifier

class FormatSpecifier {}

constructor

constructor(specifier: FormatSpecifierObject);
  • Given the specified specifier object, returning an object with exposed fields that correspond to the format specification mini-language and a toString method that reconstructs the specifier.

    Parameter specifier

    A specifier object.

property align

align: '>' | '<' | '^' | '=';
  • Alignment used for format, as set by choosing one of the following:

    '>' - Forces the field to be right-aligned within the available space. (Default behavior). '<' - Forces the field to be left-aligned within the available space. '^' - Forces the field to be centered within the available space. '=' - Like '>', but with any sign and symbol to the left of any padding.

property comma

comma: boolean;
  • The comma (,) option enables the use of a group separator, such as a comma for thousands.

property fill

fill: string;
  • fill can be any character. The presence of a fill character is signaled by the align character following it.

property precision

precision: number;
  • Depending on the type, the precision either indicates the number of digits that follow the decimal point (types 'f' and '%'), or the number of significant digits (types '' (none), 'e', 'g', 'r', 's' and 'p'). If the precision is not specified, it defaults to 6 for all types except '' (none), which defaults to 12. Precision is ignored for integer formats (types 'b', 'o', 'd', 'x', 'X' and 'c').

    See precisionFixed and precisionRound for help picking an appropriate precision.

property sign

sign: '-' | '+' | '(' | ' ';
  • The sign can be:

    '-' - nothing for positive and a minus sign for negative. (Default behavior.) '+' - a plus sign for positive and a minus sign for negative. '(' - nothing for positive and parentheses for negative. ' ' (space) - a space for positive and a minus sign for negative.

property symbol

symbol: '' | '$' | '#';
  • The symbol can be:

    '$' - apply currency symbols per the locale definition. '#' - for binary, octal, or hexadecimal notation, prefix by 0b, 0o, or 0x, respectively. '' (none) - no symbol. (Default behavior.)

property trim

trim: boolean;
  • The '~' option trims insignificant trailing zeros across all format types. This is most commonly used in conjunction with types 'r', 'e', 's' and '%'.

property type

type:
| ''
| 'e'
| 'f'
| 'g'
| 'r'
| 's'
| '%'
| 'p'
| 'b'
| 'o'
| 'd'
| 'x'
| 'X'
| 'c'
| 'n';
  • The available type values are:

    'e' - exponent notation. 'f' - fixed point notation. 'g' - either decimal or exponent notation, rounded to significant digits. 'r' - decimal notation, rounded to significant digits. 's' - decimal notation with an SI prefix, rounded to significant digits. '%' - multiply by 100, and then decimal notation with a percent sign. 'p' - multiply by 100, round to significant digits, and then decimal notation with a percent sign. 'b' - binary notation, rounded to integer. 'o' - octal notation, rounded to integer. 'd' - decimal notation, rounded to integer. 'x' - hexadecimal notation, using lower-case letters, rounded to integer. 'X' - hexadecimal notation, using upper-case letters, rounded to integer. 'c' - converts the integer to the corresponding unicode character before printing.

    The type '' (none) is also supported as shorthand for '~g' (with a default precision of 12 instead of 6), and the type 'n' is shorthand for ',g'. For the 'g', 'n' and '' (none) types, decimal notation is used if the resulting string would have precision or fewer digits; otherwise, exponent notation is used.

property width

width: number;
  • The width defines the minimum field width; if not specified, then the width will be determined by the content.

property zero

zero: boolean;
  • The zero (0) option enables zero-padding; this implicitly sets fill to 0 and align to =.

method toString

toString: () => string;
  • Return the object as a specifier string.

Interfaces

interface FormatLocaleDefinition

interface FormatLocaleDefinition {}
  • Specification of locale to use when creating a new FormatLocaleObject

property currency

currency: [string, string];
  • The currency prefix and suffix (e.g., ["$", ""]).

property decimal

decimal: string;
  • The decimal point (e.g., ".")

property grouping

grouping: number[];
  • The array of group sizes (e.g., [3]), cycled as needed.

property minus

minus?: string | undefined;
  • Optional; the minus sign (defaults to "−").

property nan

nan?: string | undefined;
  • Optional; the not-a-number value (defaults "NaN").

property numerals

numerals?: string[] | undefined;
  • An optional array of ten strings to replace the numerals 0-9.

property percent

percent?: string | undefined;
  • An optional symbol to replace the percent suffix; the percent suffix (defaults to "%").

property thousands

thousands: string;
  • The group separator (e.g., ","). Note that the thousands property is a misnomer, as the grouping definition allows groups other than thousands.

interface FormatLocaleObject

interface FormatLocaleObject {}
  • A Format Locale Object

method format

format: (specifier: string) => (n: number | { valueOf(): number }) => string;
  • Returns a new format function for the given string specifier. The returned function takes a number as the only argument, and returns a string representing the formatted number.

    Parameter specifier

    A Specifier string.

    Throws

    Error on invalid format specifier.

method formatPrefix

formatPrefix: (
specifier: string,
value: number
) => (n: number | { valueOf(): number }) => string;
  • Returns a new format function for the given string specifier. The returned function takes a number as the only argument, and returns a string representing the formatted number. The returned function will convert values to the units of the appropriate SI prefix for the specified numeric reference value before formatting in fixed point notation.

    Parameter specifier

    A Specifier string.

    Parameter value

    The reference value to determine the appropriate SI prefix.

    Throws

    Error on invalid format specifier.

interface FormatSpecifierObject

interface FormatSpecifierObject {}

property align

align?: string | undefined;
  • Alignment used for format, as set by choosing one of the following:

    '>' - Forces the field to be right-aligned within the available space. (Default behavior). '<' - Forces the field to be left-aligned within the available space. '^' - Forces the field to be centered within the available space. '=' - Like '>', but with any sign and symbol to the left of any padding.

property comma

comma?: string | undefined;
  • The comma (,) option enables the use of a group separator, such as a comma for thousands.

property fill

fill?: string | undefined;
  • fill can be any character. The presence of a fill character is signaled by the align character following it.

property precision

precision?: string | undefined;
  • Depending on the type, the precision either indicates the number of digits that follow the decimal point (types 'f' and '%'), or the number of significant digits (types '' (none), 'e', 'g', 'r', 's' and 'p'). If the precision is not specified, it defaults to 6 for all types except '' (none), which defaults to 12. Precision is ignored for integer formats (types 'b', 'o', 'd', 'x', 'X' and 'c').

    See precisionFixed and precisionRound for help picking an appropriate precision.

property sign

sign?: string | undefined;
  • The sign can be:

    '-' - nothing for positive and a minus sign for negative. (Default behavior.) '+' - a plus sign for positive and a minus sign for negative. '(' - nothing for positive and parentheses for negative. ' ' (space) - a space for positive and a minus sign for negative.

property symbol

symbol?: string | undefined;
  • The symbol can be:

    '$' - apply currency symbols per the locale definition. '#' - for binary, octal, or hexadecimal notation, prefix by 0b, 0o, or 0x, respectively. '' (none) - no symbol. (Default behavior.)

property trim

trim?: string | undefined;
  • The '~' option trims insignificant trailing zeros across all format types. This is most commonly used in conjunction with types 'r', 'e', 's' and '%'.

property type

type?: string | undefined;
  • The available type values are:

    'e' - exponent notation. 'f' - fixed point notation. 'g' - either decimal or exponent notation, rounded to significant digits. 'r' - decimal notation, rounded to significant digits. 's' - decimal notation with an SI prefix, rounded to significant digits. '%' - multiply by 100, and then decimal notation with a percent sign. 'p' - multiply by 100, round to significant digits, and then decimal notation with a percent sign. 'b' - binary notation, rounded to integer. 'o' - octal notation, rounded to integer. 'd' - decimal notation, rounded to integer. 'x' - hexadecimal notation, using lower-case letters, rounded to integer. 'X' - hexadecimal notation, using upper-case letters, rounded to integer. 'c' - converts the integer to the corresponding unicode character before printing.

    The type '' (none) is also supported as shorthand for '~g' (with a default precision of 12 instead of 6), and the type 'n' is shorthand for ',g'. For the 'g', 'n' and '' (none) types, decimal notation is used if the resulting string would have precision or fewer digits; otherwise, exponent notation is used.

property width

width?: string | undefined;
  • The width defines the minimum field width; if not specified, then the width will be determined by the content.

property zero

zero?: string | undefined;
  • The zero (0) option enables zero-padding; this implicitly sets fill to 0 and align to =.

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (0)

No dev dependencies.

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/d3-format.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/d3-format)
  • HTML
    <a href="https://www.jsdocs.io/package/@types/d3-format"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>