Skip to content

Commit 458acdc

Browse files
authored
Merge pull request #179 from zh-lx/feat-number-dict
feat: 数字词库增加"几"
2 parents 8d0e732 + 063dd36 commit 458acdc

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/common/constant.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const DoubleUnicodePrefixReg = /^[\uD800-\uDBFF]$/;
22
export const DoubleUnicodeSuffixReg = /^[\uDC00-\uDFFF]$/;
3+
export const DoubleUnicodeReg = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
34
export enum Priority {
45
DictNumber = 15,
56
DICT2 = 20,

lib/common/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
var regex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
1+
import { DoubleUnicodePrefixReg, DoubleUnicodeSuffixReg, DoubleUnicodeReg } from './constant';
22

33
export function getStringLength(string: string) {
4-
return string.replace(regex, '_').length;
4+
return string.replace(DoubleUnicodeReg, '_').length;
55
}
66

77
// 针对双音节中文特殊划分
88
export function getSplittedWord(string: string) {
99
const arr = [];
1010
for (let i = 0; i < string.length; i++) {
1111
if (
12-
/[\uD800-\uDBFF]/.test(string[i]) &&
12+
DoubleUnicodePrefixReg.test(string[i]) &&
1313
i + 1 < string.length &&
14-
/[\uDC00-\uDFFF]/.test(string[i + 1])
14+
DoubleUnicodeSuffixReg.test(string[i + 1])
1515
) {
1616
arr.push(string[i] + string[i + 1]);
1717
i++;

lib/data/dict-number.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Numbers = {
2121
: 'duō',
2222
十一: 'shí yī',
2323
零一: 'líng yī',
24+
: 'jǐ',
2425
};
2526

2627
const NumberWordMap = {

0 commit comments

Comments
 (0)