Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public parseNumber(value: string, options?: L10nNumberFormatOptions, language = this.locale.language): number | null {
if (value === '' || value == null) return null;
let format = { minimumIntegerDigits: 1, minimumFractionDigits: 0, maximumFractionDigits: 0 };
if (options && options.digits) {
format = { ...format, ...parseDigits(options.digits) };
}
let decimalSeparator: string;
switch (language) {
case 'it-IT':
decimalSeparator = ',';
break;
default:
decimalSeparator = '.';
}
const pattern = `^-?[\\d]{${format.minimumIntegerDigits},}(\\${decimalSeparator}[\\d]{${format.minimumFractionDigits},${format.maximumFractionDigits}})?$`;
const regex = new RegExp(pattern);
return regex.test(value) ? parseFloat(value.replace(decimalSeparator, '.')) : null;
}