-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathdeburr.js
35 lines (29 loc) · 1.21 KB
/
deburr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import deburrLetter from './internal/deburrLetter';
import toString from './toString';
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
/** Used to compose unicode character classes. */
var rsComboRange = '\\u0300-\\u036f\\ufe20-\\ufe23';
/** Used to compose unicode capture groups. */
var rsCombo = '[' + rsComboRange + ']';
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
var reComboMark = RegExp(rsCombo, 'g');
/**
* Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
* to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to deburr.
* @returns {string} Returns the deburred string.
* @example
*
* _.deburr('déjà vu');
* // => 'deja vu'
*/
function deburr(string) {
string = toString(string);
return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
}
export default deburr;