2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 06:28:24 +00:00

chore: add emoji functions to main exports, remove unused code, rename few emoji functions

This commit is contained in:
Vjacheslav Trushkin 2022-12-10 10:15:34 +02:00
parent dd179767f6
commit 024522fdf6
6 changed files with 40 additions and 39 deletions

View File

@ -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: '-',

View File

@ -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);

View File

@ -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[][] {

View File

@ -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 {

View File

@ -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'
);

View File

@ -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, {