diff --git a/src/formatSpecifier.js b/src/formatSpecifier.js index 8338ec1..ee1567c 100644 --- a/src/formatSpecifier.js +++ b/src/formatSpecifier.js @@ -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); diff --git a/test/formatSpecifier-test.js b/test/formatSpecifier-test.js index 36cbfca..98672f3 100644 --- a/test/formatSpecifier-test.js +++ b/test/formatSpecifier-test.js @@ -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, " ");