UNPKG

2.28 kBTypeScriptView Raw
1type EmojifyFormat = (name: string, part?: string, input?: string) => string;
2interface EmojifyOptions {
3 /**
4 * The string to fallback to if an emoji was not found.
5 */
6 fallback?: ((part: string) => string) | string;
7 /**
8 * Adds a middleware layer to modify each matched emoji after parsing.
9 */
10 format?: EmojifyFormat;
11}
12/**
13 * Parse all markdown-encoded emojis in a string.
14 */
15declare const emojify: (input: string, { fallback, format }?: EmojifyOptions) => string;
16
17/**
18 * Get the name and character of an emoji.
19 */
20declare const find: (codeOrName: string) => {
21 emoji: string;
22 key: string;
23} | undefined;
24
25/**
26 * Get an emoji from an emoji name.
27 */
28declare const get: (codeOrName: string) => string | undefined;
29
30/**
31 * Check if this library supports a specific emoji.
32 */
33declare const has: (codeOrName: string) => boolean;
34
35/**
36 * Get a random emoji.
37 */
38declare const random: () => {
39 emoji: string;
40 name: string;
41};
42
43interface Emoji {
44 emoji: string;
45 key: string;
46}
47
48type ReplaceReplacement = (emoji: Emoji, index: number, string: string) => string;
49/**
50 * Replace the emojis in a string.
51 */
52declare const replace: (input: string, replacement: ReplaceReplacement | string, { preserveSpaces }?: {
53 preserveSpaces?: boolean | undefined;
54}) => string;
55
56/**
57 * Search for emojis containing the provided name or pattern in their name.
58 */
59declare const search: (keyword: RegExp | string) => {
60 emoji: string;
61 name: string;
62}[];
63
64interface StripOptions {
65 /**
66 * Whether to keep the extra space after a stripped emoji.
67 */
68 preserveSpaces?: boolean;
69}
70/**
71 * Remove all the emojis from a string.
72 */
73declare const strip: (input: string, { preserveSpaces }?: StripOptions) => string;
74
75/**
76 * Convert all emojis in a string to their markdown-encoded counterparts.
77 */
78declare const unemojify: (input: string) => string;
79
80interface WhichOptions {
81 markdown?: boolean;
82}
83/**
84 * Get an emoji name from an emoji.
85 */
86declare const which: (emoji: string, { markdown }?: WhichOptions) => string | undefined;
87
88export { type EmojifyFormat, type EmojifyOptions, type ReplaceReplacement, type StripOptions, type WhichOptions, emojify, find, get, has, random, replace, search, strip, unemojify, which };