@omegagrid/core
Advanced tools
Comparing version 0.2.14 to 0.2.15
@@ -6,2 +6,3 @@ import { DecimalSeparator, ValueFormatter } from "../types"; | ||
signDisplay?: 'auto' | 'never' | 'always' | 'exceptZero' | 'negative'; | ||
brackets?: boolean; | ||
} & Intl.NumberFormatOptions; | ||
@@ -8,0 +9,0 @@ export type NumberFormatterFunction = ValueFormatter<number>; |
@@ -41,5 +41,14 @@ "use strict"; | ||
exports.getNumberFormatter = getNumberFormatter; | ||
function createUnitNumberFormatter(locale, format) { | ||
function createExtendedNumberFormatter(locale, format) { | ||
const formatter = new Intl.NumberFormat(locale, format); | ||
return { format: (value) => formatter.format(value) + (format.um || '') }; | ||
return { format: (value) => { | ||
let str = formatter.format(value); | ||
if (format.um) | ||
str + (format.um || ''); | ||
if (format.brackets) | ||
str = `(${str})`; | ||
if (format.color) | ||
str = `<span style="color:${format.color}">${str}</span>`; | ||
return str; | ||
} }; | ||
} | ||
@@ -49,4 +58,4 @@ function createNumberFormatter(locale, format = '', fixFormat) { | ||
const formatters = formats.map(options => (0, utils_1.isObject)(options) | ||
? (options.um | ||
? createUnitNumberFormatter(locale, options) | ||
? ((options.um || options.color || options.brackets) | ||
? createExtendedNumberFormatter(locale, options) | ||
: new Intl.NumberFormat(locale, options)) : { format: (0, dates_1.getDateFormatter)(locale, options) }); | ||
@@ -84,2 +93,6 @@ if (formatters.length == 1) | ||
switch (ch.toLowerCase()) { | ||
case '(': | ||
format.brackets = true; | ||
++offset; | ||
break; | ||
case '[': | ||
@@ -86,0 +99,0 @@ format.color = ''; |
{ | ||
"name": "@omegagrid/core", | ||
"version": "0.2.14", | ||
"version": "0.2.15", | ||
"license": "UNLICENSED", | ||
@@ -5,0 +5,0 @@ "description": "Core components", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
438678
6331