Skip to content

Commit

Permalink
feat: 姓氏模式优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Feb 25, 2022
1 parent 0c022b4 commit cf14937
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
28 changes: 15 additions & 13 deletions lib/pinyin.js
Expand Up @@ -71,26 +71,28 @@ class Pinyin {

if (options.mode === PINYIN_MODE.SURNAME) {
pys.push(this.surname_pinyin(hans, options));
}
} else {

for(let i = 0, firstCharCode, words, l = hans.length; i < l; i++) {
for(let i = 0, firstCharCode, words, l = hans.length; i < l; i++) {

words = hans[i];
firstCharCode = words.charCodeAt(0);
words = hans[i];
firstCharCode = words.charCodeAt(0);

if(this._dict[firstCharCode]) {
if(this._dict[firstCharCode]) {

// ends of non-chinese words.
if(nohans.length > 0) {
pys.push([nohans]);
nohans = ""; // reset non-chinese words.
}
// ends of non-chinese words.
if(nohans.length > 0) {
pys.push([nohans]);
nohans = ""; // reset non-chinese words.
}

pys.push(this.single_pinyin(words, options));
pys.push(this.single_pinyin(words, options));

} else {
nohans += words;
} else {
nohans += words;
}
}

}

// 清理最后的非中文字符串。
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -42,7 +42,6 @@
"test": "nyc --reporter=lcov mocha --timeout=5000 --inline-diffs ./tests/"
},
"dependencies": {
"@node-rs/jieba": "^1.6.0",
"commander": "~1.1.1",
"object-assign": "^4.0.1"
},
Expand Down

0 comments on commit cf14937

Please sign in to comment.