numeric-quantity 3.0.0 → 3.2.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 (32) hide show
  1. package/README.md +173 -16
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/numeric-quantity.cjs.development.d.ts +225 -0
  4. package/dist/cjs/numeric-quantity.cjs.development.js +208 -18
  5. package/dist/cjs/numeric-quantity.cjs.development.js.map +1 -1
  6. package/dist/cjs/numeric-quantity.cjs.production.d.ts +225 -0
  7. package/dist/cjs/numeric-quantity.cjs.production.js +1 -1
  8. package/dist/cjs/numeric-quantity.cjs.production.js.map +1 -1
  9. package/dist/numeric-quantity.d.mts +225 -0
  10. package/dist/numeric-quantity.iife.umd.min.js +1 -1
  11. package/dist/numeric-quantity.iife.umd.min.js.map +1 -1
  12. package/dist/numeric-quantity.legacy-esm.d.ts +225 -0
  13. package/dist/numeric-quantity.legacy-esm.js +221 -37
  14. package/dist/numeric-quantity.legacy-esm.js.map +1 -1
  15. package/dist/numeric-quantity.mjs +206 -19
  16. package/dist/numeric-quantity.mjs.map +1 -1
  17. package/dist/numeric-quantity.production.d.mts +225 -0
  18. package/dist/numeric-quantity.production.mjs +1 -1
  19. package/dist/numeric-quantity.production.mjs.map +1 -1
  20. package/package.json +13 -14
  21. package/dist/types/constants.d.ts +0 -79
  22. package/dist/types/dev.d.ts +0 -1
  23. package/dist/types/index.d.ts +0 -4
  24. package/dist/types/numericQuantity.d.ts +0 -12
  25. package/dist/types/parseRomanNumerals.d.ts +0 -8
  26. package/dist/types/types.d.ts +0 -49
  27. package/dist/types-esm/constants.d.mts +0 -79
  28. package/dist/types-esm/dev.d.mts +0 -1
  29. package/dist/types-esm/index.d.mts +0 -4
  30. package/dist/types-esm/numericQuantity.d.mts +0 -12
  31. package/dist/types-esm/parseRomanNumerals.d.mts +0 -8
  32. package/dist/types-esm/types.d.mts +0 -49
