Neverending Pile of Messages
Learn how companies like Phone2Action are using npm in their front-end developmentJoin the conversation »

d3plus-format

0.1.16 • Public • Published

d3plus-format

NPM Release Build Status Dependency Status Gitter

Shorthand formatters for common number types.

Installing

If you use NPM, run npm install d3plus-format --save. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. You can also load directly from d3plus.org:

<script src="https://d3plus.org/js/d3plus-format.v0.1.full.min.js"></script>

API Reference

  • formatAbbreviate - Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. 1200000 to "1.2M").
  • formatLocale - A set of default locale formatters used when assigning suffixes and currency in numbers.
Name Default Description
separator "" Separation between the number with the suffix.
suffixes [] List of suffixes used to format numbers.
grouping [3] The array of group sizes,
delimiters {thousands: ",", decimal: "."} Decimal and group separators.
currency ["$", ""] The currency prefix and suffix.

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.

Param Type Description
n Number | String The number to be formatted.
locale Object | String The locale config to be used. If value is an object, the function will format the numbers according the object. The object must include suffixes, delimiter and currency properties.

formatLocale <>

A set of default locale formatters used when assigning suffixes and currency in numbers.

Name Default Description
separator "" Separation between the number with the suffix.
suffixes [] List of suffixes used to format numbers.
grouping [3] The array of group sizes,
delimiters {thousands: ",", decimal: "."} Decimal and group separators.
currency ["$", ""] The currency prefix and suffix.

This is a global namespace.


Documentation generated on Tue, 17 Sep 2019 17:22:35 GMT

Install

npm i d3plus-format

DownloadsWeekly Downloads

480

Version

0.1.16

License

MIT

Unpacked Size

76 kB

Total Files

9

Homepage

d3plus.org

Last publish

Collaborators

  • avatar