format-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.
- package/README.md +79 -19
- package/dist/cjs/format-quantity.cjs.development.d.ts +97 -79
- package/dist/cjs/format-quantity.cjs.development.js +207 -181
- package/dist/cjs/format-quantity.cjs.development.js.map +1 -1
- package/dist/cjs/format-quantity.cjs.production.d.ts +97 -79
- package/dist/cjs/format-quantity.cjs.production.js +1 -1
- package/dist/cjs/format-quantity.cjs.production.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/format-quantity.d.mts +97 -79
- package/dist/format-quantity.legacy-esm.d.ts +131 -0
- package/dist/format-quantity.legacy-esm.js +262 -166
- package/dist/format-quantity.legacy-esm.js.map +1 -1
- package/dist/format-quantity.mjs +202 -151
- package/dist/format-quantity.mjs.map +1 -1
- package/dist/format-quantity.production.d.mts +97 -79
- package/dist/format-quantity.production.mjs +1 -1
- package/dist/format-quantity.production.mjs.map +1 -1
- package/dist/format-quantity.umd.min.js +2 -1
- package/dist/format-quantity.umd.min.js.map +1 -1
- package/package.json +28 -21
- package/dist/format-quantity.legacy-esm.d.mts +0 -113
|
@@ -1,188 +1,214 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
defaultOptions: () => defaultOptions,
|
|
24
|
-
defaultTolerance: () => defaultTolerance,
|
|
25
|
-
formatQuantity: () => formatQuantity,
|
|
26
|
-
fractionDecimalMatches: () => fractionDecimalMatches,
|
|
27
|
-
vulgarToAsciiMap: () => vulgarToAsciiMap
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let numeric_quantity = require("numeric-quantity");
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default tolerance used by {@link formatQuantity} when determining if a number
|
|
6
|
+
* is close enough to a fraction value to be considered equivalent.
|
|
7
|
+
*/
|
|
8
|
+
const defaultTolerance = .0075;
|
|
9
|
+
/**
|
|
10
|
+
* Default options for {@link formatQuantity}.
|
|
11
|
+
*/
|
|
12
|
+
const defaultOptions = Object.freeze({
|
|
13
|
+
vulgarFractions: false,
|
|
14
|
+
tolerance: defaultTolerance,
|
|
15
|
+
fractionSlash: false,
|
|
16
|
+
romanNumerals: false,
|
|
17
|
+
zeroFormat: "",
|
|
18
|
+
allowTrailingInvalid: true
|
|
28
19
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Map of vulgar fractions to their traditional ASCII equivalents.
|
|
22
|
+
*/
|
|
23
|
+
const vulgarToAsciiMap = Object.freeze({
|
|
24
|
+
"¼": "1/4",
|
|
25
|
+
"½": "1/2",
|
|
26
|
+
"¾": "3/4",
|
|
27
|
+
"⅐": "1/7",
|
|
28
|
+
"⅑": "1/9",
|
|
29
|
+
"⅒": "1/10",
|
|
30
|
+
"⅓": "1/3",
|
|
31
|
+
"⅔": "2/3",
|
|
32
|
+
"⅕": "1/5",
|
|
33
|
+
"⅖": "2/5",
|
|
34
|
+
"⅗": "3/5",
|
|
35
|
+
"⅘": "4/5",
|
|
36
|
+
"⅙": "1/6",
|
|
37
|
+
"⅚": "5/6",
|
|
38
|
+
"⅛": "1/8",
|
|
39
|
+
"⅜": "3/8",
|
|
40
|
+
"⅝": "5/8",
|
|
41
|
+
"⅞": "7/8"
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Map of "close enough" values to the {@link VulgarFraction} or {@link Sixteenth} fraction
|
|
45
|
+
* string matches. The value +/- the `tolerance` option (or {@link defaultTolerance} if not
|
|
46
|
+
* specified) is considered close enough to match the fraction.
|
|
47
|
+
*/
|
|
48
|
+
const fractionDecimalMatches = Object.freeze([
|
|
49
|
+
[1 / 16, "1/16"],
|
|
50
|
+
[1 / 10, "⅒"],
|
|
51
|
+
[1 / 9, "⅑"],
|
|
52
|
+
[1 / 8, "⅛"],
|
|
53
|
+
[1 / 7, "⅐"],
|
|
54
|
+
[1 / 6, "⅙"],
|
|
55
|
+
[3 / 16, "3/16"],
|
|
56
|
+
[1 / 5, "⅕"],
|
|
57
|
+
[1 / 4, "¼"],
|
|
58
|
+
[5 / 16, "5/16"],
|
|
59
|
+
[1 / 3, "⅓"],
|
|
60
|
+
[3 / 8, "⅜"],
|
|
61
|
+
[2 / 5, "⅖"],
|
|
62
|
+
[7 / 16, "7/16"],
|
|
63
|
+
[1 / 2, "½"],
|
|
64
|
+
[9 / 16, "9/16"],
|
|
65
|
+
[3 / 5, "⅗"],
|
|
66
|
+
[5 / 8, "⅝"],
|
|
67
|
+
[2 / 3, "⅔"],
|
|
68
|
+
[11 / 16, "11/16"],
|
|
69
|
+
[3 / 4, "¾"],
|
|
70
|
+
[4 / 5, "⅘"],
|
|
71
|
+
[13 / 16, "13/16"],
|
|
72
|
+
[5 / 6, "⅚"],
|
|
73
|
+
[7 / 8, "⅞"],
|
|
74
|
+
[15 / 16, "15/16"]
|
|
75
|
+
].map((entry) => Object.freeze(entry)));
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/formatQuantity.ts
|
|
78
|
+
const superscriptDigits = "⁰¹²³⁴⁵⁶⁷⁸⁹";
|
|
79
|
+
const subscriptDigits = "₀₁₂₃₄₅₆₇₈₉";
|
|
80
|
+
const toSuperscript = (s) => [...s].map((c) => superscriptDigits[+c]).join("");
|
|
81
|
+
const toSubscript = (s) => [...s].map((c) => subscriptDigits[+c]).join("");
|
|
82
|
+
/**
|
|
83
|
+
* Applies the `vulgarFractions` or `fractionSlash` options as necessary.
|
|
84
|
+
*/
|
|
85
|
+
const getFraction = (vulgarFractionOrSixteenth, { fractionSlash, vulgarFractions }) => {
|
|
86
|
+
if (vulgarFractions) return vulgarFractionOrSixteenth;
|
|
87
|
+
const plainFraction = vulgarToAsciiMap[vulgarFractionOrSixteenth] ?? vulgarFractionOrSixteenth;
|
|
88
|
+
if (fractionSlash) {
|
|
89
|
+
const [num, den] = plainFraction.split("/");
|
|
90
|
+
return `${toSuperscript(num)}⁄${toSubscript(den)}`;
|
|
91
|
+
}
|
|
92
|
+
return plainFraction;
|
|
38
93
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"\u215E": "7/8"
|
|
94
|
+
/**
|
|
95
|
+
* Only `false` (matching disabled) or a non-negative number is a valid
|
|
96
|
+
* `tolerance`. Everything else—negative numbers, `NaN`, non-numbers,
|
|
97
|
+
* `null`, `undefined`—resolves to {@link defaultTolerance}.
|
|
98
|
+
*/
|
|
99
|
+
const isValidTolerance = (tolerance) => tolerance === false || typeof tolerance === "number" && tolerance >= 0;
|
|
100
|
+
/**
|
|
101
|
+
* Merges options object with default options, converting boolean to object if necessary.
|
|
102
|
+
*/
|
|
103
|
+
const normalizeOptions = (options) => {
|
|
104
|
+
const opts = {
|
|
105
|
+
...defaultOptions,
|
|
106
|
+
...typeof options === "boolean" ? { vulgarFractions: options } : typeof options === "object" && options !== null ? options : {}
|
|
107
|
+
};
|
|
108
|
+
if (!isValidTolerance(opts.tolerance)) opts.tolerance = defaultOptions.tolerance;
|
|
109
|
+
if (typeof opts.zeroFormat !== "string") opts.zeroFormat = defaultOptions.zeroFormat;
|
|
110
|
+
if (opts.allowTrailingInvalid !== false) opts.allowTrailingInvalid = true;
|
|
111
|
+
return opts;
|
|
58
112
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
113
|
+
const romanNumeralsByPlace = [
|
|
114
|
+
"",
|
|
115
|
+
"C",
|
|
116
|
+
"CC",
|
|
117
|
+
"CCC",
|
|
118
|
+
"CD",
|
|
119
|
+
"D",
|
|
120
|
+
"DC",
|
|
121
|
+
"DCC",
|
|
122
|
+
"DCCC",
|
|
123
|
+
"CM",
|
|
124
|
+
"",
|
|
125
|
+
"X",
|
|
126
|
+
"XX",
|
|
127
|
+
"XXX",
|
|
128
|
+
"XL",
|
|
129
|
+
"L",
|
|
130
|
+
"LX",
|
|
131
|
+
"LXX",
|
|
132
|
+
"LXXX",
|
|
133
|
+
"XC",
|
|
134
|
+
"",
|
|
135
|
+
"I",
|
|
136
|
+
"II",
|
|
137
|
+
"III",
|
|
138
|
+
"IV",
|
|
139
|
+
"V",
|
|
140
|
+
"VI",
|
|
141
|
+
"VII",
|
|
142
|
+
"VIII",
|
|
143
|
+
"IX"
|
|
86
144
|
];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Formats a number or bigint as Roman numerals. The number must be between
|
|
147
|
+
* 1 and 3999, inclusive; any other value—including non-numbers,
|
|
148
|
+
* `NaN`, and non-finite numbers—yields `null`.
|
|
149
|
+
*/
|
|
150
|
+
const formatRomanNumerals = (quantity) => {
|
|
151
|
+
if (typeof quantity !== "number" && typeof quantity !== "bigint" || !(quantity >= 1 && quantity < 4e3)) return null;
|
|
152
|
+
const qty = Number(quantity);
|
|
153
|
+
const digits = `${Math.floor(qty)}`.split("");
|
|
154
|
+
let roman = "";
|
|
155
|
+
let i = 3;
|
|
156
|
+
while (i--) roman = `${romanNumeralsByPlace[+digits.pop() + i * 10] || ""}${roman}`;
|
|
157
|
+
return `${Array(+digits.join("") + 1).join("M")}${roman}`;
|
|
99
158
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
let i = 3;
|
|
147
|
-
while (i--) {
|
|
148
|
-
roman = `${romanNumeralValueKey[+digits.pop() + i * 10] || ""}${roman}`;
|
|
149
|
-
}
|
|
150
|
-
return `${Array(+digits.join("") + 1).join("M")}${roman}`;
|
|
151
|
-
};
|
|
152
|
-
var formatQuantity = (qty, options = defaultOptions) => {
|
|
153
|
-
const qtyAsNumber = typeof qty === "string" ? parseFloat(qty) : qty;
|
|
154
|
-
if (isNaN(qtyAsNumber) || qtyAsNumber === null) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
if (qtyAsNumber === 0) {
|
|
158
|
-
return "";
|
|
159
|
-
}
|
|
160
|
-
const opts = normalizeOptions(options ?? defaultOptions);
|
|
161
|
-
if (opts.romanNumerals) {
|
|
162
|
-
return formatRomanNumerals(qtyAsNumber);
|
|
163
|
-
}
|
|
164
|
-
const absoluteValue = Math.abs(qtyAsNumber);
|
|
165
|
-
const flooredAbsVal = Math.floor(absoluteValue);
|
|
166
|
-
const flooredAbsValStr = `${qtyAsNumber < 0 ? "-" : ""}${flooredAbsVal === 0 ? "" : `${flooredAbsVal} `}`;
|
|
167
|
-
const decimalValue = absoluteValue - flooredAbsVal;
|
|
168
|
-
if (decimalValue === 0) {
|
|
169
|
-
return `${qtyAsNumber}`;
|
|
170
|
-
}
|
|
171
|
-
for (const [num, vf] of fractionDecimalMatches) {
|
|
172
|
-
if (closeEnough(decimalValue, num, opts.tolerance)) {
|
|
173
|
-
const fraction = getFraction(vf, opts);
|
|
174
|
-
const int = fraction in vulgarToAsciiMap ? flooredAbsValStr.trim() : flooredAbsValStr;
|
|
175
|
-
return `${int}${fraction}`;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return `${qtyAsNumber}`;
|
|
159
|
+
/**
|
|
160
|
+
* Formats a number (or string that appears to be a number)
|
|
161
|
+
* as one would see it written in imperial measurements, e.g.
|
|
162
|
+
* "1 1/2" instead of "1.5". To use vulgar fraction characters
|
|
163
|
+
* like "½", pass `true` as the second argument. For other options
|
|
164
|
+
* see {@link FormatQuantityOptions}.
|
|
165
|
+
*/
|
|
166
|
+
const formatQuantity = (qty, options) => {
|
|
167
|
+
if (typeof qty !== "number" && typeof qty !== "string" && typeof qty !== "bigint") return null;
|
|
168
|
+
const opts = normalizeOptions(options);
|
|
169
|
+
const qtyAsNumber = typeof qty !== "number" && typeof qty !== "bigint" ? (0, numeric_quantity.numericQuantity)(qty, {
|
|
170
|
+
allowTrailingInvalid: opts.allowTrailingInvalid,
|
|
171
|
+
romanNumerals: opts.romanNumerals,
|
|
172
|
+
bigIntOnOverflow: true,
|
|
173
|
+
round: false
|
|
174
|
+
}) : qty;
|
|
175
|
+
if (typeof qtyAsNumber === "number" && isNaN(qtyAsNumber)) return null;
|
|
176
|
+
if (Number(qtyAsNumber) === 0) return opts.zeroFormat;
|
|
177
|
+
if (opts.romanNumerals) return formatRomanNumerals(qtyAsNumber);
|
|
178
|
+
const absoluteValue = typeof qtyAsNumber === "bigint" ? qtyAsNumber < 0n ? -qtyAsNumber : qtyAsNumber : Math.abs(qtyAsNumber);
|
|
179
|
+
const flooredAbsVal = typeof absoluteValue === "bigint" ? absoluteValue : Math.floor(absoluteValue);
|
|
180
|
+
const wholeNumberStr = `${flooredAbsVal || ""}`;
|
|
181
|
+
const decimalValue = typeof absoluteValue === "bigint" ? 0 : absoluteValue - flooredAbsVal;
|
|
182
|
+
if (decimalValue === 0) return `${qtyAsNumber}`;
|
|
183
|
+
let closestMatch = null;
|
|
184
|
+
let closestMatchDiff = Infinity;
|
|
185
|
+
if (opts.tolerance !== false) for (const [num, vf] of fractionDecimalMatches) {
|
|
186
|
+
const diff = Math.abs(decimalValue - num);
|
|
187
|
+
if (diff < opts.tolerance || diff === 0) {
|
|
188
|
+
if (diff === 0) {
|
|
189
|
+
closestMatch = vf;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
if (diff < closestMatchDiff) {
|
|
193
|
+
closestMatch = vf;
|
|
194
|
+
closestMatchDiff = diff;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (closestMatch) {
|
|
199
|
+
const fraction = getFraction(closestMatch, opts);
|
|
200
|
+
const isVulgar = fraction in vulgarToAsciiMap;
|
|
201
|
+
const sep = wholeNumberStr ? opts.separator ?? (isVulgar ? "" : " ") : "";
|
|
202
|
+
return `${qtyAsNumber < 0 ? "-" : ""}${wholeNumberStr}${sep}${fraction}`;
|
|
203
|
+
}
|
|
204
|
+
return `${qtyAsNumber}`;
|
|
179
205
|
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
206
|
+
//#endregion
|
|
207
|
+
exports.defaultOptions = defaultOptions;
|
|
208
|
+
exports.defaultTolerance = defaultTolerance;
|
|
209
|
+
exports.formatQuantity = formatQuantity;
|
|
210
|
+
exports.formatRomanNumerals = formatRomanNumerals;
|
|
211
|
+
exports.fractionDecimalMatches = fractionDecimalMatches;
|
|
212
|
+
exports.vulgarToAsciiMap = vulgarToAsciiMap;
|
|
213
|
+
|
|
188
214
|
//# sourceMappingURL=format-quantity.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/constants.ts","../../src/formatQuantity.ts"],"sourcesContent":["import { formatQuantity } from './formatQuantity';\nexport * from './constants';\nexport * from './types';\nexport { formatQuantity };\n","import type {\n FormatQuantityOptions,\n SimpleFraction,\n Sixteenth,\n VulgarFraction,\n} from './types';\n\n/**\n * Default tolerance used by {@link formatQuantity} when determining if a number\n * is close enough to a fraction value to be considered equivalent.\n */\nexport const defaultTolerance = 0.0075 as const;\n\n/**\n * Default options for {@link formatQuantity}.\n */\nexport const defaultOptions = {\n vulgarFractions: false,\n tolerance: defaultTolerance,\n fractionSlash: false,\n romanNumerals: false,\n} as const satisfies Required<FormatQuantityOptions>;\n\n/**\n * Map of vulgar fractions to their traditional ASCII equivalents.\n */\nexport const vulgarToAsciiMap = {\n '¼': '1/4',\n '½': '1/2',\n '¾': '3/4',\n '⅐': '1/7',\n '⅑': '1/9',\n '⅒': '1/10',\n '⅓': '1/3',\n '⅔': '2/3',\n '⅕': '1/5',\n '⅖': '2/5',\n '⅗': '3/5',\n '⅘': '4/5',\n '⅙': '1/6',\n '⅚': '5/6',\n '⅛': '1/8',\n '⅜': '3/8',\n '⅝': '5/8',\n '⅞': '7/8',\n} as const satisfies Record<VulgarFraction, SimpleFraction>;\n\n/**\n * Map of \"close enough\" decimal values to the {@link VulgarFraction} or\n * {@link Sixteenth} fraction string matches.\n */\nexport const fractionDecimalMatches = [\n [0.33, '⅓'],\n [0.66, '⅔'],\n [0.2, '⅕'],\n [0.4, '⅖'],\n [0.6, '⅗'],\n [0.8, '⅘'],\n [0.166, '⅙'],\n [0.833, '⅚'],\n [0.143, '⅐'],\n [0.111, '⅑'],\n [0.1, '⅒'],\n [0.125, '⅛'],\n [0.25, '¼'],\n [0.375, '⅜'],\n [0.5, '½'],\n [0.625, '⅝'],\n [0.75, '¾'],\n [0.875, '⅞'],\n [0.0625, '1/16'],\n [0.1875, '3/16'],\n [0.3125, '5/16'],\n [0.4375, '7/16'],\n [0.5625, '9/16'],\n [0.6875, '11/16'],\n [0.8125, '13/16'],\n [0.9375, '15/16'],\n] satisfies [number, VulgarFraction | Sixteenth][];\n","import {\n defaultOptions,\n fractionDecimalMatches,\n vulgarToAsciiMap,\n} from './constants';\nimport type {\n FormatQuantity,\n FormatQuantityOptions,\n SimpleFraction,\n Sixteenth,\n VulgarFraction,\n} from './types';\n\n/**\n * Determines if two numbers are close enough to consider\n * them equal for the purposes of this package.\n */\nconst closeEnough = (n1: number, n2: number, tolerance: number) =>\n Math.abs(n1 - n2) < tolerance;\n\n/**\n * Applies the `vulgarFractions` or `fractionSlash` options as necessary.\n */\nconst getFraction = (\n vulgarFractionOrSixteenth: VulgarFraction | Sixteenth,\n { fractionSlash, vulgarFractions }: FormatQuantityOptions\n) => {\n if (vulgarFractions) {\n return vulgarFractionOrSixteenth;\n }\n\n const plainFraction: SimpleFraction =\n vulgarToAsciiMap[vulgarFractionOrSixteenth as VulgarFraction] ??\n vulgarFractionOrSixteenth;\n\n if (fractionSlash) {\n return plainFraction.replace('/', '⁄');\n }\n\n return plainFraction;\n};\n\n/**\n * Merges options object with default options, converting boolean to object if necessary.\n */\nconst normalizeOptions = (\n options: Parameters<FormatQuantity>[1]\n): Required<FormatQuantityOptions> => ({\n ...defaultOptions,\n ...(typeof options === 'boolean' ? { vulgarFractions: options } : options),\n});\n\n// prettier-ignore\nconst romanNumeralValueKey = [\n \"\", \"C\", \"CC\", \"CCC\", \"CD\", \"D\", \"DC\", \"DCC\", \"DCCC\", \"CM\",\n \"\", \"X\", \"XX\", \"XXX\", \"XL\", \"L\", \"LX\", \"LXX\", \"LXXX\", \"XC\",\n \"\", \"I\", \"II\", \"III\", \"IV\", \"V\", \"VI\", \"VII\", \"VIII\", \"IX\",\n] as const;\n\n/**\n * Formats a number as Roman numerals. The number must be between\n * 1 and 3999, inclusive.\n */\nexport const formatRomanNumerals = (qty: number) => {\n if (typeof qty !== 'number' || isNaN(qty)) {\n return null;\n }\n\n if (qty < 1 || qty >= 4000) {\n return '';\n }\n\n const floored = Math.floor(qty);\n\n const digits = `${floored}`.split('');\n let roman = '';\n let i = 3;\n while (i--) {\n roman = `${romanNumeralValueKey[+digits.pop()! + i * 10] || ''}${roman}`;\n }\n\n return `${Array(+digits.join('') + 1).join('M')}${roman}`;\n};\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fraction characters\n * like \"½\", pass `true` as the second argument. For other options\n * see {@link FormatQuantityOptions}.\n */\nexport const formatQuantity: FormatQuantity = (\n qty,\n options = defaultOptions\n) => {\n // TODO: use numericQuantity instead of parseFloat?\n const qtyAsNumber = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Return `null` if input is not number-like.\n if (isNaN(qtyAsNumber) || qtyAsNumber === null) {\n return null;\n }\n\n // Return an empty string if the value is zero.\n if (qtyAsNumber === 0) {\n return '';\n }\n\n // The default options parameter in the function signature only takes effect\n // if the parameter is `undefined`. The nullish coalescing operator below\n // covers the `null` case.\n const opts = normalizeOptions(options ?? defaultOptions);\n\n if (opts.romanNumerals) {\n return formatRomanNumerals(qtyAsNumber);\n }\n\n const absoluteValue = Math.abs(qtyAsNumber);\n const flooredAbsVal = Math.floor(absoluteValue);\n const flooredAbsValStr = `${qtyAsNumber < 0 ? '-' : ''}${\n flooredAbsVal === 0 ? '' : `${flooredAbsVal} `\n }`;\n const decimalValue = absoluteValue - flooredAbsVal;\n\n // For integers just return the given value as a string.\n if (decimalValue === 0) {\n return `${qtyAsNumber}`;\n }\n\n for (const [num, vf] of fractionDecimalMatches) {\n if (closeEnough(decimalValue, num, opts.tolerance)) {\n const fraction = getFraction(vf, opts);\n const int =\n fraction in vulgarToAsciiMap\n ? flooredAbsValStr.trim()\n : flooredAbsValStr;\n return `${int}${fraction}`;\n }\n }\n\n return `${qtyAsNumber}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,mBAAmB;AAKzB,IAAM,iBAAiB;AAAA,EAC5B,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AACjB;AAKO,IAAM,mBAAmB;AAAA,EAC9B,QAAK;AAAA,EACL,QAAK;AAAA,EACL,QAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AAAA,EACL,UAAK;AACP;AAMO,IAAM,yBAAyB;AAAA,EACpC,CAAC,MAAM,QAAG;AAAA,EACV,CAAC,MAAM,QAAG;AAAA,EACV,CAAC,KAAK,QAAG;AAAA,EACT,CAAC,KAAK,QAAG;AAAA,EACT,CAAC,KAAK,QAAG;AAAA,EACT,CAAC,KAAK,QAAG;AAAA,EACT,CAAC,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AAG,WAAW;AAAA,EACvB;AAEA,aAAW,CAAC,KAAK,EAAE,KAAK,wBAAwB;AAC9C,QAAI,YAAY,cAAc,KAAK,KAAK,SAAS,GAAG;AAClD,YAAM,WAAW,YAAY,IAAI,IAAI;AACrC,YAAM,MACJ,YAAY,mBACR,iBAAiB,KAAK,IACtB;AACN,aAAO,GAAG,GAAG,GAAG,QAAQ;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO,GAAG,WAAW;AACvB;","names":[]}
|
|
1
|
+
{"version":3,"file":"format-quantity.cjs.development.js","names":["numericQuantity"],"sources":["../../src/constants.ts","../../src/formatQuantity.ts"],"sourcesContent":["import type {\n ResolvedFormatQuantityOptions,\n SimpleFraction,\n Sixteenth,\n VulgarFraction,\n} from './types';\n\n/**\n * Default tolerance used by {@link formatQuantity} when determining if a number\n * is close enough to a fraction value to be considered equivalent.\n */\nexport const defaultTolerance = 0.0075 as const;\n\n/**\n * Default options for {@link formatQuantity}.\n */\nexport const defaultOptions: Readonly<ResolvedFormatQuantityOptions> = Object.freeze({\n vulgarFractions: false,\n tolerance: defaultTolerance,\n fractionSlash: false,\n romanNumerals: false,\n zeroFormat: '',\n allowTrailingInvalid: true,\n});\n\n/**\n * Map of vulgar fractions to their traditional ASCII equivalents.\n */\nexport const vulgarToAsciiMap: Readonly<Record<VulgarFraction, SimpleFraction>> = Object.freeze({\n '¼': '1/4',\n '½': '1/2',\n '¾': '3/4',\n '⅐': '1/7',\n '⅑': '1/9',\n '⅒': '1/10',\n '⅓': '1/3',\n '⅔': '2/3',\n '⅕': '1/5',\n '⅖': '2/5',\n '⅗': '3/5',\n '⅘': '4/5',\n '⅙': '1/6',\n '⅚': '5/6',\n '⅛': '1/8',\n '⅜': '3/8',\n '⅝': '5/8',\n '⅞': '7/8',\n});\n\n/**\n * Map of \"close enough\" values to the {@link VulgarFraction} or {@link Sixteenth} fraction\n * string matches. The value +/- the `tolerance` option (or {@link defaultTolerance} if not\n * specified) is considered close enough to match the fraction.\n */\nexport const fractionDecimalMatches: readonly (readonly [number, VulgarFraction | Sixteenth])[] =\n Object.freeze(\n (\n [\n [1 / 16, '1/16'],\n [1 / 10, '⅒'],\n [1 / 9, '⅑'],\n [1 / 8, '⅛'],\n [1 / 7, '⅐'],\n [1 / 6, '⅙'],\n [3 / 16, '3/16'],\n [1 / 5, '⅕'],\n [1 / 4, '¼'],\n [5 / 16, '5/16'],\n [1 / 3, '⅓'],\n [3 / 8, '⅜'],\n [2 / 5, '⅖'],\n [7 / 16, '7/16'],\n [1 / 2, '½'],\n [9 / 16, '9/16'],\n [3 / 5, '⅗'],\n [5 / 8, '⅝'],\n [2 / 3, '⅔'],\n [11 / 16, '11/16'],\n [3 / 4, '¾'],\n [4 / 5, '⅘'],\n [13 / 16, '13/16'],\n [5 / 6, '⅚'],\n [7 / 8, '⅞'],\n [15 / 16, '15/16'],\n ] satisfies [number, VulgarFraction | Sixteenth][]\n ).map(entry => Object.freeze(entry))\n );\n","import { numericQuantity } from 'numeric-quantity';\nimport { defaultOptions, fractionDecimalMatches, vulgarToAsciiMap } from './constants';\nimport type {\n FormatQuantity,\n ResolvedFormatQuantityOptions,\n SimpleFraction,\n Sixteenth,\n VulgarFraction,\n} from './types';\n\nconst superscriptDigits = '⁰¹²³⁴⁵⁶⁷⁸⁹';\nconst subscriptDigits = '₀₁₂₃₄₅₆₇₈₉';\n\n// oxlint-disable-next-line typescript/no-misused-spread\nconst toSuperscript = (s: string) => [...s].map(c => superscriptDigits[+c]).join('');\n// oxlint-disable-next-line typescript/no-misused-spread\nconst toSubscript = (s: string) => [...s].map(c => subscriptDigits[+c]).join('');\n\n/**\n * Applies the `vulgarFractions` or `fractionSlash` options as necessary.\n */\nconst getFraction = (\n vulgarFractionOrSixteenth: VulgarFraction | Sixteenth,\n { fractionSlash, vulgarFractions }: ResolvedFormatQuantityOptions\n) => {\n if (vulgarFractions) {\n return vulgarFractionOrSixteenth;\n }\n\n const plainFraction: SimpleFraction =\n vulgarToAsciiMap[vulgarFractionOrSixteenth as VulgarFraction] ?? vulgarFractionOrSixteenth;\n\n if (fractionSlash) {\n const [num, den] = plainFraction.split('/');\n return `${toSuperscript(num)}⁄${toSubscript(den)}`;\n }\n\n return plainFraction;\n};\n\n/**\n * Only `false` (matching disabled) or a non-negative number is a valid\n * `tolerance`. Everything else—negative numbers, `NaN`, non-numbers,\n * `null`, `undefined`—resolves to {@link defaultTolerance}.\n */\nconst isValidTolerance = (tolerance: unknown): tolerance is number | false =>\n tolerance === false || (typeof tolerance === 'number' && tolerance >= 0);\n\n/**\n * Merges options object with default options, converting boolean to object if necessary.\n */\nconst normalizeOptions = (\n options: Parameters<FormatQuantity>[1]\n): ResolvedFormatQuantityOptions => {\n const opts: ResolvedFormatQuantityOptions = {\n ...defaultOptions,\n ...(typeof options === 'boolean'\n ? { vulgarFractions: options }\n : typeof options === 'object' && options !== null\n ? options\n : {}),\n };\n\n if (!isValidTolerance(opts.tolerance)) {\n opts.tolerance = defaultOptions.tolerance;\n }\n\n if (typeof opts.zeroFormat !== 'string') {\n opts.zeroFormat = defaultOptions.zeroFormat;\n }\n\n if (opts.allowTrailingInvalid !== false) {\n opts.allowTrailingInvalid = true;\n }\n\n return opts;\n};\n\n// oxfmt-ignore\nconst romanNumeralsByPlace = [\n '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',\n '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',\n '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX',\n] as const;\n\n/**\n * Formats a number or bigint as Roman numerals. The number must be between\n * 1 and 3999, inclusive; any other value—including non-numbers,\n * `NaN`, and non-finite numbers—yields `null`.\n */\nexport const formatRomanNumerals = (quantity: number | bigint): string | null => {\n if (\n (typeof quantity !== 'number' && typeof quantity !== 'bigint') ||\n !(quantity >= 1 && quantity < 4000)\n ) {\n return null;\n }\n\n const qty = Number(quantity);\n\n const floored = Math.floor(qty);\n\n const digits = `${floored}`.split('');\n let roman = '';\n let i = 3;\n while (i--) {\n roman = `${romanNumeralsByPlace[+digits.pop()! + i * 10] || ''}${roman}`;\n }\n\n return `${Array(+digits.join('') + 1).join('M')}${roman}`;\n};\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fraction characters\n * like \"½\", pass `true` as the second argument. For other options\n * see {@link FormatQuantityOptions}.\n */\nexport const formatQuantity: FormatQuantity = (qty, options) => {\n // Only numbers, bigints, and strings are accepted. Anything else (objects, booleans,\n // nullish, arrays like `[1]` that would coerce to a numeric string) is\n // rejected up front so off-type inputs behave consistently.\n if (typeof qty !== 'number' && typeof qty !== 'string' && typeof qty !== 'bigint') {\n return null;\n }\n\n const opts = normalizeOptions(options);\n\n const qtyAsNumber =\n typeof qty !== 'number' && typeof qty !== 'bigint'\n ? numericQuantity(qty, {\n allowTrailingInvalid: opts.allowTrailingInvalid,\n romanNumerals: opts.romanNumerals,\n bigIntOnOverflow: true,\n round: false,\n })\n : qty;\n\n // Return `null` if input is not number-like.\n if (typeof qtyAsNumber === 'number' && isNaN(qtyAsNumber)) {\n return null;\n }\n\n // Return empty string (or configured `zeroFormat`) if the value is zero.\n if (Number(qtyAsNumber) === 0) {\n return opts.zeroFormat;\n }\n\n if (opts.romanNumerals) {\n return formatRomanNumerals(qtyAsNumber);\n }\n\n const absoluteValue =\n typeof qtyAsNumber === 'bigint'\n ? qtyAsNumber < 0n\n ? -qtyAsNumber\n : qtyAsNumber\n : Math.abs(qtyAsNumber);\n const flooredAbsVal =\n typeof absoluteValue === 'bigint' ? absoluteValue : Math.floor(absoluteValue);\n const wholeNumberStr = `${flooredAbsVal || ''}`;\n const decimalValue =\n typeof absoluteValue === 'bigint' ? 0 : absoluteValue - (flooredAbsVal as number);\n\n // For integers just return the given value as a string.\n if (decimalValue === 0) {\n return `${qtyAsNumber}`;\n }\n\n let closestMatch: VulgarFraction | Sixteenth | null = null;\n let closestMatchDiff = Infinity;\n // `tolerance: false` disables fraction matching entirely.\n if (opts.tolerance !== false) {\n for (const [num, vf] of fractionDecimalMatches) {\n const diff = Math.abs(decimalValue - num);\n // `diff === 0` keeps exact quotients matching even at `tolerance: 0`.\n if (diff < opts.tolerance || diff === 0) {\n if (diff === 0) {\n closestMatch = vf;\n break;\n }\n if (diff < closestMatchDiff) {\n closestMatch = vf;\n closestMatchDiff = diff;\n }\n }\n }\n }\n\n if (closestMatch) {\n const fraction = getFraction(closestMatch, opts);\n const isVulgar = fraction in vulgarToAsciiMap;\n const sep = wholeNumberStr ? (opts.separator ?? (isVulgar ? '' : ' ')) : '';\n return `${qtyAsNumber < 0 ? '-' : ''}${wholeNumberStr}${sep}${fraction}`;\n }\n\n return `${qtyAsNumber}`;\n};\n"],"mappings":";;;;;;;AAWA,MAAa,mBAAmB;;;;AAKhC,MAAa,iBAA0D,OAAO,OAAO;CACnF,iBAAiB;CACjB,WAAW;CACX,eAAe;CACf,eAAe;CACf,YAAY;CACZ,sBAAsB;AACxB,CAAC;;;;AAKD,MAAa,mBAAqE,OAAO,OAAO;CAC9F,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP,CAAC;;;;;;AAOD,MAAa,yBACX,OAAO,OAEH;CACE,CAAC,IAAI,IAAI,MAAM;CACf,CAAC,IAAI,IAAI,GAAG;CACZ,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,IAAI,MAAM;CACf,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,GAAG,GAAG;CACX,CAAC,IAAI,IAAI,MAA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