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