made functions more rezilient

This commit is contained in:
Timo Bejan 2021-09-30 10:16:29 +03:00
parent 1ab7d6bbad
commit 54eb8173cf

View File

@ -1,12 +1,18 @@
import { tap } from 'rxjs/operators';
import {tap} from 'rxjs/operators';
export function capitalize(value: string): string {
if (!value) {
return "";
}
return value.charAt(0).toUpperCase() + value.slice(1);
}
export function humanize(value: string, lowercase = true): string {
const words = (lowercase ? value.toLowerCase() : value).split(/[ \-_]+/);
if (!value) {
return "";
}
const words = (lowercase ? value.toLowerCase() : value).split(/[ \-_]+/);
return words.map(capitalize).join(' ');
}