export const getHyphenatedText = (req: express.Request, res: express.Response) => {
const text = req.query.text || "";
const textList = [];
let tempTextHolder = "";
text.split("").forEach((character, index) => {
const pushToListResetTempText = () => {
textList.push(tempTextHolder.toLowerCase());
tempTextHolder = "";
};
if (tempTextHolder) {
const isUpperCaseCharater = isUpperCase(character) &&
!isNumber(character);
if (isUpperCaseCharater) {
pushToListResetTempText();
}
else if (
isNumber(character) && !Number.isInteger(Number(tempTextHolder))
) {
pushToListResetTempText();
}
}
tempTextHolder += character;
if (index === text.length - 1) {
pushToListResetTempText();
}
});
return res.send(
`For text query: ${text}, hyphenated response is: ${textList.join("-")}`,
);
};