Skip to content

Commit

Permalink
nicer generator based capitlizeFirstLetter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadav Sinai committed Sep 26, 2018
1 parent 2f46c71 commit 539c400
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/html-elements-webpack-plugin.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 539c400

Please sign in to comment.