3.0.0-alpha.3 • Published 4 months ago

@d3plus/format v3.0.0-alpha.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@d3plus/format

JavaScript formatters for localized numbers and dates.

Installing

If using npm, npm install @d3plus/format. Otherwise, you can download the latest release from GitHub or load from a CDN.

import modules from "@d3plus/format";

In vanilla JavaScript, a d3plus global is exported from the pre-bundled version:

<script src="https://cdn.jsdelivr.net/npm/@d3plus/format@3.0.0-alpha.3"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using @d3plus/react.

API Reference

  • format - An extension to d3's format function that adds more string formatting types and localizations.
  • formatAbbreviate - Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. 1200000 to "1.2M").
  • formatDate - A default set of date formatters, which takes into account both the interval in between in each data point but also the start/end data points.
  • formatDefaultLocale - An extension to d3's formatDefaultLocale function that allows setting the locale globally for formatters.

d3plus.format(specifier) <>

An extension to d3's format function that adds more string formatting types and localizations.

This is a global function


d3plus.formatAbbreviate(n, locale) <>

Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. 1200000 to "1.2M").

This is a global function


d3plus.formatDate(d, dataArray, formatter) <>

A default set of date formatters, which takes into account both the interval in between in each data point but also the start/end data points.

This is a global function


d3plus.formatDefaultLocale(definition) <>

An extension to d3's formatDefaultLocale function that allows setting the locale globally for formatters.

This is a global function