JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 36211
  • Score
    100M100P100Q145603F
  • License Apache-2.0

Utilities for managing time and number formats.

Package Exports

  • @encodable/format

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@encodable/format) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@encodable/format

Version David (path)

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 function
const numFormatFn = getNumberFormat('.2f');
// Get time format function
const timeFormatFn = getTimeFormat('%Y-%m-%d');

// or just format directly

formatNumber('.2f', 200); // 200.00
formatTime('%Y-%m-%d', new Date()); // 2020-08-15

// can customize by adding your own formatters
// or override the d3 ones

getNumberFormatterRegistry().registerValue('my-format', (x) => `haha:${x}`);
formatNumber('my-format', 200); // haha:200