UNPKG

regexp-cjk

Version:

Generate JavaScript-compatible regular expressions with chinese/jp/zh/cn

53 lines 1.7 kB
"use strict"; /** * Created by user on 2018/5/5/005. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.zhTableAutoGreedyTable = zhTableAutoGreedyTable; exports._word_zh_core = _word_zh_core; exports._word_zh_core2 = _word_zh_core2; const zh_table_list_1 = require("@lazy-cjk/zh-table-list"); const util_1 = require("./util"); //console.log(cjkConv.zhTable.auto('魯')); function zhTableAutoGreedyTable(s, options = {}) { if (true || options.greedyTable > 1) { options.safe = false; } options.greedyTable = options.greedyTable || true; return (0, zh_table_list_1.auto)(s, options); } function _word_zh_core(search, skip, zhTableFn = zh_table_list_1.auto, options = {}) { let opts; if (options.unsafe || true) { opts = { // @ts-ignore greedyTable: options.greedyTable, safe: false, }; } return search.replace((0, util_1._re_cjk_conv)('ug'), function (char) { if (skip && skip.indexOf(char) != -1) { return char; } let a = zhTableFn(char, opts); return a.length > 1 ? '[' + a.join('') + ']' : a[0]; }); } function _word_zh_core2(search, skip, zhTableFn = zh_table_list_1.auto, options = {}) { let opts; if (options.unsafe || true) { opts = { // @ts-ignore greedyTable: options.greedyTable, safe: false, }; } return search.replace((0, util_1._re_cjk_conv)('ug'), function (char) { if (skip && skip.indexOf(char) != -1) { return char; } let a = zhTableFn(char, opts); return a.join(''); }); } //# sourceMappingURL=conv.js.map