jtc-utils
Version:
Utilities for Japanese Traditional Companies
19 lines • 694 B
JavaScript
import { enUS, ja } from "./locale/index.js";
import { toHalfwidthAscii } from "./toHalfwidthAscii.js";
import { NumberFormat } from "./util/NumberFormat.js";
import { getLocale } from "./util/getLocale.js";
export function parseNumber(str, format, options) {
if (str == null) {
return undefined;
}
let num;
if (format) {
const locale = options?.locale ?? (/^ja(-|$)/i.test(getLocale()) ? ja : enUS);
num = NumberFormat.get(format, locale.code).parse(str);
}
else {
num = Number.parseFloat(toHalfwidthAscii(str.replace(/[^0-9.-]+/g, "")));
}
return Number.isFinite(num) ? num : undefined;
}
//# sourceMappingURL=parseNumber.js.map