UNPKG

1.3 kBJavaScriptView Raw
1"use strict";
2/**
3 * Created by user on 2018/4/19/019.
4 */
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.TableDictSynonymPanGu = void 0;
7const core_1 = require("./core");
8/**
9 * 原版 node-segment 的格式
10 */
11class TableDictSynonymPanGu extends core_1.default {
12 constructor(type = TableDictSynonymPanGu.type, options = {}, ...argv) {
13 super(type, options, ...argv);
14 }
15 add(data, skipExists) {
16 if (!Array.isArray(data) || data.length != 2) {
17 throw new TypeError(JSON.stringify(data));
18 }
19 data[0] = this._trim(data[0]);
20 data[1] = this._trim(data[1]);
21 if (!data[0]) {
22 throw new TypeError(JSON.stringify(data));
23 }
24 if (skipExists && this.exists(data[0])) {
25 return this;
26 }
27 this._add(data[0], data[1]);
28 return this;
29 }
30 _add(n1, n2) {
31 if (n1 !== n2) {
32 this.TABLE[n1] = n2;
33 }
34 if (this.TABLE[n2] === n1) {
35 delete this.TABLE[n2];
36 }
37 }
38 _trim(s) {
39 return s.replace(/^\s+|\s+$/g, '').trim();
40 }
41}
42exports.TableDictSynonymPanGu = TableDictSynonymPanGu;
43TableDictSynonymPanGu.type = 'SYNONYM';
44exports.default = TableDictSynonymPanGu;
45//# sourceMappingURL=synonym.pangu.js.map
\No newline at end of file