@arugaz/formatter
v1.0.0-z.2
Published
Formatter library with tiny size in ~1 Kbytes!
Downloads
127
Readme
Table of Contents
Features
- Simple and Familiar API
- Unobstrusive and Unopinionated
Install
$ npm install --save @arugaz/formatter
$ yarn add @arugaz/formatter
Usage
import Format from "@arugaz/formatter";
// size formatter
const format = Format.sizeFormatter({
std: "JEDEC", // 'SI' | 'IEC' | 'JEDEC' (default)
decimalPlaces: 2,
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`,
});
format(1024); //=> '1 KB'
// duration formatter
const span = Date.now() - Date.parse("2019-01-01T09:00:00.000+0200");
const format = Format.durationFormatter({
// default 'y' | 'mo' | 'w' | 'd' | 'h' | 'm' | 's' | 'ms'
allowMultiples: ["y", "mo", "d"],
keepNonLeadingZeroes: false, // E.g. '1y 0mo 0d'
});
format(span); //=> '1y 1mo 19d'
import { sizeFormatter } from "@arugaz/formatter";
// size formatter
const format = sizeFormatter({
std: "JEDEC", // 'SI' | 'IEC' | 'JEDEC' (default)
decimalPlaces: 2,
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`,
});
format(2048); //=> '2 KB'