Add chalk factory method

This commit is contained in:
Tom Sherman 2019-01-26 13:28:47 +00:00
parent 8cb6c683cb
commit ed509bcf0b

View file

@ -27,14 +27,11 @@ function applyOptions(object, options = {}) {
class ChalkClass { class ChalkClass {
constructor(options) { constructor(options) {
return Chalk(options) return chalkFactory(options);
} }
} }
function Chalk(options) { function chalkFactory(options) {
// We check for this.template here since calling `chalk.constructor()`
// by itself will have a `this` of a previously constructed chalk object
if (!this || !(this instanceof Chalk) || this.template) {
const chalk = {}; const chalk = {};
applyOptions(chalk, options); applyOptions(chalk, options);
@ -49,6 +46,13 @@ function Chalk(options) {
return chalk.template; return chalk.template;
} }
function Chalk(options) {
// We check for this.template here since calling `chalk.constructor()`
// by itself will have a `this` of a previously constructed chalk object
if (!this || !(this instanceof Chalk) || this.template) {
return chalkFactory(options);
}
applyOptions(this, options); applyOptions(this, options);
} }