UNPKG

jtc-utils

Version:
22 lines 907 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseNumber = parseNumber; const index_ts_1 = require("./locale/index.js"); const toHalfwidthAscii_ts_1 = require("./toHalfwidthAscii.js"); const NumberFormat_ts_1 = require("./util/NumberFormat.js"); const getLocale_ts_1 = require("./util/getLocale.js"); function parseNumber(str, format, options) { if (str == null) { return undefined; } let num; if (format) { const locale = options?.locale ?? (/^ja(-|$)/i.test((0, getLocale_ts_1.getLocale)()) ? index_ts_1.ja : index_ts_1.enUS); num = NumberFormat_ts_1.NumberFormat.get(format, locale.code).parse(str); } else { num = Number.parseFloat((0, toHalfwidthAscii_ts_1.toHalfwidthAscii)(str.replace(/[^0-9.-]+/g, ""))); } return Number.isFinite(num) ? num : undefined; } //# sourceMappingURL=parseNumber.js.map