Skip to content

Commit

Permalink
Numfmt v3.0
Browse files Browse the repository at this point in the history
Dramatic overhaul of the parser and interface inspired by #42, the need to expose types (#38), and locale issues (#23).

### Changes from 2.0:

- Formatters are no longer constructed. Formatting is just a simple call. 
   Fixes: #42

- Types are now exposed for the entire interface.
  Closes #38

- _nbsp_ option is now off by default. A non-breaking space is till used as the grouping separator in the default locale, so "13 203" should not linebreak.

- `formatColor()` now returns `null` if pattern does not define a color. Previously it would default to "black".
   Fixes #40

- _locale_ has been fixed so that a pattern may correctly override a locale. The expected behaviour is to be able to provide a default locale and that formatters override it by modifiers.

- Both _en_US_ and _en-US_ styles are now supported for locale tags.

- Group sizing is now controlled by an option, `{ grouping: [ 3, 3 ] }`
  The formatter had remnants of behaviour from [its ancestor](https://github.com/borgar/ldml-number) which allowed defining group sizing in the format. In Excel, `#,##,##0` and `#,##0` are equivalent but sizing is controlled via locale settings.
  Fixes #48

- `dateToSerial()` no longer passes non-dates through. If it gets incompatible input (such as a number), a `null` will be returned.

- _nativeDate_ option has been removed. This affects two things:
  - `dateFromSerial()` now always returns a date parts array (`[ y, m, d, ... ]`).
  - `parseValue()`/`parseDate()` can no longer return dates.

  If you need the old behaviour then here is a utility function that safely converts the output to a `Date`. 

  ```js
  function toNativeDate (dateArrray) {
    const [ y, m, d, hh, mm, ss ] = dateArrray;
    const dt = new Date(0);
    dt.setUTCFullYear(y, m - 1, d);
    dt.setUTCHours(hh, mm, ss);
    return dt;
  }
  ```
  • Loading branch information
borgar authored May 16, 2024
1 parent d70b65d commit e5a1966
Show file tree
Hide file tree
Showing 55 changed files with 9,977 additions and 7,907 deletions.
31 changes: 17 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
extends: [ '@borgar/eslint-config' ],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
"extends": [ "@borgar/eslint-config", "@borgar/eslint-config/jsdoc" ],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
"requireConfigFile": false,
},
rules: {
'import/export': 'error',
'import/no-unresolved': 'error'
"rules": {
"import/export": "error",
"import/no-unresolved": "error",
"no-mixed-operators": "off",
"jsdoc/no-undefined-types": "off",
},
globals: {
console,
Set,
require,
module
"globals": {
"console": true,
"Set": true,
"require": true,
"module": true,
},
plugins: [
'import'
"plugins": [
"import"
]
}
650 changes: 650 additions & 0 deletions API.md

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

Loading

0 comments on commit e5a1966

Please sign in to comment.