Created
November 1, 2017 17:39
-
-
Save gitexec/36a409beba258c7f67bef5d6831dafa0 to your computer and use it in GitHub Desktop.
transform-dashed-strings-to-Caps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildReactExternals(dependenciesArray){ | |
let externals = dependenciesArray.reduce((dependencies, curr, index, array) => { | |
let secondCapIndex = curr.indexOf('-'); | |
let lastCapIndex = curr.lastIndexOf('-'); | |
let firstCap, secondCap, middleCap, valueCap = curr, key, lastCap; | |
firstCap = curr.charAt(0).toUpperCase(); | |
if (secondCapIndex !== -1) { | |
secondCapIndex++; | |
secondCap = valueCap.charAt(secondCapIndex).toUpperCase(); //curr.substring(1, secondCapIndex + 1) + curr.charAt(secondCapIndex+1).toUpperCase() + curr.substring(secondCapIndex + 2); | |
} | |
if (secondCapIndex !== -1 && lastCapIndex !== -1) { | |
lastCapIndex++; | |
lastCap = valueCap.charAt(lastCapIndex).toUpperCase(); //secondCap.substring(0, lastCapIndex) + curr.charAt(lastCapIndex+1).toUpperCase() + curr.substring(lastCapIndex + 2); | |
} | |
if (secondCap) | |
valueCap = firstCap + valueCap.substring(1, secondCapIndex) + secondCap + valueCap.substring(secondCapIndex + 1); | |
if (secondCap && lastCap) | |
valueCap = valueCap.substring(0, lastCapIndex) + lastCap + valueCap.substring(lastCapIndex + 1); | |
if (!secondCap || !lastCap) | |
valueCap = firstCap + valueCap.substring(1); | |
valueCap = valueCap.split('-').join(''); | |
key = `${curr}`; | |
dependencies[key] = `${valueCap}`; | |
return dependencies; | |
}, {}); | |
return externals; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment