0.14.23 • Published 4 years ago

@superset-ui/number-format v0.14.23

Weekly downloads
757
License
Apache-2.0
Repository
github
Last release
4 years ago

@superset-ui/number-format

Version David (path)

Description

Example usage

Functions getNumberFormatter and formatNumber should be used instead of calling d3.format directly.

import { getNumberFormatter } from '@superset-ui/number-format';
const formatter = getNumberFormatter('.2f');
console.log(formatter(1000));

or

import { formatNumber } from '@superset-ui/number-format';
console.log(formatNumber('.2f', 1000));

It is powered by a registry to support registration of custom formatting, with fallback to d3.format and handle error for invalid format string.

import { getNumberFormatterRegistry, formatNumber, NumberFormatter } from '@superset-ui/number-format';

getNumberFormatterRegistry().registerValue('my_format', new NumberFormatter({
  id: 'my_format',
  formatFunc: v => `my special format of ${v}`
});

console.log(formatNumber('my_format', 1000));
// prints 'my special format of 1000'

It also define constants for common d3 formats. See the full list of formats in NumberFormats.js.

import { NumberFormats } from '@superset-ui-number-format';

NumberFormats.PERCENT // ,.2%
NumberFormats.PERCENT_3_POINT // ,.3%

There is also a formatter based on pretty-ms that can be used to format time durations:

import { createDurationFormatter, formatNumber, getNumberFormatterRegistry } from from '@superset-ui-number-format';

getNumberFormatterRegistry().registerValue('my_duration_format', createDurationFormatter({ colonNotation: true });
console.log(formatNumber('my_duration_format', 95500))
// prints '1:35.5'

API

fn(args)

  • Do something

Development

@data-ui/build-config is used to manage the build configuration for this package including babel builds, jest testing, eslint, and prettier.

0.14.23

4 years ago

0.14.9

4 years ago

0.14.0

4 years ago

0.14.1

4 years ago

0.13.27

4 years ago

0.13.21

4 years ago

0.13.3

4 years ago

0.13.0

4 years ago

0.13.1

4 years ago

0.12.19

4 years ago

0.12.21

4 years ago

0.12.14

4 years ago

0.12.15

4 years ago

0.12.13

4 years ago

0.12.12

4 years ago

0.12.10

4 years ago

0.12.9

4 years ago

0.12.8

4 years ago

0.12.5

5 years ago

0.12.4

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.14

5 years ago

0.11.5

5 years ago

0.11.3

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.5

5 years ago

0.9.3

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago