Skip to content

Commit

Permalink
add support for non-string input
Browse files Browse the repository at this point in the history
Closes #14
Closes #24
  • Loading branch information
alexeyraspopov committed Oct 4, 2021
1 parent 2bbb880 commit 3276400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion picocolors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let isColorSupported =
"CI" in process.env);

function formatter(open, close, replace = open) {
return (string) => {
return (input) => {
let string = "" + input;
let index = string.indexOf(close, open.length);
return !~index
? open + string + close
Expand Down
11 changes: 11 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ test("close sequence replacement", () => {
);
});

test("non-string input", () => {
assert.equal(pc.red(), FMT.red[0] + "undefined" + FMT.red[1]);
assert.equal(pc.red(undefined), FMT.red[0] + "undefined" + FMT.red[1]);
assert.equal(pc.red(0), FMT.red[0] + "0" + FMT.red[1]);
assert.equal(pc.red(NaN), FMT.red[0] + "NaN" + FMT.red[1]);
assert.equal(pc.red(null), FMT.red[0] + "null" + FMT.red[1]);
assert.equal(pc.red(true), FMT.red[0] + "true" + FMT.red[1]);
assert.equal(pc.red(false), FMT.red[0] + "false" + FMT.red[1]);
assert.equal(pc.red(Infinity), FMT.red[0] + "Infinity" + FMT.red[1]);
});

function test(name, fn) {
try {
fn();
Expand Down

0 comments on commit 3276400

Please sign in to comment.