forked from d3/d3-format
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import formatLocale from "./locale"; | ||
|
||
var locale; | ||
export var format; | ||
export var formatPrefix; | ||
|
||
defaultLocale({ | ||
decimal: ".", | ||
thousands: ",", | ||
grouping: [3], | ||
currency: ["$", ""] | ||
}); | ||
|
||
export default function defaultLocale(definition) { | ||
locale = formatLocale(definition); | ||
format = locale.format; | ||
formatPrefix = locale.formatPrefix; | ||
return locale; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var tape = require("tape"), | ||
d3 = require("../"); | ||
|
||
var enUs = { | ||
"decimal": ".", | ||
"thousands": ",", | ||
"grouping": [3], | ||
"currency": ["$", ""] | ||
}; | ||
|
||
var frFr = { | ||
"decimal": ",", | ||
"thousands": ".", | ||
"grouping": [3], | ||
"currency": ["", "\u00a0€"] | ||
}; | ||
|
||
tape("d3.formatDefaultLocale(definition) returns the new default locale", function(test) { | ||
var locale = d3.formatDefaultLocale(frFr); | ||
try { | ||
test.equal(locale.format("$,.2f")(12345678.90), "12.345.678,90 €"); | ||
test.end(); | ||
} finally { | ||
d3.formatDefaultLocale(enUs); | ||
} | ||
}); | ||
|
||
tape("d3.formatDefaultLocale(definition) affects d3.format", function(test) { | ||
var locale = d3.formatDefaultLocale(frFr); | ||
try { | ||
test.equal(d3.format, locale.format); | ||
test.equal(d3.format("$,.2f")(12345678.90), "12.345.678,90 €"); | ||
test.end(); | ||
} finally { | ||
d3.formatDefaultLocale(enUs); | ||
} | ||
}); | ||
|
||
tape("d3.formatDefaultLocale(definition) affects d3.formatPrefix", function(test) { | ||
var locale = d3.formatDefaultLocale(frFr); | ||
try { | ||
test.equal(d3.formatPrefix, locale.formatPrefix); | ||
test.equal(d3.formatPrefix(",.2", 1e3)(12345678.90), "12.345,68k"); | ||
test.end(); | ||
} finally { | ||
d3.formatDefaultLocale(enUs); | ||
} | ||
}); |