web 3d图形渲染器
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.

137 lines
4.4 KiB

  1. # emoji-regex [![Build status](https://travis-ci.org/mathiasbynens/emoji-regex.svg?branch=main)](https://travis-ci.org/mathiasbynens/emoji-regex)
  2. _emoji-regex_ offers a regular expression to match all emoji symbols and sequences (including textual representations of emoji) as per the Unicode Standard.
  3. This repository contains a script that generates this regular expression based on [Unicode data](https://github.com/node-unicode/node-unicode-data). Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard.
  4. ## Installation
  5. Via [npm](https://www.npmjs.com/):
  6. ```bash
  7. npm install emoji-regex
  8. ```
  9. In [Node.js](https://nodejs.org/):
  10. ```js
  11. const emojiRegex = require('emoji-regex/RGI_Emoji.js');
  12. // Note: because the regular expression has the global flag set, this module
  13. // exports a function that returns the regex rather than exporting the regular
  14. // expression itself, to make it impossible to (accidentally) mutate the
  15. // original regular expression.
  16. const text = `
  17. \u{231A}: ⌚ default emoji presentation character (Emoji_Presentation)
  18. \u{2194}\u{FE0F}: ↔️ default text presentation character rendered as emoji
  19. \u{1F469}: 👩 emoji modifier base (Emoji_Modifier_Base)
  20. \u{1F469}\u{1F3FF}: 👩🏿 emoji modifier base followed by a modifier
  21. `;
  22. const regex = emojiRegex();
  23. let match;
  24. while (match = regex.exec(text)) {
  25. const emoji = match[0];
  26. console.log(`Matched sequence ${ emoji } — code points: ${ [...emoji].length }`);
  27. }
  28. ```
  29. Console output:
  30. ```
  31. Matched sequence ⌚ — code points: 1
  32. Matched sequence ⌚ — code points: 1
  33. Matched sequence ↔️ — code points: 2
  34. Matched sequence ↔️ — code points: 2
  35. Matched sequence 👩 — code points: 1
  36. Matched sequence 👩 — code points: 1
  37. Matched sequence 👩🏿 — code points: 2
  38. Matched sequence 👩🏿 — code points: 2
  39. ```
  40. ## Regular expression flavors
  41. The package comes with three distinct regular expressions:
  42. ```js
  43. // This is the recommended regular expression to use. It matches all
  44. // emoji recommended for general interchange, as defined via the
  45. // `RGI_Emoji` property in the Unicode Standard.
  46. // https://unicode.org/reports/tr51/#def_rgi_set
  47. // When in doubt, use this!
  48. const emojiRegexRGI = require('emoji-regex/RGI_Emoji.js');
  49. // This is the old regular expression, prior to `RGI_Emoji` being
  50. // standardized. In addition to all `RGI_Emoji` sequences, it matches
  51. // some emoji you probably don’t want to match (such as emoji component
  52. // symbols that are not meant to be used separately).
  53. const emojiRegex = require('emoji-regex/index.js');
  54. // This regular expression matches even more emoji than the previous
  55. // one, including emoji that render as text instead of icons (i.e.
  56. // emoji that are not `Emoji_Presentation` symbols and that aren’t
  57. // forced to render as emoji by a variation selector).
  58. const emojiRegexText = require('emoji-regex/text.js');
  59. ```
  60. Additionally, in environments which support ES2015 Unicode escapes, you may `require` ES2015-style versions of the regexes:
  61. ```js
  62. const emojiRegexRGI = require('emoji-regex/es2015/RGI_Emoji.js');
  63. const emojiRegex = require('emoji-regex/es2015/index.js');
  64. const emojiRegexText = require('emoji-regex/es2015/text.js');
  65. ```
  66. ## For maintainers
  67. ### How to update emoji-regex after new Unicode Standard releases
  68. 1. Update the Unicode data dependency in `package.json` by running the following commands:
  69. ```sh
  70. # Example: updating from Unicode v12 to Unicode v13.
  71. npm uninstall @unicode/unicode-12.0.0
  72. npm install @unicode/unicode-13.0.0 --save-dev
  73. ````
  74. 1. Generate the new output:
  75. ```sh
  76. npm run build
  77. ```
  78. 1. Verify that tests still pass:
  79. ```sh
  80. npm test
  81. ```
  82. 1. Send a pull request with the changes, and get it reviewed & merged.
  83. 1. On the `main` branch, bump the emoji-regex version number in `package.json`:
  84. ```sh
  85. npm version patch -m 'Release v%s'
  86. ```
  87. Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).
  88. Note that this produces a Git commit + tag.
  89. 1. Push the release commit and tag:
  90. ```sh
  91. git push
  92. ```
  93. Our CI then automatically publishes the new release to npm.
  94. ## Author
  95. | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
  96. |---|
  97. | [Mathias Bynens](https://mathiasbynens.be/) |
  98. ## License
  99. _emoji-regex_ is available under the [MIT](https://mths.be/mit) license.