Skip to content

Commit

Permalink
Should always return a string (#88)
Browse files Browse the repository at this point in the history
Color functions should always return a string according to our public API.
  • Loading branch information
jorgebucaran authored Oct 15, 2021
1 parent 547fcf1 commit 9a06f4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ const colors = {
bgWhiteBright: init(107, 49),
}

const none = (any) => any

export const createColors = ({ useColor = isColorSupported } = {}) =>
useColor
? colors
: Object.keys(colors).reduce(
(colors, key) => ({ ...colors, [key]: none }),
(colors, key) => ({ ...colors, [key]: String }),
{}
)

Expand Down
11 changes: 3 additions & 8 deletions tests/createColors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default [
t("useColor overrides automatic color detection", [
(done) => {
done([
equal(
blue("megazord"),
createColors({ useColor: true }).blue("megazord")
),
equal(
"megazord",
createColors({ useColor: false }).blue("megazord")
),
equal(blue("foo"), createColors({ useColor: true }).blue("foo")),
equal("foo", createColors({ useColor: false }).blue("foo")),
equal("42", createColors({ useColor: false }).blue(42)),
])
},
]),
Expand Down

0 comments on commit 9a06f4a

Please sign in to comment.