mirror of https://github.com/lukechilds/node.git
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.
40 lines
1.4 KiB
40 lines
1.4 KiB
9 years ago
|
var deburrLetter = require('./_deburrLetter'),
|
||
|
toString = require('./toString');
|
||
10 years ago
|
|
||
|
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
|
||
|
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
|
||
|
|
||
9 years ago
|
/** Used to compose unicode character classes. */
|
||
|
var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
||
|
rsComboSymbolsRange = '\\u20d0-\\u20f0';
|
||
|
|
||
|
/** Used to compose unicode capture groups. */
|
||
|
var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
|
||
|
|
||
|
/**
|
||
|
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
|
||
|
* [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
|
||
|
*/
|
||
|
var reComboMark = RegExp(rsCombo, 'g');
|
||
|
|
||
10 years ago
|
/**
|
||
|
* 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) {
|
||
9 years ago
|
string = toString(string);
|
||
10 years ago
|
return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
|
||
|
}
|
||
|
|
||
|
module.exports = deburr;
|