Skip to content

Commit 8faac7a

Browse files
authored
Merge pull request #26 from jakeboone02/drop-umd
v2
2 parents 5cd76e6 + d50355d commit 8faac7a

33 files changed

+5089
-4538
lines changed

.codesandbox/ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"sandboxes": ["numeric-quantity-ci-p97jb"]
2+
"sandboxes": ["/ci"],
3+
"node": "18"
34
}

.github/workflows/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
# node: ['10.x', '12.x', '14.x']
12-
node: ['14.x']
11+
# node: ['14.x', '16.x', '18.x']
12+
node: ['18.x']
1313
# os: [ubuntu-latest, windows-latest, macOS-latest]
1414
os: [ubuntu-latest]
1515

1616
steps:
1717
- name: Checkout repo
1818
uses: actions/checkout@v2
1919

20-
- name: Use Node ${{ matrix.node }}
20+
- name: Use Node ${{ matrix.node }} on ${{ matrix.os }}
2121
uses: actions/setup-node@v1
2222
with:
2323
node-version: ${{ matrix.node }}
2424

2525
- name: Install deps and build (with cache)
2626
uses: bahmutov/npm-install@v1
27+
with:
28+
install-command: yarn --immutable
2729

2830
- name: Test
2931
run: yarn test --ci --maxWorkers=2
@@ -32,5 +34,5 @@ jobs:
3234
run: yarn build
3335

3436
- name: Upload coverage to Codecov
35-
if: matrix.os == 'ubuntu-latest' && matrix.node == '14.x'
37+
if: matrix.os == 'ubuntu-latest' && matrix.node == '18.x'
3638
uses: codecov/codecov-action@v1

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.formatOnSave": true
2+
"editor.formatOnSave": true,
3+
"prettier.prettierPath": "./node_modules/prettier"
34
}

.yarn/releases/yarn-3.2.3.cjs

Lines changed: 0 additions & 783 deletions
This file was deleted.

.yarn/releases/yarn-3.6.0.cjs

Lines changed: 874 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ plugins:
88
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
99
spec: "@yarnpkg/plugin-typescript"
1010

11-
yarnPath: .yarn/releases/yarn-3.2.3.cjs
11+
yarnPath: .yarn/releases/yarn-3.6.0.cjs

CHANGELOG.md

Lines changed: 162 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,180 @@
1-
## 1.0.1 (2021-02-15)
1+
# Changelog
22

3-
- Added description to package.json
3+
All notable changes to this project will be documented in this file.
44

5-
## 1.0.0 (2021-02-11)
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
67

