| 1 |
type OpenCCDict = OpenCCFileDict | OpenCCInlineDict | OpenCCGroupDict; |
| 2 |
type OpenCCSegmentation = OpenCCMmsegSegmentation | OpenCCPluginSegmentation; |
| 3 |
type OpenCCPluginSegmentation = { |
| 4 |
type: string; |
| 5 |
resources?: Record<string, string>; |
| 6 |
[key: string]: string | Record<string, string> | undefined; |
| 7 |
}; |
| 8 |
|
| 9 |
interface OpenCCConfig { |
| 10 |
name: string; |
| 11 |
normalization?: [OpenCCConversion, ...OpenCCConversion[]]; |
| 12 |
segmentation?: OpenCCSegmentation; |
| 13 |
conversion_chain: [OpenCCConversion, ...OpenCCConversion[]]; |
| 14 |
} |
| 15 |
interface OpenCCConversion { |
| 16 |
dict: OpenCCDict; |
| 17 |
} |
| 18 |
interface OpenCCFileDict { |
| 19 |
type: "text" | "ocd" | "ocd2"; |
| 20 |
file: string; |
| 21 |
may_output_tofu?: boolean; |
| 22 |
} |
| 23 |
interface OpenCCInlineDict { |
| 24 |
type: "inline"; |
| 25 |
entries: { |
| 26 |
[k: string]: string; |
| 27 |
}; |
| 28 |
} |
| 29 |
interface OpenCCGroupDict { |
| 30 |
type: "group"; |
| 31 |
match_policy: "short_circuit" | "union"; |
| 32 |
dicts: [OpenCCDict, ...OpenCCDict[]]; |
| 33 |
may_output_tofu?: boolean; |
| 34 |
} |
| 35 |
interface OpenCCMmsegSegmentation { |
| 36 |
type: "mmseg"; |
| 37 |
dict: OpenCCDict; |
| 38 |
} |
| 39 |
|
| 40 |
interface OpenCCOptions { |
| 41 |
includeTofuRiskDictionaries?: boolean; |
| 42 |
configDirectory?: string; |
| 43 |
resourceZip?: string; |
| 44 |
} |
| 45 |
|
| 46 |
declare class OpenCC { |
| 47 |
constructor(config?: string | OpenCCConfig, options?: OpenCCOptions); |
| 48 |
static readonly version: string; |
| 49 |
static fromConfig(config: OpenCCConfig, options?: OpenCCOptions): OpenCC; |
| 50 |
static generateDict(inputFileName: string, outputFileName: string, formatFrom: string, formatTo: string): void; |
| 51 |
convert(input: string, callback: (err: string | undefined, convertedText: string) => void): void; |
| 52 |
convertSync(input: string): string; |
| 53 |
convertPromise(input: string): Promise<string>; |
| 54 |
} |
| 55 |
|
| 56 |
declare namespace OpenCC { |
| 57 |
export { OpenCC, OpenCCConfig, OpenCCOptions }; |
| 58 |
} |
| 59 |
|
| 60 |
export = OpenCC; |