numeric-quantity 2.0.1 → 3.0.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.
Files changed (33) hide show
  1. package/README.md +15 -3
  2. package/dist/cjs/numeric-quantity.cjs.development.js +247 -246
  3. package/dist/cjs/numeric-quantity.cjs.development.js.map +1 -1
  4. package/dist/cjs/numeric-quantity.cjs.production.js +1 -1
  5. package/dist/cjs/numeric-quantity.cjs.production.js.map +1 -1
  6. package/dist/numeric-quantity.iife.umd.min.js +2 -0
  7. package/dist/numeric-quantity.iife.umd.min.js.map +1 -0
  8. package/dist/numeric-quantity.legacy-esm.js +301 -225
  9. package/dist/numeric-quantity.legacy-esm.js.map +1 -1
  10. package/dist/numeric-quantity.mjs +237 -210
  11. package/dist/numeric-quantity.mjs.map +1 -1
  12. package/dist/numeric-quantity.production.mjs +1 -1
  13. package/dist/numeric-quantity.production.mjs.map +1 -1
  14. package/dist/types/constants.d.ts +79 -0
  15. package/dist/types/dev.d.ts +1 -0
  16. package/dist/types/index.d.ts +4 -0
  17. package/dist/types/numericQuantity.d.ts +12 -0
  18. package/dist/types/parseRomanNumerals.d.ts +8 -0
  19. package/dist/types/types.d.ts +49 -0
  20. package/dist/types-esm/constants.d.mts +79 -0
  21. package/dist/types-esm/dev.d.mts +1 -0
  22. package/dist/types-esm/index.d.mts +4 -0
  23. package/dist/types-esm/numericQuantity.d.mts +12 -0
  24. package/dist/types-esm/parseRomanNumerals.d.mts +8 -0
  25. package/dist/types-esm/types.d.mts +49 -0
  26. package/package.json +23 -18
  27. package/dist/cjs/numeric-quantity.cjs.development.d.ts +0 -222
  28. package/dist/cjs/numeric-quantity.cjs.production.d.ts +0 -222
  29. package/dist/numeric-quantity.d.mts +0 -222
  30. package/dist/numeric-quantity.legacy-esm.d.mts +0 -222
  31. package/dist/numeric-quantity.production.d.mts +0 -222
  32. package/dist/numeric-quantity.umd.min.js +0 -2
  33. package/dist/numeric-quantity.umd.min.js.map +0 -1
