name.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { emojiComponents } from '../data.mjs';
  2. const nameSplit = ": ";
  3. const variationSplit = ", ";
  4. const ignoredVariations = /* @__PURE__ */ new Set(["person"]);
  5. function splitEmojiNameVariations(name, sequence, componentsData) {
  6. const parts = name.split(nameSplit);
  7. const base = parts.shift();
  8. if (!parts.length) {
  9. return {
  10. base,
  11. key: base
  12. };
  13. }
  14. const variations = parts.join(nameSplit).split(variationSplit).filter((text) => {
  15. const type = componentsData.types[text];
  16. if (!type) {
  17. return !ignoredVariations.has(text);
  18. }
  19. return false;
  20. });
  21. const key = base + (variations.length ? nameSplit + variations.join(variationSplit) : "");
  22. const result = {
  23. base,
  24. key
  25. };
  26. let components = 0;
  27. for (let index = 0; index < sequence.length; index++) {
  28. const num = sequence[index];
  29. for (const key2 in emojiComponents) {
  30. const type = key2;
  31. const range = emojiComponents[type];
  32. if (num >= range[0] && num < range[1]) {
  33. variations.push({
  34. index,
  35. type
  36. });
  37. components++;
  38. }
  39. }
  40. }
  41. if (variations.length) {
  42. result.variations = variations;
  43. }
  44. if (components) {
  45. result.components = components;
  46. }
  47. return result;
  48. }
  49. export { splitEmojiNameVariations };