JAVASCRIPT   83

deburr js

Guest on 26th June 2022 03:54:10 AM

  1. var baseToString = require('../internal/baseToString'),
  2.     deburrLetter = require('../internal/deburrLetter');
  3.  
  4. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  5. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  6.  
  7. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  8. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  9.  
  10. /**
  11.  * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  12.  * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13.  *
  14.  * @static
  15.  * @memberOf _
  16.  * @category String
  17.  * @param {string} [string=''] The string to deburr.
  18.  * @returns {string} Returns the deburred string.
  19.  * @example
  20.  *
  21.  * _.deburr('dĆ©jĆ  vu');
  22.  * // => 'deja vu'
  23.  */ */
  24. function deburr(string) {
  25.   string = baseToString(string);
  26.   return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  27. }
  28.  
  29. module.exports = debu

Raw Paste


Login or Register to edit or fork this paste. It's free.