-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
10 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports = { | ||
presets: [ | ||
[ '@babel/preset-env', {targets: {node: 'current'}} ], | ||
[ '@babel/preset-typescript', {allExtensions: true}], | ||
[ "@babel/preset-env", {targets: {node: "current"}} ], | ||
[ "@babel/preset-typescript", {allExtensions: true}], | ||
], | ||
'compact': true, | ||
"compact": true, | ||
}; |
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,7 +1,7 @@ | ||
import nodejieba from "nodejieba"; | ||
import { load, cut /*, tag */ } from "@node-rs/jieba"; | ||
// import nodejieba from "nodejieba"; | ||
// import { load, cut /*, tag */ } from "@node-rs/jieba"; | ||
// @ts-ignore | ||
Check warning on line 3 in src/segment.ts GitHub Actions / build (16.x)
Check warning on line 3 in src/segment.ts GitHub Actions / build (20.x)
|
||
import { Segment, useDefault } from "segmentit"; | ||
// import { Segment, useDefault } from "segmentit"; | ||
import type { IPinyinSegment } from "./declare"; | ||
|
||
let nodeRsJiebaLoaded = false; // @node-rs/jieba 加载词典。 | ||
|
@@ -15,6 +15,7 @@ let hansIntlSegmenter: any; // Intl.Segmenter | |
export function segment(hans: string, segment?: IPinyinSegment): string[] { | ||
// @node-rs/jieba (Rust) | ||
if (segment === "@node-rs/jieba") { | ||
const { load, cut /*, tag */ } = require("@node-rs/jieba"); | ||
Check failure on line 18 in src/segment.ts GitHub Actions / build (16.x)
|
||
if (!nodeRsJiebaLoaded) { | ||
nodeRsJiebaLoaded = true; | ||
load(); | ||
|
@@ -25,6 +26,7 @@ export function segment(hans: string, segment?: IPinyinSegment): string[] { | |
|
||
// segmentit (Node.js) | ||
if (segment === "segmentit") { | ||
const { Segment, useDefault } = require("segmentit"); | ||
Check failure on line 29 in src/segment.ts GitHub Actions / build (16.x)
|
||
if (!segmentit) { | ||
segmentit = useDefault(new Segment()); | ||
} | ||
|
@@ -45,9 +47,9 @@ export function segment(hans: string, segment?: IPinyinSegment): string[] { | |
} | ||
} | ||
|
||
const nodejieba = require("nodejieba"); | ||
Check failure on line 50 in src/segment.ts GitHub Actions / build (16.x)
|
||
// 默认使用 nodejieba (C++) | ||
// return nodejieba.tag(hans); | ||
// nodejieba 定义的类型返回值错误,先忽略。 | ||
// @ts-ignore | ||
return nodejieba.cutSmall(hans, 4); | ||
return nodejieba.cutSmall(hans, 4) as unknown as string[]; | ||
} |