Skip to content

Instantly share code, notes, and snippets.

@devbyray
Created December 31, 2021 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devbyray/5f880b0e20a36080be49487335a2cffe to your computer and use it in GitHub Desktop.
Save devbyray/5f880b0e20a36080be49487335a2cffe to your computer and use it in GitHub Desktop.
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