Open tshemsedinov opened 8 months ago
Since private static readonly nameDelimiters: string[] = [' ', '-']
static capitalizeName(name: string): string {
return name.split(/([- ])/g).map(ApplicationUtils.capitalizeFirstLetter).join('')
}
Pros: Much more readable Cons: Will call ApplicationUtils.capitalizeFirstLetter for delimiter with no effect But for fixing that it will look much more complex
static capitalizeName(name: string): string {
const splitList = name.split(/([- ])/g);
for(let i=0,len=splitList.length;i<len;i+=2) {
splitList[i] = ApplicationUtils.capitalizeFirstLetter(splitList[i])
}
return splitList.join('')
}
It is a good case for .map I suppose
https://github.com/diia-open-source/be-pkg-utils/blob/e969374fb769e59ab6bbdb709caeba0199e14a8c/src/applicationUtils.ts#L186-L206
capitalizeFirstLetter
is not neededif (foundDelimiters.length) {
this construction better use return-earlier pattern