From cbc9f160e8826b179fc9614d01528e7e742482a7 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Wed, 27 Mar 2019 08:37:25 +0300 Subject: [PATCH] caching simple getters --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b69a052..43373fc 100644 --- a/index.js +++ b/index.js @@ -91,14 +91,18 @@ function Chalk(options) { for (const [styleName, style] of Object.entries(ansiStyles)) { styles[styleName] = { get() { - return createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty); + const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty); + Object.defineProperty(this, styleName, {value: builder}); + return builder; } }; } styles.visible = { get() { - return createBuilder(this, this._styler, true); + const builder = createBuilder(this, this._styler, true); + Object.defineProperty(this, 'visible', {value: builder}); + return builder; } };