numeric-quantity 2.1.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/cjs/numeric-quantity.cjs.development.js +349 -250
- package/dist/cjs/numeric-quantity.cjs.development.js.map +1 -1
- package/dist/cjs/numeric-quantity.cjs.production.js +1 -1
- package/dist/cjs/numeric-quantity.cjs.production.js.map +1 -1
- package/dist/numeric-quantity.iife.umd.min.js +2 -0
- package/dist/numeric-quantity.iife.umd.min.js.map +1 -0
- package/dist/numeric-quantity.legacy-esm.js +402 -230
- package/dist/numeric-quantity.legacy-esm.js.map +1 -1
- package/dist/numeric-quantity.mjs +338 -215
- package/dist/numeric-quantity.mjs.map +1 -1
- package/dist/numeric-quantity.production.mjs +1 -1
- package/dist/numeric-quantity.production.mjs.map +1 -1
- package/dist/types/constants.d.ts +10 -1
- package/dist/types/numericQuantity.d.ts +0 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types-esm/constants.d.mts +10 -1
- package/dist/types-esm/numericQuantity.d.mts +0 -1
- package/dist/types-esm/types.d.mts +6 -0
- package/package.json +16 -13
- package/dist/numeric-quantity.umd.min.js +0 -2
- package/dist/numeric-quantity.umd.min.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[![npm][badge-npm]](https://www.npmjs.com/package/numeric-quantity)
|
|
2
2
|

|
|
3
3
|
[](https://codecov.io/github/jakeboone02/numeric-quantity?branch=main)
|
|
4
|
-
[](
|
|
5
|
-
[](
|
|
4
|
+
[](https://npm-stat.com/charts.html?package=numeric-quantity&from=2015-08-01)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
7
|
Converts a string to a number, like an enhanced version of `parseFloat`.
|
|
8
8
|
|
|
@@ -11,14 +11,16 @@ Converts a string to a number, like an enhanced version of `parseFloat`.
|
|
|
11
11
|
Features:
|
|
12
12
|
|
|
13
13
|
- In addition to plain integers and decimals, `numeric-quantity` can parse numbers with comma or underscore separators (`'1,000'` or `'1_000'`), mixed numbers (`'1 2/3'`), vulgar fractions (`'1⅖'`), and the fraction slash character (`'1 2⁄3'`).
|
|
14
|
+
- Supports non-ASCII decimal numeral systems including Arabic-Indic (`'٣'`), Devanagari (`'३'`), Bengali (`'৩'`), Thai (`'๓'`), Fullwidth (`'3'`), and 70+ other Unicode digit scripts.
|
|
14
15
|
- To allow and ignore trailing invalid characters _à la_ `parseFloat`, pass `{ allowTrailingInvalid: true }` as the second argument.
|
|
15
16
|
- To parse Roman numerals like `'MCCXIV'` or `'Ⅻ'`, pass `{ romanNumerals: true }` as the second argument or call `parseRomanNumerals` directly.
|
|
17
|
+
- To parse numbers with European-style decimal comma (where `'1,0'` means `1`, not `10`), pass `{ decimalSeparator: ',' }` as the second argument.
|
|
16
18
|
- To produce `bigint` values when the input represents an integer that would exceeds the boundaries of `number`, pass `{ bigIntOnOverflow: true }` as the second argument.
|
|
17
19
|
- Results will be rounded to three decimal places by default. To avoid rounding, pass `{ round: false }` as the second argument. To round to a different number of decimal places, assign that number to the `round` option (`{ round: 5 }` will round to five decimal places).
|
|
18
20
|
- Returns `NaN` if the provided string does not resemble a number.
|
|
19
21
|
|
|
20
22
|
> _For the inverse operation—converting a number to an imperial measurement—check out [format-quantity](https://www.npmjs.com/package/format-quantity)._
|
|
21
|
-
|
|
23
|
+
|
|
22
24
|
> _For a more complete solution to parsing recipe ingredients, try [parse-ingredient](https://www.npmjs.com/package/parse-ingredient)._
|
|
23
25
|
|
|
24
26
|
## Usage
|
|
@@ -53,4 +55,14 @@ As UMD (all exports are properties of the global object `NumericQuantity`):
|
|
|
53
55
|
</script>
|
|
54
56
|
```
|
|
55
57
|
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
| ---------------------- | ----------------- | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `round` | `number \| false` | `3` | Round the result to a certain number of decimal places. Must be greater than or equal to zero. |
|
|
63
|
+
| `allowTrailingInvalid` | `boolean` | `false` | Allow and ignore trailing invalid characters _à la_ `parseFloat`. |
|
|
64
|
+
| `romanNumerals` | `boolean` | `false` | Attempt to parse Roman numerals if Arabic numeral parsing fails. |
|
|
65
|
+
| `bigIntOnOverflow` | `boolean` | `false` | Generates a `bigint` value if the string represents a valid integer too large for the `number` type. |
|
|
66
|
+
| `decimalSeparator` | `',' \| '.'` | `"."` | Specifies which character to treat as the decimal separator. |
|
|
67
|
+
|
|
56
68
|
[badge-npm]: https://img.shields.io/npm/v/numeric-quantity.svg?cacheSeconds=3600&logo=npm
|