From 9a06f4ac8ccff66f1f3d61179352a0fca6c08903 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Fri, 15 Oct 2021 16:09:57 +0900 Subject: [PATCH] Should always return a string (#88) 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)), ]) }, ]),