Getting startedWhy use Encodable?Contributing guidelinesAbout
Gallery
Guides
Encodable API
Submodule API
@encodable/format
Utilities for managing time and number formats. Built on top of D3 formats and support customizing your own formatters.
Install
npm install @encodable/format global-box
Example usage
import {getTimeFormat,formatTime,getNumberFormat,formatNumber,getNumberFormatterRegistry,} from '@encodable/format';// Get number format functionconst numFormatFn = getNumberFormat('.2f');// Get time format functionconst timeFormatFn = getTimeFormat('%Y-%m-%d');// or just format directlyformatNumber('.2f', 200); // 200.00formatTime('%Y-%m-%d', new Date()); // 2020-08-15// can customize by adding your own formatters// or override the d3 onesgetNumberFormatterRegistry().registerValue('my-format', (x) => `haha:${x}`);formatNumber('my-format', 200); // haha:200