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