@@ -1,222 +0,0 @@
1
- /**
2
- * Map of Unicode fraction code points to their ASCII equivalents.
3
- */
4
- declare const vulgarFractionToAsciiMap: {
5
- readonly '\u00BC': "1/4";
6
- readonly '\u00BD': "1/2";
7
- readonly '\u00BE': "3/4";
8
- readonly '\u2150': "1/7";
9
- readonly '\u2151': "1/9";
10
- readonly '\u2152': "1/10";
11
- readonly '\u2153': "1/3";
12
- readonly '\u2154': "2/3";
13
- readonly '\u2155': "1/5";
14
- readonly '\u2156': "2/5";
15
- readonly '\u2157': "3/5";
16
- readonly '\u2158': "4/5";
17
- readonly '\u2159': "1/6";
18
- readonly '\u215A': "5/6";
19
- readonly '\u215B': "1/8";
20
- readonly '\u215C': "3/8";
21
- readonly '\u215D': "5/8";
22
- readonly '\u215E': "7/8";
23
- readonly '\u215F': "1/";
24
- };
25
- /**
26
- * Captures the individual elements of a numeric string.
27
- *
28
- * Capture groups:
29
- *
30
- * | # | Description | Example(s) |
31
- * | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
32
- * | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
33
- * | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
34
- * | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
35
- * | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
36
- *
37
- * _Capture group 2 may include comma/underscore separators._
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * numericRegex.exec("1") // [ "1", "1", null, null ]
43
- * numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
44
- * numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
45
- * numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
46
- * numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
47
- * ```
48
- */
49
- declare const numericRegex: RegExp;
50
- /**
51
- * Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
52
- */
53
- declare const numericRegexWithTrailingInvalid: RegExp;
54
- /**
55
- * Captures any Unicode vulgar fractions.
56
- */
57
- declare const vulgarFractionsRegex: RegExp;
58
- /**
59
- * Map of Roman numeral sequences to their decimal equivalents.
60
- */
61
- declare const romanNumeralValues: {
62
- readonly MMM: 3000;
63
- readonly MM: 2000;
64
- readonly M: 1000;
65
- readonly CM: 900;
66
- readonly DCCC: 800;
67
- readonly DCC: 700;
68
- readonly DC: 600;
69
- readonly D: 500;
70
- readonly CD: 400;
71
- readonly CCC: 300;
72
- readonly CC: 200;
73
- readonly C: 100;
74
- readonly XC: 90;
75
- readonly LXXX: 80;
76
- readonly LXX: 70;
77
- readonly LX: 60;
78
- readonly L: 50;
79
- readonly XL: 40;
80
- readonly XXX: 30;
81
- readonly XX: 20;
82
- readonly XII: 12;
83
- readonly XI: 11;
84
- readonly X: 10;
85
- readonly IX: 9;
86
- readonly VIII: 8;
87
- readonly VII: 7;
88
- readonly VI: 6;
89
- readonly V: 5;
90
- readonly IV: 4;
91
- readonly III: 3;
92
- readonly II: 2;
93
- readonly I: 1;
94
- };
95
- /**
96
- * Map of Unicode Roman numeral code points to their ASCII equivalents.
97
- */
98
- declare const romanNumeralUnicodeToAsciiMap: {
99
- readonly Ⅰ: "I";
100
- readonly Ⅱ: "II";
101
- readonly Ⅲ: "III";
102
- readonly Ⅳ: "IV";
103
- readonly Ⅴ: "V";
104
- readonly Ⅵ: "VI";
105
- readonly Ⅶ: "VII";
106
- readonly Ⅷ: "VIII";
107
- readonly Ⅸ: "IX";
108
- readonly Ⅹ: "X";
109
- readonly Ⅺ: "XI";
110
- readonly Ⅻ: "XII";
111
- readonly Ⅼ: "L";
112
- readonly Ⅽ: "C";
113
- readonly Ⅾ: "D";
114
- readonly Ⅿ: "M";
115
- readonly ⅰ: "I";
116
- readonly ⅱ: "II";
117
- readonly ⅲ: "III";
118
- readonly ⅳ: "IV";
119
- readonly ⅴ: "V";
120
- readonly ⅵ: "VI";
121
- readonly ⅶ: "VII";
122
- readonly ⅷ: "VIII";
123
- readonly ⅸ: "IX";
124
- readonly ⅹ: "X";
125
- readonly ⅺ: "XI";
126
- readonly ⅻ: "XII";
127
- readonly ⅼ: "L";
128
- readonly ⅽ: "C";
129
- readonly ⅾ: "D";
130
- readonly ⅿ: "M";
131
- };
132
- /**
133
- * Captures all Unicode Roman numeral code points.
134
- */
135
- declare const romanNumeralUnicodeRegex: RegExp;
136
- /**
137
- * Captures a valid Roman numeral sequence.
138
- *
139
- * Capture groups:
140
- *
141
- * | # | Description | Example |
142
- * | --- | --------------- | ------------------------ |
143
- * | `0` | Entire string | "MCCXIV" from "MCCXIV" |
144
- * | `1` | Thousands | "M" from "MCCXIV" |
145
- * | `2` | Hundreds | "CC" from "MCCXIV" |
146
- * | `3` | Tens | "X" from "MCCXIV" |
147
- * | `4` | Ones | "IV" from "MCCXIV" |
148
- *
149
- * @example
150
- *
151
- * ```ts
152
- * romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
153
- * romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
154
- * romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
155
- * ```
156
- */
157
- declare const romanNumeralRegex: RegExp;
158
- /**
159
- * Default options for {@link numericQuantity}.
160
- */
161
- declare const defaultOptions: {
162
- round: number;
163
- allowTrailingInvalid: false;
164
- romanNumerals: false;
165
- };
166
-
167
- interface NumericQuantityOptions {
168
- /**
169
- * Round the result to this many decimal places. Defaults to 3; must
170
- * be greater than or equal to zero.
171
- *
172
- * @default 3
173
- */
174
- round?: number | false;
175
- /**
176
- * Allow and ignore trailing invalid characters _à la_ `parseFloat`.
177
- *
178
- * @default false
179
- */
180
- allowTrailingInvalid?: boolean;
181
- /**
182
- * Attempt to parse Roman numerals if Arabic numeral parsing fails.
183
- *
184
- * @default false
185
- */
186
- romanNumerals?: boolean;
187
- }
188
- /**
189
- * Unicode vulgar fraction code points.
190
- */
191
- type VulgarFraction = '¼' | '½' | '¾' | '⅐' | '⅑' | '⅒' | '⅓' | '⅔' | '⅕' | '⅖' | '⅗' | '⅘' | '⅙' | '⅚' | '⅛' | '⅜' | '⅝' | '⅞' | '⅟';
192
- /**
193
- * Allowable Roman numeral characters (ASCII, uppercase only).
194
- */
195
- type RomanNumeralAscii = 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M';
196
- /**
197
- * Unicode Roman numeral code points (uppercase and lowercase,
198
- * representing 1-12, 50, 100, 500, and 1000).
199
- */
200
- type RomanNumeralUnicode = 'Ⅰ' | 'Ⅱ' | 'Ⅲ' | 'Ⅳ' | 'Ⅴ' | 'Ⅵ' | 'Ⅶ' | 'Ⅷ' | 'Ⅸ' | 'Ⅹ' | 'Ⅺ' | 'Ⅻ' | 'Ⅼ' | 'Ⅽ' | 'Ⅾ' | 'Ⅿ' | 'ⅰ' | 'ⅱ' | 'ⅲ' | 'ⅳ' | 'ⅴ' | 'ⅵ' | 'ⅶ' | 'ⅷ' | 'ⅸ' | 'ⅹ' | 'ⅺ' | 'ⅻ' | 'ⅼ' | 'ⅽ' | 'ⅾ' | 'ⅿ';
201
- /**
202
- * Union of ASCII and Unicode Roman numeral characters/code points.
203
- */
204
- type RomanNumeral = RomanNumeralAscii | RomanNumeralUnicode;
205
-
206
- /**
207
- * Converts a string to a number, like an enhanced version of `parseFloat`.
208
- *
209
- * The string can include mixed numbers, vulgar fractions, or Roman numerals.
210
- */
211
- declare const numericQuantity: (quantity: string | number, options?: NumericQuantityOptions) => number;
212
-
213
- /**
214
- * Converts a string of Roman numerals to a number, like `parseInt`
215
- * for Roman numerals. Uses modern, strict rules (only 1 to 3999).
216
- *
217
- * The string can include ASCII representations of Roman numerals
218
- * or Unicode Roman numeral code points (`U+2160` through `U+217F`).
219
- */
220
- declare const parseRomanNumerals: (romanNumerals: string) => number;
221
-
222
- export { type NumericQuantityOptions, type RomanNumeral, type RomanNumeralAscii, type RomanNumeralUnicode, type VulgarFraction, defaultOptions, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };
@@ -1,222 +0,0 @@
1
- /**
2
- * Map of Unicode fraction code points to their ASCII equivalents.
3
- */
4
- declare const vulgarFractionToAsciiMap: {
5
- readonly '\u00BC': "1/4";
6
- readonly '\u00BD': "1/2";
7
- readonly '\u00BE': "3/4";
8
- readonly '\u2150': "1/7";
9
- readonly '\u2151': "1/9";
10
- readonly '\u2152': "1/10";
11
- readonly '\u2153': "1/3";
12
- readonly '\u2154': "2/3";
13
- readonly '\u2155': "1/5";
14
- readonly '\u2156': "2/5";
15
- readonly '\u2157': "3/5";
16
- readonly '\u2158': "4/5";
17
- readonly '\u2159': "1/6";
18
- readonly '\u215A': "5/6";
19
- readonly '\u215B': "1/8";
20
- readonly '\u215C': "3/8";
21
- readonly '\u215D': "5/8";
22
- readonly '\u215E': "7/8";
23
- readonly '\u215F': "1/";
24
- };
25
- /**
26
- * Captures the individual elements of a numeric string.
27
- *
28
- * Capture groups:
29
- *
30
- * | # | Description | Example(s) |
31
- * | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
32
- * | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
33
- * | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
34
- * | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
35
- * | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
36
- *
37
- * _Capture group 2 may include comma/underscore separators._
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * numericRegex.exec("1") // [ "1", "1", null, null ]
43
- * numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
44
- * numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
45
- * numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
46
- * numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
47
- * ```
48
- */
49
- declare const numericRegex: RegExp;
50
- /**
51
- * Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
52
- */
53
- declare const numericRegexWithTrailingInvalid: RegExp;
54
- /**
55
- * Captures any Unicode vulgar fractions.
56
- */
57
- declare const vulgarFractionsRegex: RegExp;
58
- /**
59
- * Map of Roman numeral sequences to their decimal equivalents.
60
- */
61
- declare const romanNumeralValues: {
62
- readonly MMM: 3000;
63
- readonly MM: 2000;
64
- readonly M: 1000;
65
- readonly CM: 900;
66
- readonly DCCC: 800;
67
- readonly DCC: 700;
68
- readonly DC: 600;
69
- readonly D: 500;
70
- readonly CD: 400;
71
- readonly CCC: 300;
72
- readonly CC: 200;
73
- readonly C: 100;
74
- readonly XC: 90;
75
- readonly LXXX: 80;
76
- readonly LXX: 70;
77
- readonly LX: 60;
78
- readonly L: 50;
79
- readonly XL: 40;
80
- readonly XXX: 30;
81
- readonly XX: 20;
82
- readonly XII: 12;
83
- readonly XI: 11;
84
- readonly X: 10;
85
- readonly IX: 9;
86
- readonly VIII: 8;
87
- readonly VII: 7;
88
- readonly VI: 6;
89
- readonly V: 5;
90
- readonly IV: 4;
91
- readonly III: 3;
92
- readonly II: 2;
93
- readonly I: 1;
94
- };
95
- /**
96
- * Map of Unicode Roman numeral code points to their ASCII equivalents.
97
- */
98
- declare const romanNumeralUnicodeToAsciiMap: {
99
- readonly Ⅰ: "I";
100
- readonly Ⅱ: "II";
101
- readonly Ⅲ: "III";
102
- readonly Ⅳ: "IV";
103
- readonly Ⅴ: "V";
104
- readonly Ⅵ: "VI";
105
- readonly Ⅶ: "VII";
106
- readonly Ⅷ: "VIII";
107
- readonly Ⅸ: "IX";
108
- readonly Ⅹ: "X";
109
- readonly Ⅺ: "XI";
110
- readonly Ⅻ: "XII";
111
- readonly Ⅼ: "L";
112
- readonly Ⅽ: "C";
113
- readonly Ⅾ: "D";
114
- readonly Ⅿ: "M";
115
- readonly ⅰ: "I";
116
- readonly ⅱ: "II";
117
- readonly ⅲ: "III";
118
- readonly ⅳ: "IV";
119
- readonly ⅴ: "V";
120
- readonly ⅵ: "VI";
121
- readonly ⅶ: "VII";
122
- readonly ⅷ: "VIII";
123
- readonly ⅸ: "IX";
124
- readonly ⅹ: "X";
125
- readonly ⅺ: "XI";
126
- readonly ⅻ: "XII";
127
- readonly ⅼ: "L";
128
- readonly ⅽ: "C";
129
- readonly ⅾ: "D";
130
- readonly ⅿ: "M";
131
- };
132
- /**
133
- * Captures all Unicode Roman numeral code points.
134
- */
135
- declare const romanNumeralUnicodeRegex: RegExp;
136
- /**
137
- * Captures a valid Roman numeral sequence.
138
- *
139
- * Capture groups:
140
- *
141
- * | # | Description | Example |
142
- * | --- | --------------- | ------------------------ |
143
- * | `0` | Entire string | "MCCXIV" from "MCCXIV" |
144
- * | `1` | Thousands | "M" from "MCCXIV" |
145
- * | `2` | Hundreds | "CC" from "MCCXIV" |
146
- * | `3` | Tens | "X" from "MCCXIV" |
147
- * | `4` | Ones | "IV" from "MCCXIV" |
148
- *
149
- * @example
150
- *
151
- * ```ts
152
- * romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
153
- * romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
154
- * romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
155
- * ```
156
- */
157
- declare const romanNumeralRegex: RegExp;
158
- /**
159
- * Default options for {@link numericQuantity}.
160
- */
161
- declare const defaultOptions: {
162
- round: number;
163
- allowTrailingInvalid: false;
164
- romanNumerals: false;
165
- };
166
-
167
- interface NumericQuantityOptions {
168
- /**
169
- * Round the result to this many decimal places. Defaults to 3; must
170
- * be greater than or equal to zero.
171
- *
172
- * @default 3
173
- */
174
- round?: number | false;
175
- /**
176
- * Allow and ignore trailing invalid characters _à la_ `parseFloat`.
177
- *
178
- * @default false
179
- */
180
- allowTrailingInvalid?: boolean;
181
- /**
182
- * Attempt to parse Roman numerals if Arabic numeral parsing fails.
183
- *
184
- * @default false
185
- */
186
- romanNumerals?: boolean;
187
- }
188
- /**
189
- * Unicode vulgar fraction code points.
190
- */
191
- type VulgarFraction = '¼' | '½' | '¾' | '⅐' | '⅑' | '⅒' | '⅓' | '⅔' | '⅕' | '⅖' | '⅗' | '⅘' | '⅙' | '⅚' | '⅛' | '⅜' | '⅝' | '⅞' | '⅟';
192
- /**
193
- * Allowable Roman numeral characters (ASCII, uppercase only).
194
- */
195
- type RomanNumeralAscii = 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M';
196
- /**
197
- * Unicode Roman numeral code points (uppercase and lowercase,
198
- * representing 1-12, 50, 100, 500, and 1000).
199
- */
200
- type RomanNumeralUnicode = 'Ⅰ' | 'Ⅱ' | 'Ⅲ' | 'Ⅳ' | 'Ⅴ' | 'Ⅵ' | 'Ⅶ' | 'Ⅷ' | 'Ⅸ' | 'Ⅹ' | 'Ⅺ' | 'Ⅻ' | 'Ⅼ' | 'Ⅽ' | 'Ⅾ' | 'Ⅿ' | 'ⅰ' | 'ⅱ' | 'ⅲ' | 'ⅳ' | 'ⅴ' | 'ⅵ' | 'ⅶ' | 'ⅷ' | 'ⅸ' | 'ⅹ' | 'ⅺ' | 'ⅻ' | 'ⅼ' | 'ⅽ' | 'ⅾ' | 'ⅿ';
201
- /**
202
- * Union of ASCII and Unicode Roman numeral characters/code points.
203
- */
204
- type RomanNumeral = RomanNumeralAscii | RomanNumeralUnicode;
205
-
206
- /**
207
- * Converts a string to a number, like an enhanced version of `parseFloat`.
208
- *
209
- * The string can include mixed numbers, vulgar fractions, or Roman numerals.
210
- */
211
- declare const numericQuantity: (quantity: string | number, options?: NumericQuantityOptions) => number;
212
-
213
- /**
214
- * Converts a string of Roman numerals to a number, like `parseInt`
215
- * for Roman numerals. Uses modern, strict rules (only 1 to 3999).
216
- *
217
- * The string can include ASCII representations of Roman numerals
218
- * or Unicode Roman numeral code points (`U+2160` through `U+217F`).
219
- */
220
- declare const parseRomanNumerals: (romanNumerals: string) => number;
221
-
222
- export { type NumericQuantityOptions, type RomanNumeral, type RomanNumeralAscii, type RomanNumeralUnicode, type VulgarFraction, defaultOptions, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };
@@ -1,222 +0,0 @@
1
- /**
2
- * Map of Unicode fraction code points to their ASCII equivalents.
3
- */
4
- declare const vulgarFractionToAsciiMap: {
5
- readonly '\u00BC': "1/4";
6
- readonly '\u00BD': "1/2";
7
- readonly '\u00BE': "3/4";
8
- readonly '\u2150': "1/7";
9
- readonly '\u2151': "1/9";
10
- readonly '\u2152': "1/10";
11
- readonly '\u2153': "1/3";
12
- readonly '\u2154': "2/3";
13
- readonly '\u2155': "1/5";
14
- readonly '\u2156': "2/5";
15
- readonly '\u2157': "3/5";
16
- readonly '\u2158': "4/5";
17
- readonly '\u2159': "1/6";
18
- readonly '\u215A': "5/6";
19
- readonly '\u215B': "1/8";
20
- readonly '\u215C': "3/8";
21
- readonly '\u215D': "5/8";
22
- readonly '\u215E': "7/8";
23
- readonly '\u215F': "1/";
24
- };
25
- /**
26
- * Captures the individual elements of a numeric string.
27
- *
28
- * Capture groups:
29
- *
30
- * | # | Description | Example(s) |
31
- * | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
32
- * | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
33
- * | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
34
- * | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
35
- * | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
36
- *
37
- * _Capture group 2 may include comma/underscore separators._
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * numericRegex.exec("1") // [ "1", "1", null, null ]
43
- * numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
44
- * numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
45
- * numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
46
- * numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
47
- * ```
48
- */
49
- declare const numericRegex: RegExp;
50
- /**
51
- * Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
52
- */
53
- declare const numericRegexWithTrailingInvalid: RegExp;
54
- /**
55
- * Captures any Unicode vulgar fractions.
56
- */
57
- declare const vulgarFractionsRegex: RegExp;
58
- /**
59
- * Map of Roman numeral sequences to their decimal equivalents.
60
- */
61
- declare const romanNumeralValues: {
62
- readonly MMM: 3000;
63
- readonly MM: 2000;
64
- readonly M: 1000;
65
- readonly CM: 900;
66
- readonly DCCC: 800;
67
- readonly DCC: 700;
68
- readonly DC: 600;
69
- readonly D: 500;
70
- readonly CD: 400;
71
- readonly CCC: 300;
72
- readonly CC: 200;
73
- readonly C: 100;
74
- readonly XC: 90;
75
- readonly LXXX: 80;
76
- readonly LXX: 70;
77
- readonly LX: 60;
78
- readonly L: 50;
79
- readonly XL: 40;
80
- readonly XXX: 30;
81
- readonly XX: 20;
82
- readonly XII: 12;
83
- readonly XI: 11;
84
- readonly X: 10;
85
- readonly IX: 9;
86
- readonly VIII: 8;
87
- readonly VII: 7;
88
- readonly VI: 6;
89
- readonly V: 5;
90
- readonly IV: 4;
91
- readonly III: 3;
92
- readonly II: 2;
93
- readonly I: 1;
94
- };
95
- /**
96
- * Map of Unicode Roman numeral code points to their ASCII equivalents.
97
- */
98
- declare const romanNumeralUnicodeToAsciiMap: {
99
- readonly Ⅰ: "I";
100
- readonly Ⅱ: "II";
101
- readonly Ⅲ: "III";
102
- readonly Ⅳ: "IV";
103
- readonly Ⅴ: "V";
104
- readonly Ⅵ: "VI";
105
- readonly Ⅶ: "VII";
106
- readonly Ⅷ: "VIII";
107
- readonly Ⅸ: "IX";
108
- readonly Ⅹ: "X";
109
- readonly Ⅺ: "XI";
110
- readonly Ⅻ: "XII";
111
- readonly Ⅼ: "L";
112
- readonly Ⅽ: "C";
113
- readonly Ⅾ: "D";
114
- readonly Ⅿ: "M";
115
- readonly ⅰ: "I";
116
- readonly ⅱ: "II";
117
- readonly ⅲ: "III";
118
- readonly ⅳ: "IV";
119
- readonly ⅴ: "V";
120
- readonly ⅵ: "VI";
121
- readonly ⅶ: "VII";
122
- readonly ⅷ: "VIII";
123
- readonly ⅸ: "IX";
124
- readonly ⅹ: "X";
125
- readonly ⅺ: "XI";
126
- readonly ⅻ: "XII";
127
- readonly ⅼ: "L";
128
- readonly ⅽ: "C";
129
- readonly ⅾ: "D";
130
- readonly ⅿ: "M";
131
- };
132
- /**
133
- * Captures all Unicode Roman numeral code points.
134
- */
135
- declare const romanNumeralUnicodeRegex: RegExp;
136
- /**
137
- * Captures a valid Roman numeral sequence.
138
- *
139
- * Capture groups:
140
- *
141
- * | # | Description | Example |
142
- * | --- | --------------- | ------------------------ |
143
- * | `0` | Entire string | "MCCXIV" from "MCCXIV" |
144
- * | `1` | Thousands | "M" from "MCCXIV" |
145
- * | `2` | Hundreds | "CC" from "MCCXIV" |
146
- * | `3` | Tens | "X" from "MCCXIV" |
147
- * | `4` | Ones | "IV" from "MCCXIV" |
148
- *
149
- * @example
150
- *
151
- * ```ts
152
- * romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
153
- * romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
154
- * romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
155
- * ```
156
- */
157
- declare const romanNumeralRegex: RegExp;
158
- /**
159
- * Default options for {@link numericQuantity}.
160
- */
161
- declare const defaultOptions: {
162
- round: number;
163
- allowTrailingInvalid: false;
164
- romanNumerals: false;
165
- };
166
-
167
- interface NumericQuantityOptions {
168
- /**
169
- * Round the result to this many decimal places. Defaults to 3; must
170
- * be greater than or equal to zero.
171
- *
172
- * @default 3
173
- */
174
- round?: number | false;
175
- /**
176
- * Allow and ignore trailing invalid characters _à la_ `parseFloat`.
177
- *
178
- * @default false
179
- */
180
- allowTrailingInvalid?: boolean;
181
- /**
182
- * Attempt to parse Roman numerals if Arabic numeral parsing fails.
183
- *
184
- * @default false
185
- */
186
- romanNumerals?: boolean;
187
- }
188
- /**
189
- * Unicode vulgar fraction code points.
190
- */
191
- type VulgarFraction = '¼' | '½' | '¾' | '⅐' | '⅑' | '⅒' | '⅓' | '⅔' | '⅕' | '⅖' | '⅗' | '⅘' | '⅙' | '⅚' | '⅛' | '⅜' | '⅝' | '⅞' | '⅟';
192
- /**
193
- * Allowable Roman numeral characters (ASCII, uppercase only).
194
- */
195
- type RomanNumeralAscii = 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M';
196
- /**
197
- * Unicode Roman numeral code points (uppercase and lowercase,
198
- * representing 1-12, 50, 100, 500, and 1000).
199
- */
200
- type RomanNumeralUnicode = 'Ⅰ' | 'Ⅱ' | 'Ⅲ' | 'Ⅳ' | 'Ⅴ' | 'Ⅵ' | 'Ⅶ' | 'Ⅷ' | 'Ⅸ' | 'Ⅹ' | 'Ⅺ' | 'Ⅻ' | 'Ⅼ' | 'Ⅽ' | 'Ⅾ' | 'Ⅿ' | 'ⅰ' | 'ⅱ' | 'ⅲ' | 'ⅳ' | 'ⅴ' | 'ⅵ' | 'ⅶ' | 'ⅷ' | 'ⅸ' | 'ⅹ' | 'ⅺ' | 'ⅻ' | 'ⅼ' | 'ⅽ' | 'ⅾ' | 'ⅿ';
201
- /**
202
- * Union of ASCII and Unicode Roman numeral characters/code points.
203
- */
204
- type RomanNumeral = RomanNumeralAscii | RomanNumeralUnicode;
205
-
206
- /**
207
- * Converts a string to a number, like an enhanced version of `parseFloat`.
208
- *
209
- * The string can include mixed numbers, vulgar fractions, or Roman numerals.
210
- */
211
- declare const numericQuantity: (quantity: string | number, options?: NumericQuantityOptions) => number;
212
-
213
- /**
214
- * Converts a string of Roman numerals to a number, like `parseInt`
215
- * for Roman numerals. Uses modern, strict rules (only 1 to 3999).
216
- *
217
- * The string can include ASCII representations of Roman numerals
218
- * or Unicode Roman numeral code points (`U+2160` through `U+217F`).
219
- */
220
- declare const parseRomanNumerals: (romanNumerals: string) => number;
221
-
222
- export { type NumericQuantityOptions, type RomanNumeral, type RomanNumeralAscii, type RomanNumeralUnicode, type VulgarFraction, defaultOptions, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };