_hasUnicode.js 949 B

123456789101112131415161718192021222324252627
  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 rsZWJ = '\\u200d';
  10. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  11. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  12. /**
  13. * Checks if `string` contains Unicode symbols.
  14. *
  15. * @private
  16. * @param {string} string The string to inspect.
  17. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  18. */
  19. function hasUnicode(string) {
  20. return reHasUnicode.test(string);
  21. }
  22. module.exports = hasUnicode;