Giter VIP home page Giter VIP logo

purescript-formatters's Introduction

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

  • Number of digits before dot
  • Number of digits after dot
  • Should sign be printed for positive numbers
  • Should thousands be separated by comma
  • Should output string have abbreviations (like K or M)

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.

  • 0000.0 will show 4 digits: 12 → "0012.0", 1234 → "1234.0"
  • 00.0 will show only 2 digits : 12 → "12.0", 1234 → "1234.0"

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

  • 0.000 will show 3 digits: 0.12345 → "0.123", 12.98765 → "12.988"
  • 0.0 will show only 1 digit: 0.12345 → "0.1", 12.98765 → "13.0"

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

  • +0: 12.0 → "+12", -34.8 → "-35"
  • 0: 12.0 → "12", -34.8 → "-35"

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

  • 00,0: 1234567890 → "1,234,567,890.0", 1 → "1.0"`

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.

  • 0a: 1234567 → "1M", 1 → "1"

Date/Time formatters

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

  • YYYY - Full Year (1999)
  • YY - 2 digit year (99)
  • MMMM - Full Month (January)
  • MMM - Short Month (Jan)
  • DD - Padded Day (02)
  • D - Day of month (2)
  • X - Unix Timestamp (1506875681)
  • E - Day of Week (2)
  • dddd - DOW Name (Monday)
  • ddd - DOW Name Short (Mon)
  • HH - 24 Hour (13)
  • hh - 12 Hour (1)
  • a - Meridiem (am/pm)
  • mm - Minutes Padded (02)
  • m - Minutes (2)
  • ss - Seconds Padded (02)
  • s - Seconds (2)
  • S - MilliSeconds (4)
  • SS - MilliSeconds (04)
  • SSS - MilliSeconds (004)

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.

purescript-formatters's People

Contributors

garyb avatar safareli avatar thomashoneyman avatar cryogenian avatar tippenein avatar dgendill avatar sectore avatar negator avatar paulbjarne avatar mjhoy avatar kl0tl avatar davezuch avatar jamesdbrock avatar doolse avatar jordanmartinez avatar korayal avatar paulyoung avatar purefunctor avatar ntwilson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.