I am trying to convert "getuserdetailsbyname" to ["get","user","details","by","name"] in short I am trying to convert the all small written varibale names to camel case. And so far I have not found a solution that could detect it and convert this to uppercase. With a words array I am able to convert "getuserdetailsbyname" to ["get","user","detail"] and the remaining array get discarded.Here is my code
import { words } from "popular-english-words";
import { splitIntoWords } from "@zzzzbov/split-into-words";
const word = words.getAll();
console.log("ALlWords", word);
// console.log("SplitIntoWords",splitIntoWords("getuserdetailsbytrim"))
function toUpperCase(compiledArray) {
for (let counter = 0; counter < compiledArray.length; counter++) {
if (counter != 0) {
compiledArray[counter] =
compiledArray[counter].charAt(0).toUpperCase() +
compiledArray[counter].slice(1);
}
}
return compiledArray;
}
function convertVariable(variableName) {
let compiledArray = [];
const bool = false;
for (let counter = 0; counter < variableName.length; counter++) {
if (counter > 2) {
if (word.includes(variableName.slice(0, counter))) {
console.log(variableName.slice(0, counter));
compiledArray.push(variableName.slice(0, counter));
variableName = variableName.slice(counter);
}
}
}
console.log("compiledArr", compiledArray);
}
convertVariable("getuserdetailbytrim");
convertVariable("getuserdetailedSubscriptions");
console.log(
"toUpperCase",
toUpperCase(["get", "user", "details", "from", "trim"])
);