-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(3.6.2): 修复 surname 模式和 customPinyin 同时使用的问题
fix(3.6.2): 修复 surname 模式和 customPinyin 同时使用的问题
- Loading branch information
Showing
11 changed files
with
177 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
import _DICT1 from '../data/dict1'; | ||
import _DICT2 from '../data/dict2'; | ||
import _DICT3 from '../data/dict3'; | ||
import _DICT4 from '../data/dict4'; | ||
import _DICT5 from '../data/dict5'; | ||
const _dictArr = [{}, {}, _DICT2, _DICT3, _DICT4, _DICT5]; | ||
let customDict: { [key: string]: string } = {}; | ||
|
||
/** | ||
* @description: 用户自定义拼音 | ||
* @param {{ [key: string]: string }} config 用户自定义的拼音映射(支持汉字、词语、句子的映射),若匹配到该映射,优先将汉字转换为该映射 | ||
*/ | ||
export function customPinyin(config: { [key: string]: string } = {}) { | ||
for (let key in config) { | ||
let pinyin = config[key]; | ||
if (key.length === 1) { | ||
const wordCode = key.charCodeAt(0); | ||
_DICT1[wordCode] = pinyin; | ||
} else if (key.length === 2) { | ||
_dictArr[2][key] = pinyin; | ||
} else if (key.length === 3) { | ||
_dictArr[3][key] = pinyin; | ||
} else if (key.length === 4) { | ||
_dictArr[4][key] = pinyin; | ||
} else { | ||
_dictArr[5][key] = pinyin; | ||
customDict = {}; | ||
const keys = Object.keys(config).sort( | ||
(key1, key2) => key2.length - key1.length | ||
); | ||
keys.forEach((key) => { | ||
customDict[key] = config[key]; | ||
}); | ||
} | ||
|
||
export const getCustomDict = () => { | ||
return customDict; | ||
}; | ||
|
||
export function hasCustomConfig() { | ||
for (let key in customDict) { | ||
if (key) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
export const DICT1 = _DICT1; | ||
export const dictArr = _dictArr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters