diff --git a/source/index.js b/source/index.js index 8bc993d..4bd2d7c 100644 --- a/source/index.js +++ b/source/index.js @@ -19,8 +19,6 @@ const levelMapping = [ 'ansi16m', ]; -const styles = Object.create(null); - const applyOptions = (object, options = {}) => { if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) { throw new Error('The `level` option should be an integer from 0 to 3'); @@ -31,13 +29,6 @@ const applyOptions = (object, options = {}) => { object.level = options.level === undefined ? colorLevel : options.level; }; -export class Chalk { - constructor(options) { - // eslint-disable-next-line no-constructor-return - return chalkFactory(options); - } -} - const chalkFactory = options => { const chalk = (...strings) => strings.join(' '); applyOptions(chalk, options); @@ -51,7 +42,7 @@ function createChalk(options) { return chalkFactory(options); } -Object.setPrototypeOf(createChalk.prototype, Function.prototype); +const styles = Object.create(null); for (const [styleName, style] of Object.entries(ansiStyles)) { styles[styleName] = { @@ -199,9 +190,18 @@ const applyStyle = (self, string) => { return openAll + string + closeAll; }; +Object.setPrototypeOf(createChalk.prototype, Function.prototype); Object.defineProperties(createChalk.prototype, styles); const chalk = createChalk(); + +export class Chalk { + constructor(options) { + // eslint-disable-next-line no-constructor-return + return chalkFactory(options); + } +} + export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0}); export {