mirror of
https://github.com/iconify/iconify.git
synced 2025-01-06 07:20:40 +00:00
chore(utils): restructure some emoji code
This commit is contained in:
parent
70758ebfa6
commit
5a78469fdb
@ -137,6 +137,16 @@
|
||||
"import": "./lib/emoji/replace/replace.mjs",
|
||||
"types": "./lib/emoji/replace/replace.d.ts"
|
||||
},
|
||||
"./lib/emoji/test/parse": {
|
||||
"require": "./lib/emoji/test/parse.cjs",
|
||||
"import": "./lib/emoji/test/parse.mjs",
|
||||
"types": "./lib/emoji/test/parse.d.ts"
|
||||
},
|
||||
"./lib/emoji/test/variations": {
|
||||
"require": "./lib/emoji/test/variations.cjs",
|
||||
"import": "./lib/emoji/test/variations.mjs",
|
||||
"types": "./lib/emoji/test/variations.d.ts"
|
||||
},
|
||||
"./lib/emoji/cleanup": {
|
||||
"require": "./lib/emoji/cleanup.cjs",
|
||||
"import": "./lib/emoji/cleanup.mjs",
|
||||
@ -157,16 +167,6 @@
|
||||
"import": "./lib/emoji/format.mjs",
|
||||
"types": "./lib/emoji/format.d.ts"
|
||||
},
|
||||
"./lib/emoji/parse-test": {
|
||||
"require": "./lib/emoji/parse-test.cjs",
|
||||
"import": "./lib/emoji/parse-test.mjs",
|
||||
"types": "./lib/emoji/parse-test.d.ts"
|
||||
},
|
||||
"./lib/emoji/variations": {
|
||||
"require": "./lib/emoji/variations.cjs",
|
||||
"import": "./lib/emoji/variations.mjs",
|
||||
"types": "./lib/emoji/variations.d.ts"
|
||||
},
|
||||
"./lib/icon-set/convert-info": {
|
||||
"require": "./lib/icon-set/convert-info.cjs",
|
||||
"import": "./lib/icon-set/convert-info.mjs",
|
||||
|
@ -75,8 +75,8 @@ export function removeEmojiVariations(sequence: number[]): number[] {
|
||||
*/
|
||||
export function removeEmojiTones(sequence: number[]): number[] {
|
||||
return sequence.filter((code) => {
|
||||
for (let i = 0; i < emojiTones.length; i++) {
|
||||
const range = emojiTones[i];
|
||||
for (const key in emojiTones) {
|
||||
const range = emojiTones[key as keyof typeof emojiTones];
|
||||
if (code >= range[0] && code < range[1]) {
|
||||
return false;
|
||||
}
|
||||
@ -85,6 +85,13 @@ export function removeEmojiTones(sequence: number[]): number[] {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unqualified sequence
|
||||
*/
|
||||
export function getUnqualifiedEmojiSequence(sequence: number[]): number[] {
|
||||
return sequence.filter((num) => num !== vs16Emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Types for mapEmojiSequence()
|
||||
*/
|
||||
|
@ -16,13 +16,14 @@ export const keycapEmoji = 0x20e3;
|
||||
*
|
||||
* First value in array is minimum, second value is maximum+1
|
||||
*/
|
||||
type ToneType = 'skin' | 'hair';
|
||||
type Range = [number, number];
|
||||
export const emojiTones: Range[] = [
|
||||
export const emojiTones: Record<ToneType, Range> = {
|
||||
// Skin tones
|
||||
[0x1f3fb, 0x1f400],
|
||||
skin: [0x1f3fb, 0x1f400],
|
||||
// Hair tones
|
||||
[0x1f9b0, 0x1f9b4],
|
||||
];
|
||||
hair: [0x1f9b0, 0x1f9b4],
|
||||
};
|
||||
|
||||
/**
|
||||
* Minimum UTF-32 number
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getEmojiSequenceFromString } from '../cleanup';
|
||||
import { convertEmojiSequenceToUTF32 } from '../convert';
|
||||
import { addOptionalEmojiVariations } from '../variations';
|
||||
import { addOptionalEmojiVariations } from '../test/variations';
|
||||
import { createEmojisTree, parseEmojiTree } from './tree';
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { getEmojiSequenceFromString } from './cleanup';
|
||||
import { getEmojiSequenceString } from './format';
|
||||
import { getUnqualifiedEmojiSequence } from './variations';
|
||||
import {
|
||||
getEmojiSequenceFromString,
|
||||
getUnqualifiedEmojiSequence,
|
||||
} from '../cleanup';
|
||||
import { getEmojiSequenceString } from '../format';
|
||||
|
||||
// Emoji types
|
||||
type EmojiStatus =
|
@ -3,18 +3,11 @@ import {
|
||||
joinEmojiSequences,
|
||||
removeEmojiVariations,
|
||||
splitEmojiSequences,
|
||||
} from './cleanup';
|
||||
import { convertEmojiSequenceToUTF32 } from './convert';
|
||||
import { keycapEmoji, vs16Emoji } from './data';
|
||||
import { getEmojiSequenceString } from './format';
|
||||
import { getQualifiedEmojiSequencesMap } from './parse-test';
|
||||
|
||||
/**
|
||||
* Get unqualified sequence
|
||||
*/
|
||||
export function getUnqualifiedEmojiSequence(sequence: number[]): number[] {
|
||||
return sequence.filter((num) => num !== vs16Emoji);
|
||||
}
|
||||
} from '../cleanup';
|
||||
import { convertEmojiSequenceToUTF32 } from '../convert';
|
||||
import { keycapEmoji, vs16Emoji } from '../data';
|
||||
import { getEmojiSequenceString } from '../format';
|
||||
import { EmojiTestDataItem, getQualifiedEmojiSequencesMap } from './parse';
|
||||
|
||||
/**
|
||||
* Get qualified sequence, adding optional `FE0F` wherever it might exist
|
||||
@ -50,25 +43,29 @@ export function guessQualifiedEmojiSequence(sequence: number[]): number[] {
|
||||
*
|
||||
* `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.
|
||||
* It can also be an array of sequences.
|
||||
*/
|
||||
export function addOptionalEmojiVariations(
|
||||
sequences: number[][],
|
||||
testData?: number[][]
|
||||
testData?: (number[] | EmojiTestDataItem)[]
|
||||
): number[][];
|
||||
export function addOptionalEmojiVariations(
|
||||
sequences: number[][],
|
||||
testData: number[][],
|
||||
testData: (number[] | EmojiTestDataItem)[],
|
||||
toString: (value: number[]) => string
|
||||
): string[];
|
||||
export function addOptionalEmojiVariations(
|
||||
sequences: number[][],
|
||||
testData: number[][] = [],
|
||||
testData: (number[] | EmojiTestDataItem)[] = [],
|
||||
toString?: (value: number[]) => string
|
||||
): number[][] | string[] {
|
||||
const convert = toString || getEmojiSequenceString;
|
||||
const testSequences = testData.map((item) =>
|
||||
item instanceof Array ? item : item.sequence
|
||||
);
|
||||
|
||||
// Map test data
|
||||
const testDataMap = getQualifiedEmojiSequencesMap(testData, convert);
|
||||
const testDataMap = getQualifiedEmojiSequencesMap(testSequences, convert);
|
||||
|
||||
// Parse all sequences
|
||||
const set: Set<string> = new Set();
|
@ -86,6 +86,7 @@ export { loadIcon } from './loader/loader';
|
||||
// Emojis
|
||||
export {
|
||||
getEmojiSequenceFromString,
|
||||
getUnqualifiedEmojiSequence,
|
||||
removeEmojiVariations,
|
||||
removeEmojiTones,
|
||||
mapEmojiSequences,
|
||||
@ -103,11 +104,8 @@ export { getEmojiUnicodeString, getEmojiSequenceString } from './emoji/format';
|
||||
export {
|
||||
parseEmojiTestFile,
|
||||
getQualifiedEmojiSequencesMap,
|
||||
} from './emoji/parse-test';
|
||||
export {
|
||||
getUnqualifiedEmojiSequence,
|
||||
addOptionalEmojiVariations,
|
||||
} from './emoji/variations';
|
||||
} from './emoji/test/parse';
|
||||
export { addOptionalEmojiVariations } from './emoji/test/variations';
|
||||
export {
|
||||
createOptimisedRegex,
|
||||
createOptimisedRegexForEmojiSequences,
|
||||
|
@ -4,8 +4,8 @@ import { getEmojiSequenceString } from '../lib/emoji/format';
|
||||
import {
|
||||
getQualifiedEmojiSequencesMap,
|
||||
parseEmojiTestFile,
|
||||
} from '../lib/emoji/parse-test';
|
||||
import { addOptionalEmojiVariations } from '../lib/emoji/variations';
|
||||
} from '../lib/emoji/test/parse';
|
||||
import { addOptionalEmojiVariations } from '../lib/emoji/test/variations';
|
||||
|
||||
describe('Optional variations of emoji sequences', () => {
|
||||
it('Variations without data', () => {
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
endUTF32Pair,
|
||||
minUTF32,
|
||||
} from '../lib/emoji/data';
|
||||
import { parseEmojiTestFile } from '../lib/emoji/parse-test';
|
||||
import { parseEmojiTestFile } from '../lib/emoji/test/parse';
|
||||
|
||||
describe('Testing emoji code points', () => {
|
||||
it('Checking available ranges', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user