normalize-string.ts 453 B

12345678910111213
  1. /**
  2. * Normalizes a string to replace non-alphanumeric and diacritical marks with
  3. * plain equivalents.
  4. * Based on https://stackoverflow.com/a/37511463/772859
  5. */
  6. export function normalizeString(input: string, spaceReplacer = ' '): string {
  7. return input
  8. .normalize('NFD')
  9. .replace(/[\u0300-\u036f]/g, '')
  10. .toLowerCase()
  11. .replace(/[!"£$%^&*()+[\]{};:@#~?\\/,|><`¬]/g, '')
  12. .replace(/\s+/g, spaceReplacer);
  13. }