7-
- New build system ([tsdx](https://tsdx.io/))
8+
## [Unreleased]
89

9-
## 0.5.1 (2019-08-24)
10+
### Changed
1011

11-
- Fixed README.md note about return values
12+
- `numericQuantity` is now a named export; there is no default export.
13+
- UMD build assigns all exports, including `numericQuantity`, to the global object `NumericQuantity`. Previously, it assigned the main function to the global namespace as `numericQuantity`.
1214

13-
## 0.5.0 (2019-08-24)
15+
### Added
1416

15-
### Breaking change
17+
- Support for comma (`','`) and underscore (`'_'`) separators within Arabic numeral sequences. If a numeric sequence has a leading or trailing separator, that sequence will be considered invalid. This will cause `numericQuantity` to return `NaN` unless `allowTrailingInvalid` is `true` (see next item), in which case the sequence in question and everything after it will be ignored.
18+
- Options object as optional second parameter. Accepts the following options:
19+
- `allowTrailingInvalid` (`boolean`, default `false`): Allows `numericQuantity` to more closely resemble the behavior of `parseFloat` by accepting and ignoring everything from the first invalid character to the end of the string.
20+
- `romanNumerals` (`boolean`, default `false`): Enables support for Roman numerals with modern, strict rules, including the Unicode code points `U+2160` through `U+217F`. Roman numerals will only be parsed if an attempt to parse the string based on Arabic numerals fails. To parse Roman numerals unconditionally, call `parseRomanNumerals` directly.
21+
- `round` (`number | false`, default `3`): Rounds the result to the specified number of decimal places. Use `round: false` to avoid rounding.
22+
- Support for Unicode "Fraction Numerator One" code point (`'⅟'`, `U+215F`), which must be followed by a numeric sequence (the denominator) to be considered part of a valid fraction representation.
23+
- Named exports of internal utilities like regular expressions, character maps, types, etc.
24+
- Build with ([tsup](https://tsup.egoist.dev/)).
1625

17-
- Returns `NaN` for invalid inputs instead of `-1`
26+
## [v1.0.4] - 2022-04-16
1827

19-
### Bug fixes
28+
### Fixed
2029

21-
- Handles negative numbers properly (fixes [#3](https://github.com/jakeboone02/numeric-quantity/issues/3))
30+
- Corrected filenames in [package.json](./package.json).
2231

23-
## 0.4.2 (2019-08-23)
32+
## [v1.0.3] - 2022-04-16
2433

25-
- Rewritten with TypeScript
34+
### Added
2635

27-
## 0.3.2 (2018-09-21)
36+
- Build with [Vite](https://vitejs.dev/).
2837

29-
## 0.3.1 (2015-07-16)
38+
## [v1.0.2] - 2021-08-23
3039

31-
## 0.3.0 (2015-07-16)
40+
### Added
3241

33-
## 0.1.2 (2015-03-20)
42+
- [#21] Support for Unicode fraction slash (``, `U+2044`).
3443

35-
## 0.1.1 (2015-03-19)
44+
## [v1.0.1] - 2021-02-15
3645

37-
## 0.1.0 (2015-03-18)
46+
### Fixed
47+
48+
- Added description to [package.json](./package.json).
49+
50+
## [v1.0.0] - 2021-02-11
51+
52+
### Added
53+
54+
- [#12] New build system ([tsdx](https://tsdx.io/)).
55+
56+
## [v0.5.2] - 2021-02-08
57+
58+
### Fixed
59+
60+
- Updated CI badges on [README.md](./README.md).
61+
62+
## [v0.5.1] - 2019-08-24
63+
64+
### Fixed
65+
66+
- [README.md](./README.md) note about return values.
67+
68+
## [v0.5.0] - 2019-08-24
69+
70+
### Changed
71+
72+
- Returns `NaN` for invalid inputs instead of `-1`.
73+
74+
### Fixed
75+
76+
- [#3] Handles negative numbers.
77+
78+
## [v0.4.2] - 2019-08-23
79+
80+
### Fixed
81+
82+
- Publish `dist` directory only.
83+
84+
## [v0.4.1] - 2019-08-23
85+
86+
### Changed
87+
88+
- Rewritten in TypeScript.
89+
90+
### Added
91+
92+
- Build with [Rollup](https://rollupjs.org/).
93+
94+
## [v0.4.0] - 2019-08-22
95+
96+
### Added
97+
98+
- ESM and CJS builds.
99+
100+
## [v0.3.3] - 2019-07-21
101+
102+
### Added
103+
104+
- JSDoc comments for tooltips
105+
106+
## [v0.3.2] - 2018-09-21
107+
108+
### Added
109+
110+
- TypeScript types.
111+
112+
## [v0.3.1] - 2015-07-16
113+
114+
### Fixed
115+
116+
- Documentation update.
117+
118+
## [v0.3.0] - 2015-07-16
119+
120+
### Added
121+
122+
- UMD support.
123+
124+
### Fixed
125+
126+
- Minor bug fixes.
127+
128+
## [v0.2.0] - 2015-05-14
129+
130+
### Added
131+
132+
- [#1] Accept decimals without a leading zero.
133+
134+
## [v0.1.2] - 2015-03-20
135+
136+
### Fixed
137+
138+
- Minor performance improvement.
139+
140+
## [v0.1.1] - 2015-03-19
141+
142+
### Changed
143+
144+
- Use `parseInt`/`parseFloat` instead of `str - 0` to parse numbers from strings.
145+
146+
## [v0.1.0] - 2015-03-18
147+
148+
### Added
149+
150+
- Initial release.
151+
152+
<!-- Issue/PR links -->
153+
154+
[#1]: https://github.com/jakeboone02/numeric-quantity/issues/1
155+
[#3]: https://github.com/jakeboone02/numeric-quantity/issues/3
156+
[#21]: https://github.com/jakeboone02/numeric-quantity/pull/21
157+
[#12]: https://github.com/jakeboone02/numeric-quantity/pull/12
158+
159+
<!-- Release comparison links -->
160+
161+
[unreleased]: https://github.com/jakeboone02/numeric-quantity/compare/v1.0.4...HEAD
162+
[v1.0.4]: https://github.com/jakeboone02/numeric-quantity/compare/v1.0.3...v1.0.4
163+
[v1.0.3]: https://github.com/jakeboone02/numeric-quantity/compare/v1.0.2...v1.0.3
164+
[v1.0.2]: https://github.com/jakeboone02/numeric-quantity/compare/v1.0.1...v1.0.2
165+
[v1.0.1]: https://github.com/jakeboone02/numeric-quantity/compare/v1.0.0...v1.0.1
166+
[v1.0.0]: https://github.com/jakeboone02/numeric-quantity/compare/v0.5.2...v1.0.0
167+
[v0.5.2]: https://github.com/jakeboone02/numeric-quantity/compare/v0.5.1...v0.5.2
168+
[v0.5.1]: https://github.com/jakeboone02/numeric-quantity/compare/v0.5.0...v0.5.1
169+
[v0.5.0]: https://github.com/jakeboone02/numeric-quantity/compare/v0.4.2...v0.5.0
170+
[v0.4.2]: https://github.com/jakeboone02/numeric-quantity/compare/v0.4.1...v0.4.2
171+
[v0.4.1]: https://github.com/jakeboone02/numeric-quantity/compare/v0.4.0...v0.4.1
172+
[v0.4.0]: https://github.com/jakeboone02/numeric-quantity/compare/v0.3.3...v0.4.0
173+
[v0.3.3]: https://github.com/jakeboone02/numeric-quantity/compare/v0.3.2...v0.3.3
174+
[v0.3.2]: https://github.com/jakeboone02/numeric-quantity/compare/v0.3.1...v0.3.2
175+
[v0.3.1]: https://github.com/jakeboone02/numeric-quantity/compare/v0.3.0...v0.3.1
176+
[v0.3.0]: https://github.com/jakeboone02/numeric-quantity/compare/v0.2.0...v0.3.0
177+
[v0.2.0]: https://github.com/jakeboone02/numeric-quantity/compare/v0.1.2...v0.2.0
178+
[v0.1.2]: https://github.com/jakeboone02/numeric-quantity/compare/v0.1.1...v0.1.2
179+
[v0.1.1]: https://github.com/jakeboone02/numeric-quantity/compare/v0.1.0...v0.1.1
180+
[v0.1.0]: https://github.com/jakeboone02/numeric-quantity/tree/v0.1.0

README.md

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,74 @@
11
# numeric-quantity
22

3-
[![npm version](https://badge.fury.io/js/numeric-quantity.svg)](//npmjs.com/package/numeric-quantity)
4-
![workflow status](https://github.com/jakeboone02/numeric-quantity/workflows/Continuous%20Integration/badge.svg)
5-
[![codecov.io](https://codecov.io/github/jakeboone02/numeric-quantity/coverage.svg?branch=master)](https://codecov.io/github/jakeboone02/numeric-quantity?branch=master)
3+
[![npm][badge-npm]](https://www.npmjs.com/package/numeric-quantity)
4+
![workflow status](https://github.com/jakeboone02/numeric-quantity/actions/workflows/main.yml/badge.svg)
5+
[![codecov.io](https://codecov.io/github/jakeboone02/numeric-quantity/coverage.svg?branch=main)](https://codecov.io/github/jakeboone02/numeric-quantity?branch=main)
66
[![downloads](https://img.shields.io/npm/dm/numeric-quantity.svg)](http://npm-stat.com/charts.html?package=numeric-quantity&from=2015-08-01)
77
[![MIT License](https://img.shields.io/npm/l/numeric-quantity.svg)](http://opensource.org/licenses/MIT)
88

9-
Converts a string to a number. The string can include mixed numbers or vulgar fractions.
9+
Converts a string to a number, like an enhanced version of `parseFloat`. The return value will be `NaN` if the provided string does not resemble a number.
1010

11-
For the inverse operation (converting a number to an imperial measurement), check out [format-quantity](https://www.npmjs.com/package/format-quantity).
11+
Features:
1212

13-
For a more complete solution to parsing recipe ingredients, try [parse-ingredient](https://www.npmjs.com/package/parse-ingredient).
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+
- To allow and ignore trailing invalid characters _à la_ `parseFloat`, pass `{ allowTrailingInvalid: true }` as the second argument.
15+
- To parse Roman numerals like `'MCCXIV'` or `'Ⅻ'`, pass `{ romanNumerals: true }` as the second argument or call `parseRomanNumerals` directly.
16+
- 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).
1417

15-
## Installation
18+
> _For the inverse operation—converting a number to an imperial measurement—check out [format-quantity](https://www.npmjs.com/package/format-quantity)._
19+
>
20+
> _For a more complete solution to parsing recipe ingredients, try [parse-ingredient](https://www.npmjs.com/package/parse-ingredient)._
1621
17-
### npm
22+
## Usage
23+
24+
### Installed
1825

19-
```shell
20-
# npm
21-
npm i numeric-quantity
26+
```js
27+
import { numericQuantity } from 'numeric-quantity';
2228

23-
# yarn
24-
yarn add numeric-quantity
29+
console.log(numericQuantity('1 1/2')); // 1.5
30+
console.log(numericQuantity('2 2/3')); // 2.667
2531
```
2632

27-
### Browser
33+
### CDN
2834

29-
In the browser, available as a global function `numericQuantity`.
35+
As an ES module:
36+
37+
```html
38+
<script type="module">
39+
import { numericQuantity } from 'https://cdn.jsdelivr.net/npm/numeric-quantity/+esm';
40+
41+
console.log(numericQuantity('10½')); // 10.5
42+
</script>
43+
```
44+
45+
As UMD (all exports are properties of the global object `NumericQuantity`):
3046

3147
```html
3248
<script src="https://unpkg.com/numeric-quantity"></script>
3349
<script>
34-
console.log(numericQuantity('10 1/2')); // 10.5
50+
console.log(NumericQuantity.numericQuantity('xii')); // 12
3551
</script>
3652
```
3753

38-
## Usage
54+
## Other exports
3955

40-
```js
41-
import numericQuantity from 'numeric-quantity';
42-
43-
console.log(numericQuantity('1 1/2')); // 1.5
44-
console.log(numericQuantity('2 2/3')); // 2.666
45-
```
56+
| Name | Type | Description |
57+
| --------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------- |
58+
| `numericRegex` | `RegExp` | Regular expression matching a string that resembles a number (using Arabic numerals) in its entirety |
59+
| `numericRegexWithTrailingInvalid` | `RegExp` | Same as `numericRegex`, but allows/ignores trailing invalid characters. |
60+
| `VulgarFraction` | `type` | Union type of all unicode vulgar fraction code points |
61+
| `vulgarFractionsRegex` | `RegExp` | Regular expression matching the first unicode vulgar fraction code point |
62+
| `vulgarFractionToAsciiMap` | `object` | Mapping of each vulgar fraction to its traditional ASCII representation (e.g., `'½'` to `'1/2'`) |
63+
| `parseRomanNumerals` | `function` | Same function signature as `numericQuantity`, but only for Roman numerals (used internally) |
64+
| `romanNumeralRegex` | `RegExp` | Regular expression matching valid Roman numeral sequences (uses modern, strict rules) |
65+
| `romanNumeralUnicodeRegex` | `RegExp` | Regular expression matching any unicode Roman numeral code point |
66+
| `romanNumeralUnicodeToAsciiMap` | `object` | Mapping of each Roman numeral to its traditional ASCII representation (e.g., `'Ⅻ'` to `'XII'`) |
67+
| `romanNumeralValues` | `object` | Mapping of each valid Roman numeral sequence fragment to its numeric value |
68+
| `NumericQuantityOptions` | `interface` | Shape of the (optional) second argument to `numericQuantity` |
69+
| `RomanNumeralAscii` | `type` | Union type of allowable Roman numeral characters (uppercase only) |
70+
| `RomanNumeralUnicode` | `type` | Union type of all Unicode Roman numeral characters (representing 1-12, 50, 100, 500, and 1000) |
71+
| `RomanNumeral` | `type` | Union type of `RomanNumeralAscii` and `RomanNumeralUnicode` |
72+
| `defaultOptions` | `object` | Object representing the default options |
4673

47-
The return value will be `NaN` if the provided string does not resemble a number.
74+
[badge-npm]: https://img.shields.io/npm/v/numeric-quantity.svg?cacheSeconds=3600&logo=npm

babel.config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

ci/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8" />
4+
<title>numeric-quantity CI Test Page</title>
5+
</head>
6+
<body>
7+
<div id="app"></div>
8+
<script src="src/index.ts"></script>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)