From 2e87a6ed147ded007956460f42636d0df6ea2627 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Fri, 15 Oct 2021 13:49:06 +0900 Subject: [PATCH] Should always return a string Color functions should always return a string according to our public API. --- index.js | 4 +--- tests/createColors.test.js | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 2e16e25..fb4b3a9 100644 --- a/index.js +++ b/index.js @@ -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 }), {} ) diff --git a/tests/createColors.test.js b/tests/createColors.test.js index 26b192d..01c9947 100644 --- a/tests/createColors.test.js +++ b/tests/createColors.test.js @@ -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)), ]) }, ]),