This package has been deprecated

Author message:

We merged all @superset-ui packages. Use @superset-ui/core instead.

@superset-ui/number-format
TypeScript icon, indicating that this package has built-in type declarations

0.14.23 • Public • Published

@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.

Readme

Keywords

Package Sidebar

Install

npm i @superset-ui/number-format

Weekly Downloads

286

Version

0.14.23

License

Apache-2.0

Unpacked Size

47.7 kB

Total Files

43

Last publish

Collaborators

  • eschutho
  • arash_suri
  • michael.s.molina
  • suddjian
  • superset-ui-owner
  • kristw
  • data-ui
  • conglei
  • christopher.card.williams
  • soboko
  • mistercrunch
  • cdchambers
  • khtruong
  • erik_ritter
  • graceguo-supercat
  • michellet
  • supersetbot
  • ktmud
  • villebro
  • rusackas
  • kgabryje