1
1
import type { EmojiGroup , EmojiMetadata } from "@mojis/internal-utils" ;
2
- import { extractEmojiVersion , extractUnicodeVersion } from "@mojis/internal-utils" ;
3
- import { defineAdapterHandler } from "../../ define" ;
2
+ import { extractEmojiVersion , extractUnicodeVersion , isBefore } from "@mojis/internal-utils" ;
3
+ import { defineAdapterHandler } from "../define" ;
4
4
5
5
function slugify ( val : string ) : string {
6
6
return val . normalize ( "NFD" )
@@ -14,19 +14,19 @@ function slugify(val: string): string {
14
14
}
15
15
16
16
// These emoji versions doesn't seem to have a emoji-test,
17
- // where we can extract the metadata from.
17
+ // which we need to extract the groups and such from.
18
+ // We will probably just have to "generate" them from a html page.
18
19
const DISALLOWED_EMOJI_VERSIONS = [ "1.0" , "2.0" , "3.0" ] ;
19
20
20
- export const modernMetadataHandler = defineAdapterHandler ( {
21
+ export const baseMetadataHandler = defineAdapterHandler ( {
21
22
type : "metadata" ,
22
23
shouldExecute : ( ctx ) => {
24
+ // Since we can't get the metadata for these versions,
25
+ // we will just skip them.
26
+ // We have a fallback handler for these versions (notSupportedMetadataHandler) find it below.
23
27
return ! DISALLOWED_EMOJI_VERSIONS . includes ( ctx . emoji_version ) ;
24
28
} ,
25
29
urls : ( ctx ) => {
26
- if ( DISALLOWED_EMOJI_VERSIONS . includes ( ctx . emoji_version ) ) {
27
- return undefined ;
28
- }
29
-
30
30
return {
31
31
url : `https://unicode.org/Public/emoji/${ ctx . emoji_version } /emoji-test.txt` ,
32
32
cacheKey : `v${ ctx . emoji_version } /metadata` ,
@@ -91,8 +91,18 @@ export const modernMetadataHandler = defineAdapterHandler({
91
91
const hexcode = baseHexcode . trim ( ) . replace ( / \s + / g, "-" ) ;
92
92
const qualifier = baseQualifier . trim ( ) ;
93
93
94
- const emojiVersion = extractEmojiVersion ( comment . trim ( ) ) ;
95
- const [ emoji , trimmedComment ] = comment . trim ( ) . split ( ` E${ emojiVersion } ` ) ;
94
+ // if the emoji_version is v5 and under.
95
+ // the content after the # doesn't include the emoji version.
96
+ let emoji ;
97
+ let trimmedComment ;
98
+
99
+ const extractedEmojiVersion = extractEmojiVersion ( comment . trim ( ) ) ;
100
+
101
+ if ( isBefore ( ctx . emoji_version , "6.0.0" ) ) {
102
+ [ emoji , trimmedComment ] = comment . trim ( ) . split ( " " ) ;
103
+ } else {
104
+ [ emoji , trimmedComment ] = comment . trim ( ) . split ( ` E${ extractedEmojiVersion } ` ) ;
105
+ }
96
106
97
107
const groupName = currentGroup ?. slug ?? "unknown" ;
98
108
const subgroupName = currentGroup ?. subgroups [ currentGroup . subgroups . length - 1 ] ?? "unknown" ;
@@ -107,8 +117,8 @@ export const modernMetadataHandler = defineAdapterHandler({
107
117
group : groupName ,
108
118
subgroup : subgroupName ,
109
119
qualifier,
110
- emojiVersion : emojiVersion || null ,
111
- unicodeVersion : extractUnicodeVersion ( emojiVersion , ctx . unicode_version ) ,
120
+ emojiVersion : extractedEmojiVersion || null ,
121
+ unicodeVersion : extractUnicodeVersion ( extractedEmojiVersion , ctx . unicode_version ) ,
112
122
description : trimmedComment || "" ,
113
123
emoji : emoji || null ,
114
124
hexcodes : hexcode . split ( "-" ) ,
@@ -124,3 +134,25 @@ export const modernMetadataHandler = defineAdapterHandler({
124
134
return transformed ;
125
135
} ,
126
136
} ) ;
137
+
138
+ // Handles the versions that doesn't seem to have an emoji-test file.
139
+ // We will just return an empty object for these versions.
140
+ export const notSupportedMetadataHandler = defineAdapterHandler ( {
141
+ type : "metadata" ,
142
+ shouldExecute : ( ctx ) => {
143
+ return DISALLOWED_EMOJI_VERSIONS . includes ( ctx . emoji_version ) ;
144
+ } ,
145
+ urls : ( ) => {
146
+ return undefined ;
147
+ } ,
148
+ parser : "generic" ,
149
+ transform ( ) {
150
+ return undefined ;
151
+ } ,
152
+ output ( ) {
153
+ return {
154
+ groups : [ ] ,
155
+ emojis : { } ,
156
+ } ;
157
+ } ,
158
+ } ) ;
0 commit comments