From 539c400a5778b68728fc60f0da2efa7e95870e59 Mon Sep 17 00:00:00 2001 From: Nadav Sinai Date: Wed, 26 Sep 2018 10:22:31 +0300 Subject: [PATCH] nicer generator based capitlizeFirstLetter --- lib/html-elements-webpack-plugin.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/html-elements-webpack-plugin.js b/lib/html-elements-webpack-plugin.js index 6986542..2f7fc73 100644 --- a/lib/html-elements-webpack-plugin.js +++ b/lib/html-elements-webpack-plugin.js @@ -1,17 +1,23 @@ const RE_ENDS_WITH_BS = /\/$/; -function capitlizeFirstLetter(str) { - let [first, ...rest] = str; - first = first.toUpperCase(); - return [first, ...rest].join(''); +function* capitlizeFirstLetter(str) { + for (let [i, l] of Array.from(str).entries()) { + yield (i === 0) ? l.toUpperCase() : l; + } +} + +function* capitalizeWordsArray(rest) { + for (let word of rest) { + yield* capitlizeFirstLetter(word); + } } function kebbabCase2CamelCase(str) { const strArr = str.split('-'); if (strArr.length < 2) return str; let [first, ...rest] = strArr; - rest = rest.map(capitlizeFirstLetter); - return [first, ...rest].join(''); + const restGen = capitalizeWordsArray(rest); + return [first, ...restGen].join(''); } function compatAddPlugin(tappable, hookName, callback, async = false, forType = null) {