Add chalk factory method
This commit is contained in:
parent
8cb6c683cb
commit
ed509bcf0b
1 changed files with 18 additions and 14 deletions
16
index.js
16
index.js
|
|
@ -26,15 +26,12 @@ 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);
|
||||||
|
|
||||||
|
|
@ -47,6 +44,13 @@ function Chalk(options) {
|
||||||
chalk.template.instance = ChalkClass;
|
chalk.template.instance = ChalkClass;
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue