2022-03-29 08:54:35 +00:00
|
|
|
/**
|
|
|
|
* If given to parse, this callback will be invoked per each found emoji.
|
|
|
|
*
|
|
|
|
* If this callback returns a falsy value instead of a valid `src` to use for the image, nothing will actually change for that specific emoji.
|
|
|
|
*
|
|
|
|
* @param icon the lower case HEX code point i.e. "1f4a9"
|
|
|
|
* @param options all info for this parsing operation
|
|
|
|
* @param variant the optional \uFE0F ("as image") variant, in case this info is anyhow meaningful. By default this is ignored.
|
|
|
|
*/
|
2022-04-30 06:56:42 +00:00
|
|
|
export type ParseCallback = (icon: string, options: object, variant: string) => string | false;
|
2022-03-29 08:54:35 +00:00
|
|
|
|
2022-04-30 06:56:42 +00:00
|
|
|
export type ReplacerFunction = (substring: string, ...args: any[]) => string;
|
2022-04-29 22:34:13 +00:00
|
|
|
|
2022-04-30 06:56:42 +00:00
|
|
|
export type TwemojiOptions = {
|
2020-02-13 14:50:17 +00:00
|
|
|
/**
|
2023-01-09 21:31:23 +00:00
|
|
|
* Default: Cloudflare
|
2020-02-13 14:50:17 +00:00
|
|
|
*/
|
|
|
|
base?: string;
|
|
|
|
/**
|
|
|
|
* Default: .png
|
|
|
|
*/
|
|
|
|
ext?: string;
|
|
|
|
/**
|
|
|
|
* Default: emoji
|
|
|
|
*/
|
|
|
|
className?: string;
|
|
|
|
/**
|
|
|
|
* Default: 72x72
|
|
|
|
*/
|
|
|
|
size?: string | number;
|
|
|
|
/**
|
|
|
|
* To render with SVG use `folder: svg, ext: .svg`
|
|
|
|
*/
|
|
|
|
folder?: string;
|
|
|
|
/**
|
|
|
|
* The function to invoke in order to generate image src(s).
|
|
|
|
*/
|
2022-03-29 08:54:35 +00:00
|
|
|
callback?: ParseCallback
|
2020-02-13 14:50:17 +00:00
|
|
|
/**
|
2022-03-29 08:54:35 +00:00
|
|
|
* The function to invoke in order to generate additional, custom attributes for the image tag.
|
2020-02-13 14:50:17 +00:00
|
|
|
* Default () => ({})
|
2022-03-29 08:54:35 +00:00
|
|
|
* @param icon the lower case HEX code point i.e. "1f4a9"
|
|
|
|
* @param variant variant the optional \uFE0F ("as image") variant, in case this info is anyhow meaningful. By default this is ignored.
|
|
|
|
*
|
2020-02-13 14:50:17 +00:00
|
|
|
*/
|
2022-03-29 08:54:35 +00:00
|
|
|
attributes?(icon: string, variant: string): object;
|
2020-02-13 14:50:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 06:56:42 +00:00
|
|
|
export type Twemoji = {
|
2022-04-29 22:29:16 +00:00
|
|
|
base: string;
|
|
|
|
ext: string;
|
|
|
|
className: string;
|
|
|
|
size: string;
|
2020-02-13 14:50:17 +00:00
|
|
|
convert: {
|
2022-03-29 08:54:35 +00:00
|
|
|
/**
|
|
|
|
* Given an HEX codepoint, returns UTF16 surrogate pairs.
|
|
|
|
*
|
|
|
|
* @param codepoint string generic codepoint, i.e. '1F4A9'
|
|
|
|
* @return string codepoint transformed into utf16 surrogates pair,
|
|
|
|
* i.e. \uD83D\uDCA9
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* twemoji.convert.fromCodePoint('1f1e8');
|
|
|
|
* // "\ud83c\udde8"
|
|
|
|
*
|
|
|
|
* '1f1e8-1f1f3'.split('-').map(twemoji.convert.fromCodePoint).join('')
|
|
|
|
* // "\ud83c\udde8\ud83c\uddf3"
|
|
|
|
*/
|
2020-02-13 14:50:17 +00:00
|
|
|
fromCodePoint(hexCodePoint: string): string;
|
2022-03-29 08:54:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given UTF16 surrogate pairs, returns the equivalent HEX codepoint.
|
|
|
|
*
|
|
|
|
* @param utf16surrogatePairs string generic utf16 surrogates pair, i.e. \uD83D\uDCA9
|
|
|
|
* @param sep string optional separator for double code points, default='-'
|
|
|
|
* @return string utf16 transformed into codepoint, i.e. '1F4A9'
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3');
|
|
|
|
* // "1f1e8-1f1f3"
|
|
|
|
*
|
|
|
|
* twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~');
|
|
|
|
* // "1f1e8~1f1f3"
|
|
|
|
*/
|
|
|
|
toCodePoint(utf16surrogatePairs: string, sep?: string): string;
|
2020-02-13 14:50:17 +00:00
|
|
|
};
|
2022-03-29 08:54:35 +00:00
|
|
|
parse<T extends string | HTMLElement>(node: T, options?: TwemojiOptions | ParseCallback): T;
|
2022-04-30 06:40:40 +00:00
|
|
|
replace(text: string, replacer: string | ReplacerFunction): string;
|
2022-04-29 22:29:16 +00:00
|
|
|
test(text: string): boolean;
|
|
|
|
onerror(): void;
|
2020-02-13 14:50:17 +00:00
|
|
|
};
|
|
|
|
|
2022-03-14 15:01:32 +00:00
|
|
|
declare module 'twemoji' {
|
|
|
|
const twemoji: Twemoji;
|
2022-03-14 14:48:25 +00:00
|
|
|
export default twemoji;
|
2022-03-14 15:01:32 +00:00
|
|
|
}
|