purescript-contrib / purescript-formatters

Formatting and printing for numeric and date/time/interval values
Apache License 2.0
41 stars 29 forks source link

Formatters

CI Release Pursuit Maintainer: garyb

A PureScript alternative to numeral.js, moment.js, etc.

Installation

Install formatters with Spago:

spago install formatters

Quick start

Number formatters

Formatter has following properties

Note: The parser will return a formatter with the default separator-characters - use withSeparators to override this after parsing.

Number will be padded with zeros to have at least this number of leading zeros. This doesn't restrict number to have more digits then leading zeros in format string.

Number of digits after dot is set by number of trailing zeros (note the rounding)

If number is lesser then zero - is always printed. Otherwise you could specify + in format string

Thousands separator is specified as ,0 please note that this 0 isn't counted as leading.

For abbreviation one could use a flag. In general it tries to find the closest power of thousand and then use formatter to result of division of input number and that power.

Date/Time formatters

This is a subset of common format/parse strings currently supported.

Full list is defined here

Documentation

formatters documentation is stored in a few places:

  1. Module documentation is published on Pursuit.
  2. Written documentation is kept in the docs directory.
  3. Usage examples can be found in the test suite.

If you get stuck, there are several ways to get help:

Contributing

You can contribute to formatters in several ways:

  1. If you encounter a problem or have a question, please open an issue. We'll do our best to work with you to resolve or answer it.

  2. If you would like to contribute code, tests, or documentation, please read the contributor guide. It's a short, helpful introduction to contributing to this library, including development instructions.

  3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the PureScript Discourse! Writing libraries and learning resources are a great way to help this library succeed.