Socket
Socket
Sign inDemoInstall

d3-format

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-format

Format numbers for human consumption.


Version published
Weekly downloads
7.2M
increased by5.97%
Maintainers
1
Weekly downloads
 
Created

What is d3-format?

The d3-format package is part of the D3 (Data-Driven Documents) JavaScript library, which is used for producing graphical visualizations of data primarily on the web. The d3-format module provides a system for formatting numbers for human-readable display, allowing users to specify the appearance of numbers, such as the decimal precision, alignment, padding, rounding, and locale-specific formatting.

What are d3-format's main functionalities?

Number Formatting

This feature allows you to format numbers using a variety of options. The example shows formatting a number to two decimal places.

const d3 = require('d3-format');
const format = d3.format('.2f');
console.log(format(3.14159)); // Outputs: '3.14'

Locale-specific Formatting

This feature supports locale-specific formatting. The example demonstrates formatting a number as currency in a European style, using comma for decimal and period for thousands separator.

const d3 = require('d3-format');
const locale = d3.formatLocale({ decimal: ',', thousands: '.', grouping: [3], currency: ['€', ''] });
const format = locale.format('$,.2f');
console.log(format(1234567.89)); // Outputs: '€1.234.567,89'

SI Prefix Formatting

This feature allows formatting numbers with SI prefixes, useful for representing large or small numbers succinctly. The example formats the number 1500 with an SI prefix, resulting in '1.50k'.

const d3 = require('d3-format');
const format = d3.format('.3s');
console.log(format(1500)); // Outputs: '1.50k'

Other packages similar to d3-format

Keywords

FAQs

Package last updated on 29 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc