|
1 | 1 | # purescript-formatters |
2 | 2 | Replacement for numeral.js, moment.js etc |
| 3 | + |
| 4 | +## Number formatters |
| 5 | + |
| 6 | +Formatter has following properties |
| 7 | ++ Number of digits before dot |
| 8 | ++ Number of digits after dot |
| 9 | ++ Should sign be printed for positive numbers |
| 10 | ++ Should thousands be separated by comma |
| 11 | ++ Should output string have abbreviations (like `K` or `M`) |
| 12 | + |
| 13 | +Number will be padded with zeros to have at least this number of leading zeros. |
| 14 | +This doesn't restrict number to have more digits then leading zeros in format string. |
| 15 | ++ `0000.0` will show 4 digits: `12 -> "0012.0"`, `1234 -> "1234.0"` |
| 16 | ++ `00.0` will show only 2 digits : `12 -> "12.0"`, `1234 -> "1234.0"` |
| 17 | + |
| 18 | +Number of digits after dot is set by number of trailing zeros (note the rounding) |
| 19 | ++ `0.000` will show 3 digits: `0.12345 -> "0.123"`, `12.98765 -> "12.988"` |
| 20 | ++ `0.0` will show only 1 digit: `0.12345 -> "0.1"`, `12.98765 -> "13.0"` |
| 21 | + |
| 22 | +If number is lesser then zero `-` is always printed. Otherwise you could specify `+` in format string |
| 23 | ++ `+0`: `12.0 -> "+12"`, `-34.8 -> "-35"` |
| 24 | ++ `0`: `12.0 -> "12"`, `-34.8 -> "-35"` |
| 25 | + |
| 26 | +Thousands separator is specified as `,0` please note that this `0` isn't counted as leading. |
| 27 | ++ `00,0`: `1234567890 -> "1,234,567,890.0", `1 -> "1.0"` |
| 28 | + |
| 29 | +For abbreviation one could use `a` flag. In general it tries to find the closest power of thousand and |
| 30 | +then use formatter to result of division of input number and that power. |
| 31 | ++ `0a`: `1234567 -> "1M"`, `1 -> "1"` |
| 32 | + |
| 33 | +## Date/Time formatters |
| 34 | + |
| 35 | +This is just subset of format/parse string from moment.js library. Currently supported |
| 36 | ++ `YYYY` |
| 37 | ++ `YY` |
| 38 | ++ `MMMM` |
| 39 | ++ `MMM` |
| 40 | ++ `MM` |
| 41 | ++ `DD` |
| 42 | ++ `X` |
| 43 | ++ `E` |
| 44 | ++ `HH` |
| 45 | ++ `hh` |
| 46 | ++ `a` |
| 47 | ++ `mm` |
| 48 | ++ `ss` |
| 49 | ++ `SSS` |
0 commit comments