Skip to content

Instantly share code, notes, and snippets.

@devbyray
Created Dec 31, 2021
Embed
What would you like to do?
public formatInitials(value: string): string {
if (!value || value === '') {
return value;
}
let format = value.split('').map((val) => val.toUpperCase());
let formatted = [];
if (value.toLowerCase().includes('th')) {
const regex = /(\bth\b)/gm;
format = value.trim().split(regex);
formatted = format
.filter((val) => /\w+/gm.test(val))
.map((val) => {
return val.trim().split(/\W+/gm);
})
.flat();
} else {
formatted = format.map((val) => val.trim());
}
const voorletters =
formatted
.filter((val) => /\w+/gm.test(val))
.map((val) => val.trim().replace('.', '').replace(',', ''))
.map((val) => {
if (!val.toLowerCase().includes('th')) {
return val.toUpperCase();
}
return val;
})
.join('.') + '.';
return voorletters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment