_unicodeToArray.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /** Used to compose unicode character classes. */
  2. var rsAstralRange = '\\ud800-\\udfff',
  3. rsComboMarksRange = '\\u0300-\\u036f',
  4. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  5. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  6. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  7. rsVarRange = '\\ufe0e\\ufe0f';
  8. /** Used to compose unicode capture groups. */
  9. var rsAstral = '[' + rsAstralRange + ']',
  10. rsCombo = '[' + rsComboRange + ']',
  11. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  12. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  13. rsNonAstral = '[^' + rsAstralRange + ']',
  14. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  15. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  16. rsZWJ = '\\u200d';
  17. /** Used to compose unicode regexes. */
  18. var reOptMod = rsModifier + '?',
  19. rsOptVar = '[' + rsVarRange + ']?',
  20. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  21. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  22. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  23. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  24. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  25. /**
  26. * Converts a Unicode `string` to an array.
  27. *
  28. * @private
  29. * @param {string} string The string to convert.
  30. * @returns {Array} Returns the converted array.
  31. */
  32. function unicodeToArray(string) {
  33. return string.match(reUnicode) || [];
  34. }
  35. module.exports = unicodeToArray;