Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import RHElement from "../rhelement/rhelement.js";
import numeral from "numeral";
// easy aliases for common format strings
const types = {
abbrev: "0a", // or 'approx'?
ordinal: "0o",
percent: "0%",
bytes: "0[.][00] ib",
e: "0[.00]e+0",
thousands: "0,0[.00]"
};
// use thin spaces to separate thousands chunks
// debugger;
numeral.locales.en.delimiters.thousands = " ";
class RhNumber extends RHElement {
static get tag() {
return "rh-number";
}
get styleUrl() {
return "rh-number.scss";
}
get templateUrl() {
return "rh-number.html";
}
static get observedAttributes() {
return ["number", "format", "type"];
function initNumeralLocales(lang, locale) {
const language = lang.toLowerCase();
const LOCAL_NUMERAL_FORMAT = {
defaultFormat: '0,0.00[000]',
delimiters: {
thousands: locale.numberGroupingSeparator || ',',
decimal: locale.numberDecimalSeparator || '.',
},
};
if (typeof numeral.locales[language] === 'undefined') {
numeral.register('locale', language, LOCAL_NUMERAL_FORMAT);
}
if (typeof numeral.locales[language] !== 'undefined') {
numeral.locale(language);
if (LOCAL_NUMERAL_FORMAT.defaultFormat) {
numeral.defaultFormat(LOCAL_NUMERAL_FORMAT.defaultFormat);
}
}
}
define(function(require) {
'use strict';
const numeral = require('numeral');
const localeSettings = require('./locale-settings');
const currencySettings = localeSettings.getNumberFormats('currency');
numeral.locales[localeSettings.getLocale().toLowerCase()] = {
delimiters: {
thousands: currencySettings.grouping_separator_symbol,
decimal: currencySettings.decimal_separator_symbol
},
abbreviations: {
thousand: 'k',
million: 'm',
billion: 'b',
trillion: 't'
},
ordinal: function(number) {
const b = number % 10;
return (~~(number % 100 / 10) === 1) ? 'th'
: (b === 1) ? 'st'
: (b === 2) ? 'nd'
: (b === 3) ? 'rd' : 'th';
function initNumeralLocales(lang, locale) {
const language = lang.toLowerCase();
const LOCAL_NUMERAL_FORMAT = {
defaultFormat: '0,0.00[000]',
delimiters: {
thousands: locale.numberGroupingSeparator || ',',
decimal: locale.numberDecimalSeparator || '.',
},
};
if (typeof numeral.locales[language] === 'undefined') {
numeral.register('locale', language, LOCAL_NUMERAL_FORMAT);
}
if (typeof numeral.locales[language] !== 'undefined') {
numeral.locale(language);
if (LOCAL_NUMERAL_FORMAT.defaultFormat) {
numeral.defaultFormat(LOCAL_NUMERAL_FORMAT.defaultFormat);
}
}
}