1
+ /**
2
+ * If given to parse, this callback will be invoked per each found emoji.
3
+ *
4
+ * 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.
5
+ *
6
+ * @param icon the lower case HEX code point i.e. "1f4a9"
7
+ * @param options all info for this parsing operation
8
+ * @param variant the optional \uFE0F ("as image") variant, in case this info is anyhow meaningful. By default this is ignored.
9
+ */
10
+ declare type ParseCallback = ( icon : string , options : object , variant : string ) => string | false ;
11
+
1
12
declare interface TwemojiOptions {
2
13
/**
3
14
* Default: MaxCDN
@@ -22,19 +33,52 @@ declare interface TwemojiOptions {
22
33
/**
23
34
* The function to invoke in order to generate image src(s).
24
35
*/
25
- callback ?( icon : string , options : TwemojiOptions ) : void ;
36
+ callback ?: ParseCallback
26
37
/**
38
+ * The function to invoke in order to generate additional, custom attributes for the image tag.
27
39
* Default () => ({})
40
+ * @param icon the lower case HEX code point i.e. "1f4a9"
41
+ * @param variant variant the optional \uFE0F ("as image") variant, in case this info is anyhow meaningful. By default this is ignored.
42
+ *
28
43
*/
29
- attributes ?( ) : void ;
44
+ attributes ?( icon : string , variant : string ) : object ;
30
45
}
31
46
32
47
declare type Twemoji = {
33
48
convert : {
49
+ /**
50
+ * Given an HEX codepoint, returns UTF16 surrogate pairs.
51
+ *
52
+ * @param codepoint string generic codepoint, i.e. '1F4A9'
53
+ * @return string codepoint transformed into utf16 surrogates pair,
54
+ * i.e. \uD83D\uDCA9
55
+ *
56
+ * @example
57
+ * twemoji.convert.fromCodePoint('1f1e8');
58
+ * // "\ud83c\udde8"
59
+ *
60
+ * '1f1e8-1f1f3'.split('-').map(twemoji.convert.fromCodePoint).join('')
61
+ * // "\ud83c\udde8\ud83c\uddf3"
62
+ */
34
63
fromCodePoint ( hexCodePoint : string ) : string ;
35
- toCodePoint ( utf16surrogatePairs : string ) : string ;
64
+
65
+ /**
66
+ * Given UTF16 surrogate pairs, returns the equivalent HEX codepoint.
67
+ *
68
+ * @param utf16surrogatePairs string generic utf16 surrogates pair, i.e. \uD83D\uDCA9
69
+ * @param sep string optional separator for double code points, default='-'
70
+ * @return string utf16 transformed into codepoint, i.e. '1F4A9'
71
+ *
72
+ * @example
73
+ * twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3');
74
+ * // "1f1e8-1f1f3"
75
+ *
76
+ * twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~');
77
+ * // "1f1e8~1f1f3"
78
+ */
79
+ toCodePoint ( utf16surrogatePairs : string , sep ?: string ) : string ;
36
80
} ;
37
- parse ( node : HTMLElement | string , options ?: TwemojiOptions ) : void ;
81
+ parse < T extends string | HTMLElement > ( node : T , options ?: TwemojiOptions | ParseCallback ) : T ;
38
82
} ;
39
83
40
84
declare module 'twemoji' {
0 commit comments