@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
50 lines (49 loc) • 1.76 kB
JavaScript
var n = Object.defineProperty;
var u = (t, r, a) => r in t ? n(t, r, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[r] = a;
var c = (t, r, a) => (u(t, typeof r != "symbol" ? r + "" : r, a), a);
const e = class e {
/**
* Format a number for a provided locale.
*
* @param value Number to format.
* @param options formatting options.
* @param locale The user's locale.
*
* @returns The formatted number as a string.
*/
static formatNumber(r, a, l) {
const g = a && (a.decimals || a.minimumFractionDigits || a.style || a.currency) ? {
minimumFractionDigits: a.decimals || a.minimumFractionDigits,
maximumFractionDigits: a.decimals,
style: a.style,
currency: a.currency
} : {}, m = Number(a && a.percentage ? 100 * r : r).toLocaleString(
l || navigator.language,
g
);
if (a) {
if (a.format)
return a.format.replace(e.valuePlaceholder, m);
if (a.percentage)
return e.percentageFormat.replace(e.valuePlaceholder, m);
}
return m;
}
/**
* Parse a number string, removing formatting & returning the numeric value.
*
* @param value The number string to parse.
*
* @returns The parsed number.
*/
static parseNumber(r) {
const l = r.replace(e.cleanPattern, "").replace(e.decimalSeparator, ".");
return parseFloat(l);
}
};
c(e, "parseExample", Intl.NumberFormat([...navigator.languages]).format(1.1)), c(e, "decimalSeparator", e.parseExample.charAt(1)), c(e, "cleanPattern", new RegExp(`[^-+0-9${e.decimalSeparator}]`, "g")), c(e, "valuePlaceholder", "{value}"), c(e, "percentageFormat", `${e.valuePlaceholder}%`);
let i = e;
export {
i as NeonNumberUtils
};
//# sourceMappingURL=NeonNumberUtils.es.js.map