From e05b4a85f7c4f19b72e5b3fdb8ab9f1a5fd38c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Bergstr=C3=B6m?= Date: Tue, 29 Mar 2016 13:19:49 +0200 Subject: [PATCH] able to use extras when stylizing on string with corresponding test --- lib/colors.js | 12 ++++++++++-- tests/basic-test.js | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/colors.js b/lib/colors.js index 790ffd43..8bf45fc7 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -2,7 +2,7 @@ The MIT License (MIT) -Original Library +Original Library - Copyright (c) Marak Squires Additional functionality @@ -52,6 +52,14 @@ var stylize = colors.stylize = function stylize (str, style) { return str+''; } + if(style in colors){ + return colors[style](str); + } + + if(style in colors.maps){ + return colors[style](str); + } + return ansiStyles[style].open + str + ansiStyles[style].close; } @@ -184,4 +192,4 @@ for (var map in colors.maps) { })(map) } -defineProps(colors, init()); \ No newline at end of file +defineProps(colors, init()); diff --git a/tests/basic-test.js b/tests/basic-test.js index fda8af4e..e9094bfc 100644 --- a/tests/basic-test.js +++ b/tests/basic-test.js @@ -31,6 +31,12 @@ assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m'); assert.ok(s.rainbow); +assert.ok(colors.stylize(s, "rainbow")) +assert.ok(colors.stylize(s, "america")) +assert.ok(colors.stylize(s, "zebra")) +assert.ok(colors.stylize(s, "trap")) +assert.ok(colors.stylize(s, "random")) + aE(s, 'white', 37); aE(s, 'grey', 90); aE(s, 'black', 30); @@ -47,4 +53,3 @@ colors.setTheme({error:'red'}); assert.equal(typeof("astring".red),'string'); assert.equal(typeof("astring".error),'string'); -