From 091e8ed9362ee42ce391de6916ddb5c17246bc44 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Tue, 26 Mar 2019 18:13:31 +0300 Subject: [PATCH] optimized arguments handling, moved out of hot zone --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 51fc535..dd7cbf1 100644 --- a/index.js +++ b/index.js @@ -178,7 +178,10 @@ const proto = Object.defineProperties(() => {}, { }); const createBuilder = (self, _styles, _isEmpty) => { - const builder = (...arguments_) => applyStyle(builder, ...arguments_); + const builder = (...arguments_) => { + // eslint-disable-next-line no-implicit-coercion + return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' ')); + }; // `__proto__` is used because we must return a function, but there is // no way to create a function with a different prototype @@ -191,9 +194,7 @@ const createBuilder = (self, _styles, _isEmpty) => { return builder; }; -const applyStyle = (self, ...arguments_) => { - let string = arguments_.join(' '); - +const applyStyle = (self, string) => { if (!self.enabled || self.level <= 0 || !string) { return self._isEmpty ? '' : string; }