Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docusaurus-theme-common): classify Chinese tag into alphabet #7843

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"*.xyz",
"*.docx",
"versioned_docs",
"*.min.*"
"*.min.*",
"packages/docusaurus-theme-common/src/utils/pinyin/src/genMap/dict.ts",
"packages/docusaurus-theme-common/src/utils/pinyin/data/pinyin.json"
],
"ignoreRegExpList": ["Email", "Urls", "#[\\w-]*"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {ChineseWord2Pinyin} from '../pinyin/src/index';

describe('getFirstLetterFromChinese', () => {
it('included chinese --> a lower-cased alphabet', () => {
expect(ChineseWord2Pinyin('你')).toEqual(['ni']);
expect(ChineseWord2Pinyin('我们')).toEqual(['wo', 'men']);
});

it('excluded chinese --> unchanged', () => {
// todo: support 繁體字
expect(ChineseWord2Pinyin('妳')).toEqual(['妳']);
// 生僻字应该不需要支持(就提取标签来说)
expect(ChineseWord2Pinyin('犇')).toEqual(['犇']);
});

it('non-chinese --> unchanged (but separated)', () => {
// english
expect(ChineseWord2Pinyin('hello')).toEqual(['h', 'e', 'l', 'l', 'o']);
});

it('mixture --> mixture and separated', () => {
expect(ChineseWord2Pinyin('facebook好棒')).toEqual([
'f',
'a',
'c',
'e',
'b',
'o',
'o',
'k',
'hao',
'bang',
]);
});
});
Loading