Skip to content

Commit

Permalink
feat: 增加了 Flag 识别字段
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Oct 10, 2019
1 parent 057269d commit 86c1489
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/utils/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Object.keys(flag).forEach(emoji => {

export const prependFlag = (str: string): string => {
for (const key in flagMap) {
if (flagMap.hasOwnProperty(key) && str.includes(key)) {
if (flagMap.hasOwnProperty(key) && str.toUpperCase().includes(key)) {
return `${flagMap[key]} ${str}`;
}
}
Expand Down
17 changes: 10 additions & 7 deletions static/flag_cn.json5
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"圣保罗"
],
"🇨🇦": [
"CAN",
"加拿大",
"蒙特利尔",
"温哥华"
Expand All @@ -34,6 +35,8 @@
"苏黎世"
],
"🇨🇳": [
"TW",
"回国",
"中国",
"江苏",
"北京",
Expand All @@ -60,19 +63,18 @@
"赫尔辛基"
],
"🇫🇷": [
"FR",
"法国",
"巴黎"
],
"🇬🇧": [
"UK",
"英国",
"伦敦"
],
"🇭🇰": [
"HK",
"香港",
"深港",
"沪港",
"呼港"
"港",
],
"🇮🇩": [
"印尼",
Expand All @@ -92,6 +94,7 @@
"米兰"
],
"🇯🇵": [
"JP",
"日本",
"东京",
"大阪",
Expand Down Expand Up @@ -130,6 +133,7 @@
"新西伯利亚"
],
"🇸🇬": [
"SG",
"新加坡",
"狮城"
],
Expand All @@ -143,7 +147,7 @@
],
"🇺🇲": [
"US",
"美国",
"",
"波特兰",
"达拉斯",
"俄勒冈",
Expand All @@ -155,8 +159,7 @@
"圣何塞",
"圣克拉拉",
"西雅图",
"芝加哥",
"沪美"
"芝加哥"
],
"🇻🇳": [
"越南"
Expand Down
2 changes: 2 additions & 0 deletions test/flag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { prependFlag } from '../lib/utils/flag';
test('addFlag', t => {
t.is(prependFlag('美国'), '🇺🇲 美国');
t.is(prependFlag('阿联酋'), '阿联酋');
t.is(prependFlag('US'), '🇺🇲 US');
t.is(prependFlag('us'), '🇺🇲 us');
});

0 comments on commit 86c1489

Please sign in to comment.