-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringUtil.ts
37 lines (31 loc) 路 1.06 KB
/
StringUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export function camelCase(words: string[], isPascalCase: boolean = false): string {
const casedWords = words.map(
word =>
word
.toLowerCase()
.charAt(0)
.toUpperCase() + word.slice(1),
);
if (!isPascalCase) {
casedWords[0] = casedWords[0].toLowerCase();
}
return casedWords.join('');
}
export function pascalCase(words: string[]): string {
return camelCase(words, true);
}
export function camelize(resourceName: string, isPascalCase = false): string {
return camelCase(resourceName.split('-'), isPascalCase);
}
export function generateServiceName(url: string): string {
const urlParts = url.split('/').filter(part => part.length && !part.startsWith('{'));
const lastUrlPart = urlParts[urlParts.length - 1];
const resourceName = lastUrlPart || 'Root';
return camelize(`${resourceName}-service`, true);
}
export function normalizeUrl(url: string): string {
return url.replace(/\/\{.*\}/g, '');
}
export function addStarsToNewline(text?: string): string {
return text ? text.replace(/([\r\n])/g, '$1 * ') : '';
}