Skip to content

Commit 539c400

Browse files
author
Nadav Sinai
committed
nicer generator based capitlizeFirstLetter
1 parent 2f46c71 commit 539c400

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

lib/html-elements-webpack-plugin.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
const RE_ENDS_WITH_BS = /\/$/;
22

3-
function capitlizeFirstLetter(str) {
4-
let [first, ...rest] = str;
5-
first = first.toUpperCase();
6-
return [first, ...rest].join('');
3+
function* capitlizeFirstLetter(str) {
4+
for (let [i, l] of Array.from(str).entries()) {
5+
yield (i === 0) ? l.toUpperCase() : l;
6+
}
7+
}
8+
9+
function* capitalizeWordsArray(rest) {
10+
for (let word of rest) {
11+
yield* capitlizeFirstLetter(word);
12+
}
713
}
814

915
function kebbabCase2CamelCase(str) {
1016
const strArr = str.split('-');
1117
if (strArr.length < 2) return str;
1218
let [first, ...rest] = strArr;
13-
rest = rest.map(capitlizeFirstLetter);
14-
return [first, ...rest].join('');
19+
const restGen = capitalizeWordsArray(rest);
20+
return [first, ...restGen].join('');
1521
}
1622

1723
function compatAddPlugin(tappable, hookName, callback, async = false, forType = null) {

0 commit comments

Comments
 (0)