From 6f7474417af6adc76750abe6d7c90ff70559ed07 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Fri, 26 Jul 2024 22:48:05 +0200 Subject: [PATCH] inline `is_uppercase` for perf --- index.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index cfdd5d0..719f563 100644 --- a/index.js +++ b/index.js @@ -13,17 +13,10 @@ const TYPE_SELECTOR = 'Selector' const TYPE_DECLARATION = 'Declaration' const TYPE_OPERATOR = 'Operator' -/** - * Check if a string contains uppercase characters - * @param {string} str - */ -function is_uppercase(str) { - return /[A-Z]/.test(str) -} - /** @param {string} str */ function lowercase(str) { - if (is_uppercase(str)) { + // Only create new strings in memory if we need to + if (/[A-Z]/.test(str)) { return str.toLowerCase() } return str