You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

4 years ago
  1. var deburrLetter = require('./_deburrLetter'),
  2. toString = require('./toString');
  3. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  4. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  5. /** Used to compose unicode character classes. */
  6. var rsComboMarksRange = '\\u0300-\\u036f',
  7. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  8. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  9. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
  10. /** Used to compose unicode capture groups. */
  11. var rsCombo = '[' + rsComboRange + ']';
  12. /**
  13. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  14. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  15. */
  16. var reComboMark = RegExp(rsCombo, 'g');
  17. /**
  18. * Deburrs `string` by converting
  19. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  20. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  21. * letters to basic Latin letters and removing
  22. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  23. *
  24. * @static
  25. * @memberOf _
  26. * @since 3.0.0
  27. * @category String
  28. * @param {string} [string=''] The string to deburr.
  29. * @returns {string} Returns the deburred string.
  30. * @example
  31. *
  32. * _.deburr('déjà vu');
  33. * // => 'deja vu'
  34. */
  35. function deburr(string) {
  36. string = toString(string);
  37. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  38. }
  39. module.exports = deburr;