From d865cec69b8dc30cc7edf2be2b871da9f5b86b45 Mon Sep 17 00:00:00 2001 From: benib Date: Wed, 4 Sep 2019 18:58:39 +0200 Subject: [PATCH 1/3] allow minus sign to be configured in locale --- src/defaultLocale.js | 3 ++- src/locale.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/defaultLocale.js b/src/defaultLocale.js index 41ec802..7f7dc29 100644 --- a/src/defaultLocale.js +++ b/src/defaultLocale.js @@ -8,7 +8,8 @@ defaultLocale({ decimal: ".", thousands: ",", grouping: [3], - currency: ["$", ""] + currency: ["$", ""], + minusSign: "-" }); export default function defaultLocale(definition) { diff --git a/src/locale.js b/src/locale.js index c6aa8c0..e3ee9fd 100644 --- a/src/locale.js +++ b/src/locale.js @@ -14,7 +14,8 @@ export default function(locale) { currency = locale.currency, decimal = locale.decimal, numerals = locale.numerals ? formatNumerals(locale.numerals) : identity, - percent = locale.percent || "%"; + percent = locale.percent || "%", + minusSign = locale.minusSign || "-" function newFormat(specifier) { specifier = formatSpecifier(specifier); @@ -80,7 +81,8 @@ export default function(locale) { if (valueNegative && +value === 0) valueNegative = false; // Compute the prefix and suffix. - valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix; + valuePrefix = (valueNegative ? (sign === "(" ? sign : minusSign) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix; + valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : ""); // Break the formatted value into the integer “value” part that can be From ef58652fab7444cfacb4e680eb78cd70cae7a5a8 Mon Sep 17 00:00:00 2001 From: benib Date: Thu, 5 Sep 2019 08:47:36 +0200 Subject: [PATCH 2/3] use minus instead of minusSign as the probperty name for the minus character --- src/defaultLocale.js | 2 +- src/locale.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/defaultLocale.js b/src/defaultLocale.js index 7f7dc29..9ecf0fa 100644 --- a/src/defaultLocale.js +++ b/src/defaultLocale.js @@ -9,7 +9,7 @@ defaultLocale({ thousands: ",", grouping: [3], currency: ["$", ""], - minusSign: "-" + minus: "-" }); export default function defaultLocale(definition) { diff --git a/src/locale.js b/src/locale.js index e3ee9fd..e100b83 100644 --- a/src/locale.js +++ b/src/locale.js @@ -15,7 +15,7 @@ export default function(locale) { decimal = locale.decimal, numerals = locale.numerals ? formatNumerals(locale.numerals) : identity, percent = locale.percent || "%", - minusSign = locale.minusSign || "-" + minus = locale.minus || "-" function newFormat(specifier) { specifier = formatSpecifier(specifier); @@ -81,7 +81,7 @@ export default function(locale) { if (valueNegative && +value === 0) valueNegative = false; // Compute the prefix and suffix. - valuePrefix = (valueNegative ? (sign === "(" ? sign : minusSign) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix; + valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix; valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : ""); From dd09548af5acc79ce0c95aaba5fc9313d24d7368 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 5 Sep 2019 07:31:59 -0700 Subject: [PATCH 3/3] Add missing semicolon. --- src/locale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale.js b/src/locale.js index e100b83..bed6c02 100644 --- a/src/locale.js +++ b/src/locale.js @@ -15,7 +15,7 @@ export default function(locale) { decimal = locale.decimal, numerals = locale.numerals ? formatNumerals(locale.numerals) : identity, percent = locale.percent || "%", - minus = locale.minus || "-" + minus = locale.minus || "-"; function newFormat(specifier) { specifier = formatSpecifier(specifier);