Skip to content

Commit

Permalink
Default to minus, not hyphen-minus.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 20, 2020
1 parent c7a8573 commit 8de6078
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 113 deletions.
4 changes: 1 addition & 3 deletions src/defaultLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ export var format;
export var formatPrefix;

defaultLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""],
minus: "-"
currency: ["$", ""]
});

export default function defaultLocale(definition) {
Expand Down
2 changes: 1 addition & 1 deletion src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function(locale) {
decimal = locale.decimal === undefined ? "." : locale.decimal + "",
numerals = locale.numerals === undefined ? identity : formatNumerals(map.call(locale.numerals, String)),
percent = locale.percent === undefined ? "%" : locale.percent + "",
minus = locale.minus === undefined ? "-" : locale.minus + "",
minus = locale.minus === undefined ? "" : locale.minus + "",
nan = locale.nan === undefined ? "NaN" : locale.nan + "";

function newFormat(specifier) {
Expand Down
2 changes: 1 addition & 1 deletion test/arabicLocale-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var tape = require("tape"),

tape("formatLocale(…) can format numbers using ar-001 locale.", function(test) {
var locale = d3.formatLocale(require("../locale/ar-001"));
test.equal(locale.format("$,.2f")(-1234.56), "-١٬٢٣٤٫٥٦");
test.equal(locale.format("$,.2f")(-1234.56), "١٬٢٣٤٫٥٦");
test.end();
});

Expand Down
16 changes: 8 additions & 8 deletions test/format-trim-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ tape("format(\"~e\") trims insignificant zeros", function(test) {
test.equal(f(42), "4.2e+1");
test.equal(f(42000000), "4.2e+7");
test.equal(f(0.042), "4.2e-2");
test.equal(f(-4), "-4e+0");
test.equal(f(-42), "-4.2e+1");
test.equal(f(-4), "4e+0");
test.equal(f(-42), "4.2e+1");
test.equal(f(42000000000), "4.2e+10");
test.equal(f(0.00000000042), "4.2e-10");
test.end();
Expand All @@ -37,15 +37,15 @@ tape("format(\".4~e\") trims insignificant zeros", function(test) {
test.equal(f(0.00000000012345), "1.2345e-10");
test.equal(f(0.00000000012340), "1.234e-10");
test.equal(f(0.00000000012300), "1.23e-10");
test.equal(f(-0.00000000012345), "-1.2345e-10");
test.equal(f(-0.00000000012340), "-1.234e-10");
test.equal(f(-0.00000000012300), "-1.23e-10");
test.equal(f(-0.00000000012345), "1.2345e-10");
test.equal(f(-0.00000000012340), "1.234e-10");
test.equal(f(-0.00000000012300), "1.23e-10");
test.equal(f(12345000000), "1.2345e+10");
test.equal(f(12340000000), "1.234e+10");
test.equal(f(12300000000), "1.23e+10");
test.equal(f(-12345000000), "-1.2345e+10");
test.equal(f(-12340000000), "-1.234e+10");
test.equal(f(-12300000000), "-1.23e+10");
test.equal(f(-12345000000), "1.2345e+10");
test.equal(f(-12340000000), "1.234e+10");
test.equal(f(-12300000000), "1.23e+10");
test.end();
});

Expand Down
8 changes: 4 additions & 4 deletions test/format-type-%-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ tape("format(\"%\") can output a whole percentage", function(test) {
test.equal(f(.042), "4%");
test.equal(f(.42), "42%");
test.equal(f(4.2), "420%");
test.equal(f(-.042), "-4%");
test.equal(f(-.42), "-42%");
test.equal(f(-4.2), "-420%");
test.equal(f(-.042), "4%");
test.equal(f(-.42), "42%");
test.equal(f(-4.2), "420%");
test.end();
});

Expand All @@ -30,6 +30,6 @@ tape("format(\"%\") fill respects suffix", function(test) {
tape("format(\"^%\") align center puts suffix adjacent to number", function(test) {
test.equal(format.format("^21.0%")(.42), " 42% ");
test.equal(format.format("^21,.0%")(422), " 42,200% ");
test.equal(format.format("^21,.0%")(-422), " -42,200% ");
test.equal(format.format("^21,.0%")(-422), " 42,200% ");
test.end();
});
48 changes: 24 additions & 24 deletions test/format-type-d-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ tape("format(\"d\") can zero fill", function(test) {
test.equal(f(42), "00000042");
test.equal(f(42000000), "42000000");
test.equal(f(420000000), "420000000");
test.equal(f(-4), "-0000004");
test.equal(f(-42), "-0000042");
test.equal(f(-4200000), "-4200000");
test.equal(f(-42000000), "-42000000");
test.equal(f(-4), "0000004");
test.equal(f(-42), "0000042");
test.equal(f(-4200000), "4200000");
test.equal(f(-42000000), "42000000");
test.end();
});

Expand All @@ -20,10 +20,10 @@ tape("format(\"d\") can space fill", function(test) {
test.equal(f(42), " 42");
test.equal(f(42000000), "42000000");
test.equal(f(420000000), "420000000");
test.equal(f(-4), " -4");
test.equal(f(-42), " -42");
test.equal(f(-4200000), "-4200000");
test.equal(f(-42000000), "-42000000");
test.equal(f(-4), " 4");
test.equal(f(-42), " 42");
test.equal(f(-4200000), "4200000");
test.equal(f(-42000000), "42000000");
test.end();
});

Expand All @@ -33,10 +33,10 @@ tape("format(\"d\") can underscore fill", function(test) {
test.equal(f(42), "______42");
test.equal(f(42000000), "42000000");
test.equal(f(420000000), "420000000");
test.equal(f(-4), "______-4");
test.equal(f(-42), "_____-42");
test.equal(f(-4200000), "-4200000");
test.equal(f(-42000000), "-42000000");
test.equal(f(-4), "______4");
test.equal(f(-42), "_____42");
test.equal(f(-4200000), "4200000");
test.equal(f(-42000000), "42000000");
test.end();
});

Expand All @@ -46,18 +46,18 @@ tape("format(\"d\") can zero fill with sign and group", function(test) {
test.equal(f(42), "+0,000,042");
test.equal(f(42000000), "+42,000,000");
test.equal(f(420000000), "+420,000,000");
test.equal(f(-4), "-0,000,004");
test.equal(f(-42), "-0,000,042");
test.equal(f(-4200000), "-4,200,000");
test.equal(f(-42000000), "-42,000,000");
test.equal(f(-4), "0,000,004");
test.equal(f(-42), "0,000,042");
test.equal(f(-4200000), "4,200,000");
test.equal(f(-42000000), "42,000,000");
test.end();
});

tape("format(\"d\") always uses zero precision", function(test) {
var f = format.format(".2d");
test.equal(f(0), "0");
test.equal(f(42), "42");
test.equal(f(-4.2), "-4");
test.equal(f(-4.2), "4");
test.end();
});

Expand All @@ -73,10 +73,10 @@ tape("format(\",d\") can group thousands", function(test) {
test.equal(f(42), "42");
test.equal(f(42000000), "42,000,000");
test.equal(f(420000000), "420,000,000");
test.equal(f(-4), "-4");
test.equal(f(-42), "-42");
test.equal(f(-4200000), "-4,200,000");
test.equal(f(-42000000), "-42,000,000");
test.equal(f(-4), "4");
test.equal(f(-42), "42");
test.equal(f(-4200000), "4,200,000");
test.equal(f(-42000000), "42,000,000");
test.equal(f(1e21), "1,000,000,000,000,000,000,000");
test.equal(f(1.3e27), "1,300,000,000,000,000,000,000,000,000");
test.equal(f(1.3e107), "130,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000");
Expand All @@ -94,7 +94,7 @@ tape("format(\"0,d\") can group thousands and zero fill", function(test) {
test.equal(format.format("08,d")(0), "0,000,000");
test.equal(format.format("013,d")(0), "0,000,000,000");
test.equal(format.format("021,d")(0), "0,000,000,000,000,000");
test.equal(format.format("013,d")(-42000000), "-0,042,000,000");
test.equal(format.format("013,d")(-42000000), "0,042,000,000");
test.equal(format.format("012,d")(1e21), "1,000,000,000,000,000,000,000");
test.equal(format.format("013,d")(1e21), "1,000,000,000,000,000,000,000");
test.equal(format.format("014,d")(1e21), "1,000,000,000,000,000,000,000");
Expand Down Expand Up @@ -203,7 +203,7 @@ tape("format(\"=+$,d\") pad after sign with currency", function(test) {
});

tape("format(\" ,d\") a space can denote positive numbers", function(test) {
test.equal(format.format(" 1,d")(-1), "-1");
test.equal(format.format(" 1,d")(-1), "1");
test.equal(format.format(" 1,d")(0), " 0");
test.equal(format.format(" 2,d")(0), " 0");
test.equal(format.format(" 3,d")(0), " 0");
Expand All @@ -216,7 +216,7 @@ tape("format(\" ,d\") a space can denote positive numbers", function(test) {
});

tape("format(\"-,d\") explicitly only use a sign for negative numbers", function(test) {
test.equal(format.format("-1,d")(-1), "-1");
test.equal(format.format("-1,d")(-1), "1");
test.equal(format.format("-1,d")(0), "0");
test.equal(format.format("-2,d")(0), " 0");
test.equal(format.format("-3,d")(0), " 0");
Expand Down
12 changes: 6 additions & 6 deletions test/format-type-e-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ tape("format(\"e\") can output exponent notation", function(test) {
test.equal(f(42), "4.200000e+1");
test.equal(f(42000000), "4.200000e+7");
test.equal(f(420000000), "4.200000e+8");
test.equal(f(-4), "-4.000000e+0");
test.equal(f(-42), "-4.200000e+1");
test.equal(f(-4200000), "-4.200000e+6");
test.equal(f(-42000000), "-4.200000e+7");
test.equal(f(-4), "4.000000e+0");
test.equal(f(-42), "4.200000e+1");
test.equal(f(-4200000), "4.200000e+6");
test.equal(f(-42000000), "4.200000e+7");
test.equal(format.format(".0e")(42), "4e+1")
test.equal(format.format(".3e")(42), "4.200e+1")
test.end();
});

tape("format(\"e\") can format negative zero as zero", function(test) {
test.equal(format.format("1e")(-0), "0.000000e+0");
test.equal(format.format("1e")(-1e-12), "-1.000000e-12");
test.equal(format.format("1e")(-1e-12), "1.000000e-12");
test.end();
});

Expand All @@ -28,6 +28,6 @@ tape("format(\",e\") does not group Infinity", function(test) {
});

tape("format(\".3e\") can format negative infinity", function(test) {
test.equal(format.format(".3e")(-Infinity), "-Infinity");
test.equal(format.format(".3e")(-Infinity), "Infinity");
test.end();
});
10 changes: 5 additions & 5 deletions test/format-type-f-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ tape("format(\"+$,f\") can output a currency with comma-grouping and sign", func
var f = format.format("+$,.2f");
test.equal(f(0), "+$0.00");
test.equal(f(0.429), "+$0.43");
test.equal(f(-0.429), "-$0.43");
test.equal(f(-1), "-$1.00");
test.equal(f(-0.429), "$0.43");
test.equal(f(-1), "$1.00");
test.equal(f(1e4), "+$10,000.00");
test.end();
});
Expand Down Expand Up @@ -47,15 +47,15 @@ tape("format(\"f\") can format negative zero as zero", function(test) {
});

tape("format(\"+f\") signs negative zero correctly", function(test) {
test.equal(format.format("+f")(-0), "-0.000000");
test.equal(format.format("+f")(-0), "0.000000");
test.equal(format.format("+f")(+0), "+0.000000");
test.equal(format.format("+f")(-1e-12), "-0.000000");
test.equal(format.format("+f")(-1e-12), "0.000000");
test.equal(format.format("+f")(+1e-12), "+0.000000");
test.end();
});

tape("format(\"f\") can format negative infinity", function(test) {
test.equal(format.format("f")(-Infinity), "-Infinity");
test.equal(format.format("f")(-Infinity), "Infinity");
test.end();
});

Expand Down
8 changes: 4 additions & 4 deletions test/format-type-g-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ tape("format(\",g\") can group thousands with general notation", function(test)
test.equal(f(42), "42.0000000000");
test.equal(f(42000000), "42,000,000.0000");
test.equal(f(420000000), "420,000,000.000");
test.equal(f(-4), "-4.00000000000");
test.equal(f(-42), "-42.0000000000");
test.equal(f(-4200000), "-4,200,000.00000");
test.equal(f(-42000000), "-42,000,000.0000");
test.equal(f(-4), "4.00000000000");
test.equal(f(-42), "42.0000000000");
test.equal(f(-4200000), "4,200,000.00000");
test.equal(f(-42000000), "42,000,000.0000");
test.end();
});
10 changes: 5 additions & 5 deletions test/format-type-n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ tape("format(\"n\") is an alias for \",g\"", function(test) {
test.equal(f(42), "42.0000000000");
test.equal(f(42000000), "42,000,000.0000");
test.equal(f(420000000), "420,000,000.000");
test.equal(f(-4), "-4.00000000000");
test.equal(f(-42), "-42.0000000000");
test.equal(f(-4200000), "-4,200,000.00000");
test.equal(f(-42000000), "-42,000,000.0000");
test.equal(f(-4), "4.00000000000");
test.equal(f(-42), "42.0000000000");
test.equal(f(-4200000), "4,200,000.00000");
test.equal(f(-42000000), "42,000,000.0000");
test.equal(f(.0042), "0.00420000000000");
test.equal(f(.42), "0.420000000000");
test.equal(f(1e21), "1.00000000000e+21");
Expand All @@ -25,6 +25,6 @@ tape("format(\"n\") uses zero padding", function(test) {
test.equal(format.format("08.0n")(0), "0,000,000");
test.equal(format.format("013.0n")(0), "0,000,000,000");
test.equal(format.format("021.0n")(0), "0,000,000,000,000,000");
test.equal(format.format("013.8n")(-42000000), "-0,042,000,000");
test.equal(format.format("013.8n")(-42000000), "0,042,000,000");
test.end();
});
8 changes: 4 additions & 4 deletions test/format-type-none-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ tape("format(\"$\") can output a currency", function(test) {
test.equal(f(.042), "$0.042");
test.equal(f(.42), "$0.42");
test.equal(f(4.2), "$4.2");
test.equal(f(-.042), "-$0.042");
test.equal(f(-.42), "-$0.42");
test.equal(f(-4.2), "-$4.2");
test.equal(f(-.042), "$0.042");
test.equal(f(-.42), "$0.42");
test.equal(f(-4.2), "$4.2");
test.end();
});

Expand All @@ -65,6 +65,6 @@ tape("format(\"\") can format negative zero as zero", function(test) {
});

tape("format(\"\") can format negative infinity", function(test) {
test.equal(format.format("")(-Infinity), "-Infinity");
test.equal(format.format("")(-Infinity), "Infinity");
test.end();
});
16 changes: 8 additions & 8 deletions test/format-type-p-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ tape("format(\"p\") can output a percentage", function(test) {
test.equal(f(.123), "12.3000%");
test.equal(f(.234), "23.4000%");
test.equal(f(1.23), "123.000%");
test.equal(f(-.00123), "-0.123000%");
test.equal(f(-.0123), "-1.23000%");
test.equal(f(-.123), "-12.3000%");
test.equal(f(-1.23), "-123.000%");
test.equal(f(-.00123), "0.123000%");
test.equal(f(-.0123), "1.23000%");
test.equal(f(-.123), "12.3000%");
test.equal(f(-1.23), "123.000%");
test.end();
});

Expand All @@ -21,9 +21,9 @@ tape("format(\"+p\") can output a percentage with rounding and sign", function(t
test.equal(f(.0123), "+1.2%");
test.equal(f(.123), "+12%");
test.equal(f(1.23), "+120%");
test.equal(f(-.00123), "-0.12%");
test.equal(f(-.0123), "-1.2%");
test.equal(f(-.123), "-12%");
test.equal(f(-1.23), "-120%");
test.equal(f(-.00123), "0.12%");
test.equal(f(-.0123), "1.2%");
test.equal(f(-.123), "12%");
test.equal(f(-1.23), "120%");
test.end();
});
4 changes: 2 additions & 2 deletions test/format-type-r-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var tape = require("tape"),
tape("format(\"r\") can round to significant digits", function(test) {
test.equal(format.format(".2r")(0), "0.0");
test.equal(format.format(".1r")(0.049), "0.05");
test.equal(format.format(".1r")(-0.049), "-0.05");
test.equal(format.format(".1r")(-0.049), "0.05");
test.equal(format.format(".1r")(0.49), "0.5");
test.equal(format.format(".1r")(-0.49), "-0.5");
test.equal(format.format(".1r")(-0.49), "0.5");
test.equal(format.format(".2r")(0.449), "0.45");
test.equal(format.format(".3r")(0.4449), "0.445");
test.equal(format.format(".3r")(1.00), "1.00");
Expand Down
Loading

0 comments on commit 8de6078

Please sign in to comment.