Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow minus sign to be configured in locale #76

Merged
merged 3 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/defaultLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defaultLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""]
currency: ["$", ""],
minus: "-"
});

export default function defaultLocale(definition) {
Expand Down
6 changes: 4 additions & 2 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "%",
minus = locale.minus || "-";

function newFormat(specifier) {
specifier = formatSpecifier(specifier);
Expand Down Expand Up @@ -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 : minus) : 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
Expand Down