@@ -1,79 +0,0 @@
1
- import type { NumericQuantityOptions, RomanNumeralAscii, RomanNumeralUnicode, VulgarFraction } from "./types.mjs";
2
- /**
3
- * Map of Unicode fraction code points to their ASCII equivalents.
4
- */
5
- export declare const vulgarFractionToAsciiMap: Record<VulgarFraction, `${number}/${number | ""}`>;
6
- /**
7
- * Captures the individual elements of a numeric string. Commas and underscores are allowed
8
- * as separators, as long as they appear between digits and are not consecutive.
9
- *
10
- * Capture groups:
11
- *
12
- * | # | Description | Example(s) |
13
- * | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
14
- * | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
15
- * | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
16
- * | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
17
- * | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
18
- *
19
- * _Capture group 2 may include comma/underscore separators._
20
- *
21
- * @example
22
- *
23
- * ```ts
24
- * numericRegex.exec("1") // [ "1", "1", null, null ]
25
- * numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
26
- * numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
27
- * numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
28
- * numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
29
- * ```
30
- */
31
- export declare const numericRegex: RegExp;
32
- /**
33
- * Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
34
- */
35
- export declare const numericRegexWithTrailingInvalid: RegExp;
36
- /**
37
- * Captures any Unicode vulgar fractions.
38
- */
39
- export declare const vulgarFractionsRegex: RegExp;
40
- type RomanNumeralSequenceFragment = `${RomanNumeralAscii}` | `${RomanNumeralAscii}${RomanNumeralAscii}` | `${RomanNumeralAscii}${RomanNumeralAscii}${RomanNumeralAscii}` | `${RomanNumeralAscii}${RomanNumeralAscii}${RomanNumeralAscii}${RomanNumeralAscii}`;
41
- /**
42
- * Map of Roman numeral sequences to their decimal equivalents.
43
- */
44
- export declare const romanNumeralValues: { [k in RomanNumeralSequenceFragment]? : number };
45
- /**
46
- * Map of Unicode Roman numeral code points to their ASCII equivalents.
47
- */
48
- export declare const romanNumeralUnicodeToAsciiMap: Record<RomanNumeralUnicode, keyof typeof romanNumeralValues>;
49
- /**
50
- * Captures all Unicode Roman numeral code points.
51
- */
52
- export declare const romanNumeralUnicodeRegex: RegExp;
53
- /**
54
- * Captures a valid Roman numeral sequence.
55
- *
56
- * Capture groups:
57
- *
58
- * | # | Description | Example |
59
- * | --- | --------------- | ------------------------ |
60
- * | `0` | Entire string | "MCCXIV" from "MCCXIV" |
61
- * | `1` | Thousands | "M" from "MCCXIV" |
62
- * | `2` | Hundreds | "CC" from "MCCXIV" |
63
- * | `3` | Tens | "X" from "MCCXIV" |
64
- * | `4` | Ones | "IV" from "MCCXIV" |
65
- *
66
- * @example
67
- *
68
- * ```ts
69
- * romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
70
- * romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
71
- * romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
72
- * ```
73
- */
74
- export declare const romanNumeralRegex: RegExp;
75
- /**
76
- * Default options for {@link numericQuantity}.
77
- */
78
- export declare const defaultOptions: Required<NumericQuantityOptions>;
79
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export * from "./constants.mjs";
2
- export * from "./numericQuantity.mjs";
3
- export * from "./parseRomanNumerals.mjs";
4
- export * from "./types.mjs";
@@ -1,12 +0,0 @@
1
- import type { NumericQuantityOptions } from "./types.mjs";
2
- /**
3
- * Converts a string to a number, like an enhanced version of `parseFloat`.
4
- *
5
- * The string can include mixed numbers, vulgar fractions, or Roman numerals.
6
- */
7
- declare function numericQuantity(quantity: string | number): number;
8
- declare function numericQuantity(quantity: string | number, options: NumericQuantityOptions & {
9
- bigIntOnOverflow: true
10
- }): number | bigint;
11
- declare function numericQuantity(quantity: string | number, options?: NumericQuantityOptions): number;
12
- export { numericQuantity };
@@ -1,8 +0,0 @@
1
- /**
2
- * Converts a string of Roman numerals to a number, like `parseInt`
3
- * for Roman numerals. Uses modern, strict rules (only 1 to 3999).
4
- *
5
- * The string can include ASCII representations of Roman numerals
6
- * or Unicode Roman numeral code points (`U+2160` through `U+217F`).
7
- */
8
- export declare const parseRomanNumerals: (romanNumerals: string) => number;
@@ -1,49 +0,0 @@
1
- export interface NumericQuantityOptions {
2
- /**
3
- * Round the result to this many decimal places. Defaults to 3; must
4
- * be greater than or equal to zero.
5
- *
6
- * @default 3
7
- */
8
- round?: number | false;
9
- /**
10
- * Allow and ignore trailing invalid characters _à la_ `parseFloat`.
11
- *
12
- * @default false
13
- */
14
- allowTrailingInvalid?: boolean;
15
- /**
16
- * Attempt to parse Roman numerals if Arabic numeral parsing fails.
17
- *
18
- * @default false
19
- */
20
- romanNumerals?: boolean;
21
- /**
22
- * Generates a `bigint` value if the string represents
23
- * a valid integer too large for the `number` type.
24
- */
25
- bigIntOnOverflow?: boolean;
26
- /**
27
- * Specifies which character ("." or ",") to treat as the decimal separator.
28
- *
29
- * @default "."
30
- */
31
- decimalSeparator?: "," | ".";
32
- }
33
- /**
34
- * Unicode vulgar fraction code points.
35
- */
36
- export type VulgarFraction = "¼" | "½" | "¾" | "⅐" | "⅑" | "⅒" | "⅓" | "⅔" | "⅕" | "⅖" | "⅗" | "⅘" | "⅙" | "⅚" | "⅛" | "⅜" | "⅝" | "⅞" | "⅟";
37
- /**
38
- * Allowable Roman numeral characters (ASCII, uppercase only).
39
- */
40
- export type RomanNumeralAscii = "I" | "V" | "X" | "L" | "C" | "D" | "M";
41
- /**
42
- * Unicode Roman numeral code points (uppercase and lowercase,
43
- * representing 1-12, 50, 100, 500, and 1000).
44
- */
45
- export type RomanNumeralUnicode = "Ⅰ" | "Ⅱ" | "Ⅲ" | "Ⅳ" | "Ⅴ" | "Ⅵ" | "Ⅶ" | "Ⅷ" | "Ⅸ" | "Ⅹ" | "Ⅺ" | "Ⅻ" | "Ⅼ" | "Ⅽ" | "Ⅾ" | "Ⅿ" | "ⅰ" | "ⅱ" | "ⅲ" | "ⅳ" | "ⅴ" | "ⅵ" | "ⅶ" | "ⅷ" | "ⅸ" | "ⅹ" | "ⅺ" | "ⅻ" | "ⅼ" | "ⅽ" | "ⅾ" | "ⅿ";
46
- /**
47
- * Union of ASCII and Unicode Roman numeral characters/code points.
48
- */
49
- export type RomanNumeral = RomanNumeralAscii | RomanNumeralUnicode;