From cc4e4c429fac6d7715d23aacf2e5eec11834ed54 Mon Sep 17 00:00:00 2001 From: David Keijser Date: Thu, 29 Jan 2015 10:53:47 +0100 Subject: [PATCH] use options hash as argument to constructor --- index.js | 8 +++++--- test.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a8a5e99..8cacd8c 100644 --- a/index.js +++ b/index.js @@ -6,10 +6,12 @@ var hasAnsi = require('has-ansi'); var supportsColor = require('supports-color'); var defineProps = Object.defineProperties; -function Chalk(enabled) { +function Chalk(options) { // detect mode if not set manually - if (enabled === undefined) { - this.enabled = this.supportsColor; + if (!options || options.enabled === undefined) { + this.enabled = supportsColor; + } else { + this.enabled = options.enabled; } } diff --git a/test.js b/test.js index d96fd40..5787e18 100644 --- a/test.js +++ b/test.js @@ -70,7 +70,7 @@ describe('chalk.enabled', function () { describe('chalk.constructor', function () { it('should create a isolated context where colors can be disabled', function () { - var ctx = new chalk.constructor(false); + var ctx = new chalk.constructor({enabled: false}); assert.equal(ctx.red('foo'), 'foo'); assert.equal(chalk.red('foo'), '\u001b[31mfoo\u001b[39m'); });