1.0.0-z.2 • Published 3 years ago

@arugaz/formatter v1.0.0-z.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 years ago

npm version install size npm downloads

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'

License

MIT

1.0.0-z.2

3 years ago

1.0.0-z.1

3 years ago