forked from kevin.shehu/GGD
41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
|
/** Used to compose unicode character classes. */
|
||
|
var rsAstralRange = '\\ud800-\\udfff',
|
||
|
rsComboMarksRange = '\\u0300-\\u036f',
|
||
|
reComboHalfMarksRange = '\\ufe20-\\ufe2f',
|
||
|
rsComboSymbolsRange = '\\u20d0-\\u20ff',
|
||
|
rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
|
||
|
rsVarRange = '\\ufe0e\\ufe0f';
|
||
|
|
||
|
/** Used to compose unicode capture groups. */
|
||
|
var rsAstral = '[' + rsAstralRange + ']',
|
||
|
rsCombo = '[' + rsComboRange + ']',
|
||
|
rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
||
|
rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
|
||
|
rsNonAstral = '[^' + rsAstralRange + ']',
|
||
|
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
||
|
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
||
|
rsZWJ = '\\u200d';
|
||
|
|
||
|
/** Used to compose unicode regexes. */
|
||
|
var reOptMod = rsModifier + '?',
|
||
|
rsOptVar = '[' + rsVarRange + ']?',
|
||
|
rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
|
||
|
rsSeq = rsOptVar + reOptMod + rsOptJoin,
|
||
|
rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
|
||
|
|
||
|
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
||
|
var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
|
||
|
|
||
|
/**
|
||
|
* Converts a Unicode `string` to an array.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to convert.
|
||
|
* @returns {Array} Returns the converted array.
|
||
|
*/
|
||
|
function unicodeToArray(string) {
|
||
|
return string.match(reUnicode) || [];
|
||
|
}
|
||
|
|
||
|
module.exports = unicodeToArray;
|