From 8be88700789f9a0526fdf222407f6e502eebd579 Mon Sep 17 00:00:00 2001 From: Salah Alhashmi Date: Sat, 15 Jul 2023 10:46:50 +0400 Subject: [PATCH 1/3] move Chalk class to the bottom (readablity) --- source/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/index.js b/source/index.js index 8bc993da..ec7643b0 100644 --- a/source/index.js +++ b/source/index.js @@ -31,13 +31,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); @@ -202,6 +195,14 @@ const applyStyle = (self, string) => { 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 { From a7ee3d7b11aec5bcd3d33eefb11d0c12ef1b5d63 Mon Sep 17 00:00:00 2001 From: Salah Alhashmi Date: Sat, 15 Jul 2023 10:49:14 +0400 Subject: [PATCH 2/3] move styles variable (readablity) --- source/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.js b/source/index.js index ec7643b0..a40a1a1d 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'); @@ -46,6 +44,8 @@ function createChalk(options) { Object.setPrototypeOf(createChalk.prototype, Function.prototype); +const styles = Object.create(null); + for (const [styleName, style] of Object.entries(ansiStyles)) { styles[styleName] = { get() { From c738c69ceab59a44ed7ce559347d73ad344a6ca6 Mon Sep 17 00:00:00 2001 From: Salah Alhashmi Date: Sat, 15 Jul 2023 10:53:33 +0400 Subject: [PATCH 3/3] gather createChalkPrototype set --- source/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/index.js b/source/index.js index a40a1a1d..4bd2d7c5 100644 --- a/source/index.js +++ b/source/index.js @@ -42,8 +42,6 @@ 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)) { @@ -192,6 +190,7 @@ const applyStyle = (self, string) => { return openAll + string + closeAll; }; +Object.setPrototypeOf(createChalk.prototype, Function.prototype); Object.defineProperties(createChalk.prototype, styles); const chalk = createChalk();