Skip to content

Commit

Permalink
Fix instanceof d3.formatSpecifier.
Browse files Browse the repository at this point in the history
Fixes d3/d3#3023.
  • Loading branch information
mbostock committed Nov 14, 2016
1 parent 5b9efde commit ae85342
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/formatSpecifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import formatTypes from "./formatTypes";
// [[fill]align][sign][symbol][0][width][,][.precision][type]
var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;

export default function(specifier) {
export default function formatSpecifier(specifier) {
return new FormatSpecifier(specifier);
}

formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof

function FormatSpecifier(specifier) {
if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);

Expand Down
6 changes: 6 additions & 0 deletions test/formatSpecifier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ tape("formatSpecifier(specifier) throws an error for invalid formats", function(
test.end();
});

tape("formatSpecifier(specifier) returns an instanceof formatSpecifier", function(test) {
var s = format.formatSpecifier("");
test.equal(s instanceof format.formatSpecifier, true);
test.end();
});

tape("formatSpecifier(\"\") has the expected defaults", function(test) {
var s = format.formatSpecifier("");
test.equal(s.fill, " ");
Expand Down

0 comments on commit ae85342

Please sign in to comment.