diff --git a/packages/utils/src/emoji/format.ts b/packages/utils/src/emoji/format.ts index 225399f..f2487d0 100644 --- a/packages/utils/src/emoji/format.ts +++ b/packages/utils/src/emoji/format.ts @@ -89,28 +89,6 @@ export function getEmojiSequenceString( }); } -const regexOptions: UnicodeFormattingOptions = { - prefix: '\\u', - separator: '', - case: 'upper', - format: 'utf-16', - add0: false, - throwOnError: true, -}; - -/** - * Merge unicode numbers sequence as regex - */ -export function emojiSequenceToRegex( - sequence: number[], - throwOnError = true -): string { - return convert(sequence, { - ...regexOptions, - throwOnError, - }); -} - const keywordOptions: UnicodeFormattingOptions = { prefix: '', separator: '-', diff --git a/packages/utils/src/emoji/regex/create.ts b/packages/utils/src/emoji/regex/create.ts index b93b1d8..a09d103 100644 --- a/packages/utils/src/emoji/regex/create.ts +++ b/packages/utils/src/emoji/regex/create.ts @@ -1,6 +1,6 @@ import { getEmojiSequenceFromString } from '../cleanup'; import { convertEmojiSequenceToUTF32 } from '../convert'; -import { addOptionalVariations } from '../variations'; +import { addOptionalEmojiVariations } from '../variations'; import { createEmojisTree, parseEmojiTree } from './tree'; /** @@ -26,14 +26,16 @@ export function createOptimisedRegexForEmojiSequences( * Create optimised regex for emojis */ export function createOptimisedRegex( - emojis: string[], + emojis: (string | number[])[], testData?: number[][] ): string { // Convert to numbers - let sequences = emojis.map(getEmojiSequenceFromString); + let sequences = emojis.map((item) => + typeof item === 'string' ? getEmojiSequenceFromString(item) : item + ); // Add variations - sequences = addOptionalVariations(sequences, testData); + sequences = addOptionalEmojiVariations(sequences, testData); // Parse return createOptimisedRegexForEmojiSequences(sequences); diff --git a/packages/utils/src/emoji/variations.ts b/packages/utils/src/emoji/variations.ts index bc40724..8456bca 100644 --- a/packages/utils/src/emoji/variations.ts +++ b/packages/utils/src/emoji/variations.ts @@ -16,7 +16,7 @@ import { getEmojiSequenceString } from './format'; * `testData`, returned by parseEmojiTestFile() is used to check which emojis have `FE0F` variations. * If missing or emoji is missing in test data, `FE0F` is added to every single code emoji. */ -export function addOptionalVariations( +export function addOptionalEmojiVariations( sequences: number[][], testData?: number[][] ): number[][] { diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 2e8f62c..3475ed0 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -83,6 +83,36 @@ export { getCustomIcon } from './loader/custom'; export { searchForIcon } from './loader/modern'; export { loadIcon } from './loader/loader'; +// Emojis +export { + getEmojiSequenceFromString, + splitEmojiSequences, + joinEmojiSequences, + removeEmojiVariations, + removeEmojiTones, + mapEmojiSequences, +} from './emoji/cleanup'; +export { + getEmojiCodePoint, + splitUTF32Number, + isUTF32SplitNumber, + mergeUTF32Numbers, + getEmojiUnicode, + convertEmojiSequenceToUTF16, + convertEmojiSequenceToUTF32, +} from './emoji/convert'; +export { + getEmojiUnicodeString, + getEmojiSequenceString, + emojiSequenceToKeyword, +} from './emoji/format'; +export { parseEmojiTestFile } from './emoji/parse-test'; +export { addOptionalEmojiVariations } from './emoji/variations'; +export { + createOptimisedRegex, + createOptimisedRegexForEmojiSequences, +} from './emoji/regex/create'; + // Misc export { camelize, camelToKebab, snakelize, pascalize } from './misc/strings'; export { diff --git a/packages/utils/tests/emoji-format-test.ts b/packages/utils/tests/emoji-format-test.ts index f757ed2..0cab9e4 100644 --- a/packages/utils/tests/emoji-format-test.ts +++ b/packages/utils/tests/emoji-format-test.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { getEmojiSequenceString, - emojiSequenceToRegex, emojiSequenceToKeyword, } from '../lib/emoji/format'; @@ -9,7 +8,6 @@ describe('Testing formatting emoji code points', () => { it('Empty sequence', () => { const sequence: number[] = []; expect(getEmojiSequenceString(sequence)).toBe(''); - expect(emojiSequenceToRegex(sequence)).toBe(''); expect(emojiSequenceToKeyword(sequence)).toBe(''); }); @@ -17,7 +15,6 @@ describe('Testing formatting emoji code points', () => { const sequence: number[] = [0x23, 0xfe0f, 0x20e3]; expect(getEmojiSequenceString(sequence)).toBe('23-fe0f-20e3'); - expect(emojiSequenceToRegex(sequence)).toBe('\\u23\\uFE0F\\u20E3'); expect(emojiSequenceToKeyword(sequence)).toBe('0023-fe0f-20e3'); }); @@ -30,9 +27,6 @@ describe('Testing formatting emoji code points', () => { expect(getEmojiSequenceString(sequence)).toBe( '1f441-fe0f-200d-1f5e8-fe0f' ); - expect(emojiSequenceToRegex(sequence)).toBe( - '\\uD83D\\uDC41\\uFE0F\\u200D\\uD83D\\uDDE8\\uFE0F' - ); expect(emojiSequenceToKeyword(sequence)).toBe( '1f441-fe0f-200d-1f5e8-fe0f' ); @@ -45,9 +39,6 @@ describe('Testing formatting emoji code points', () => { expect(getEmojiSequenceString(sequence)).toBe( '1f441-fe0f-200d-1f5e8-fe0f' ); - expect(emojiSequenceToRegex(sequence)).toBe( - '\\uD83D\\uDC41\\uFE0F\\u200D\\uD83D\\uDDE8\\uFE0F' - ); expect(emojiSequenceToKeyword(sequence)).toBe( '1f441-fe0f-200d-1f5e8-fe0f' ); diff --git a/packages/utils/tests/emoji-optional-variations-test.ts b/packages/utils/tests/emoji-optional-variations-test.ts index eb76553..4296fa6 100644 --- a/packages/utils/tests/emoji-optional-variations-test.ts +++ b/packages/utils/tests/emoji-optional-variations-test.ts @@ -3,7 +3,7 @@ import { readFile, writeFile, unlink } from 'node:fs/promises'; import { getEmojiSequenceFromString } from '../lib/emoji/cleanup'; import { getEmojiSequenceString } from '../lib/emoji/format'; import { parseEmojiTestFile } from '../lib/emoji/parse-test'; -import { addOptionalVariations } from '../lib/emoji/variations'; +import { addOptionalEmojiVariations } from '../lib/emoji/variations'; describe('Optional variations of emoji sequences', () => { it('Variations without data', () => { @@ -25,7 +25,7 @@ describe('Optional variations of emoji sequences', () => { '1F9D7 1F3FE 200D 2640 FE0F', '1F9D7 1F3FF 200D 2642 ', ].map(getEmojiSequenceFromString); - const results = addOptionalVariations(sequences); + const results = addOptionalEmojiVariations(sequences); expect( results.map((sequence) => getEmojiSequenceString(sequence, { @@ -106,7 +106,7 @@ describe('Optional variations of emoji sequences', () => { // fake keycap, not in test file '2345 20E3 200D 1235', ].map(getEmojiSequenceFromString); - const results = addOptionalVariations(sequences, testData); + const results = addOptionalEmojiVariations(sequences, testData); expect( results.map((sequence) => getEmojiSequenceString(sequence, {