diff --git a/package.json b/package.json index cfdb079..9649d78 100644 --- a/package.json +++ b/package.json @@ -354,8 +354,8 @@ "@types/vscode": "^1.12.0", "glob": "^7.1.4", "mocha": "^6.1.4", - "typescript": "^3.3.1", "tslint": "^5.12.1", + "typescript": "^3.3.1", "vscode-test": "^1.0.2" }, "configuration": { @@ -373,5 +373,8 @@ "description": "激活AnyRule的文件类型,多个类型用逗号分隔" } } + }, + "dependencies": { + "transliteration": "^2.1.8" } -} \ No newline at end of file +} diff --git a/packages/www/src/RULES.js b/packages/www/src/RULES.js index 14caf88..c31f78b 100644 --- a/packages/www/src/RULES.js +++ b/packages/www/src/RULES.js @@ -59,7 +59,7 @@ module.exports = [{ examples: ['/usr/ad/dd/a.js', '/root/b.ts'] }, { - title: 'window下"文件夹"路径', + title: 'window"文件夹"路径', rule: /^[a-zA-Z]:\\(?:\w+\\?)*$/, examples: ['C:\\Users\\Administrator\\Desktop', 'e:\\m\\'] }, @@ -69,7 +69,7 @@ module.exports = [{ examples: ['C:\\Users\\Administrator\\Desktop\\qq.link', 'e:\\m\\vscode.exe'] }, { - title: 'A股代码', + title: '股票代码(A股)', rule: /^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$/, examples: ['sz000858', 'SZ002136', 'sz300675', 'SH600600', 'sh601155'] }, @@ -145,12 +145,12 @@ module.exports = [{ examples: ['James', 'Kevin Wayne Durant', 'Dirk Nowitzki'] }, { - title: '新能源车牌号', + title: '车牌号(新能源)', rule: /[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$/, examples: ['京AD92035', '甘G23459F'], }, { - title: '非新能源车牌号', + title: '车牌号(非新能源)', rule: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/, examples: ['京A00599', '黑D23908'] }, @@ -160,17 +160,17 @@ module.exports = [{ examples: ['京A12345D', '京A00599'] }, { - title: '中国手机号(严谨), 根据工信部2019年最新公布的手机号段', + title: '手机号中国(严谨), 根据工信部2019年最新公布的手机号段', rule: /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/, examples: ['008618311006933', '+8617888829981', '19119255642'] }, { - title: '中国手机号(宽松), 只要是13,14,15,16,17,18,19开头即可', + title: '手机号中国(宽松), 只要是13,14,15,16,17,18,19开头即可', rule: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/, examples: ['008618311006933', '+8617888829981', '19119255642'] }, { - title: '中国手机号(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条', + title: '手机号中国(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条', rule: /^(?:(?:\+|00)86)?1\d{10}$/, examples: ['008618311006933', '+8617888829981', '19119255642'] }, @@ -180,22 +180,22 @@ module.exports = [{ examples: ['1990-12-12', '2020-1-1'] }, { - title: '邮箱地址(email)', + title: 'email(邮箱)', rule: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, examples: ['90203918@qq.com', 'nbilly@126.com'] }, { - title: '国内座机电话,如: 0341-86091234', + title: '座机电话(国内),如: 0341-86091234', rule: /\d{3}-\d{8}|\d{4}-\d{7}/, examples: ['0936-4211235'] }, { - title: '一代身份证号(15位数字)', + title: '身份证号(1代,15位数字)', rule: /^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$/, examples: ['622001790131123'] }, { - title: '二代身份证号(18位数字),最后一位是校验位,可能为数字或字符X', + title: '身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符X', rule: /^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}[\dXx]$/, examples: ['62222319991205131x'] }, @@ -215,48 +215,48 @@ module.exports = [{ examples: ['justin', 'justin1989', 'justin_666'] }, { - title: '纯中文/汉字', + title: '中文/汉字', // rule: /^[\u4E00-\u9FA5]+$/, rule: /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/, examples: ['正则', '前端'] }, { - title: '是否小数', + title: '小数', rule: /^\d+\.\d+$/, examples: ['0.0', '0.09'] }, { - title: '纯数字', + title: '数字', rule: /^\d{1,}$/, examples: [12345678] }, { - title: '是否html标签(宽松匹配)', + title: 'html标签(宽松匹配)', rule: /<(\w+)[^>]*>(.*?<\/\1>)?/, examples: ['
2333
', '', '
'] }, { - title: '是否qq号格式正确', + title: 'qq号格式正确', rule: /^[1-9][0-9]{4,10}$/, examples: [903013545, 9020304] }, { - title: '是否由数字和字母组成', + title: '数字和字母组成', rule: /^[A-Za-z0-9]+$/, examples: ['james666', 'haha233hi'] }, { - title: '纯英文字母', + title: '英文字母', rule: /^[a-zA-Z]+$/, examples: ['Russel'] }, { - title: '纯小写英文字母组成', + title: '小写英文字母组成', rule: /^[a-z]+$/, examples: ['russel'] }, { - title: '纯大写英文字母', + title: '大写英文字母', rule: /^[A-Z]+$/, examples: ['ABC', 'KD'] }, @@ -291,12 +291,12 @@ module.exports = [{ examples: ['github666', 'kd_-666'] }, { - title: '中国邮政编码', + title: '邮政编码(中国)', rule: /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, examples: ['734500', '100101'] }, { - title: '只包含中文和数字', + title: '中文和数字', rule: /^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/, examples: ['哈哈哈', '你好6啊'] }, @@ -306,7 +306,7 @@ module.exports = [{ examples: ['你好6啊', '@¥()!'] }, { - title: 'Android 包名校验', + title: 'java包名', rule: /^([a-zA-Z_][a-zA-Z0-9_]*)+([.][a-zA-Z_][a-zA-Z0-9_]*)+$/, examples: ['com.bbb.name'] } diff --git a/rules.json b/rules.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/rules.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/src/anyrule.ts b/src/anyrule.ts deleted file mode 100644 index 55848b2..0000000 --- a/src/anyrule.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { ExtensionContext, CompletionItem, CompletionItemKind, languages, Disposable, workspace, window, commands, TextDocument, Position, Range, Selection } from "vscode"; -import { generateFilterString, getRulesByText } from "./utils"; -import { IRule } from "./interface"; -import { loadRules } from './loader'; -import { RegexDiagram } from './diagram/panel'; - -export class AnyRule { - context: ExtensionContext; - disposable: Disposable | null = null; - rules: IRule[] | null = null; - regexDiagram: RegexDiagram | null = null; - constructor(context: ExtensionContext) { - this.context = context; - this.regexDiagram = new RegexDiagram(context); - loadRules(context.extensionPath).then(rules => { - this.rules = rules; - this.load(); - this.oldFunctionCompatible(); - }); - } - public load() { - let currentRules: IRule[] = []; - const configuration = workspace.getConfiguration(); - let START_IDENTIFIER: string = configuration.get('anyRule.triggerString') || 'zz'; - const setting: string = configuration.get('anyRule.supportedLanguages') || 'javascript,typescirpt' as string; - const supportedLanguages = setting.split(','); - this.commandRegisters(START_IDENTIFIER); - this.disposable = languages.registerCompletionItemProvider(supportedLanguages, { - provideCompletionItems: (document, position, token, context) => { - const line = document.lineAt(position); - const lineText = line.text.substring(0, position.character); - if (new RegExp(`${START_IDENTIFIER}\.`, 'g').test(lineText)) { - currentRules = getRulesByText(START_IDENTIFIER, this.rules || [], lineText); - return currentRules.map(rule => { - const item = new CompletionItem(rule.title, rule.regex ? CompletionItemKind.Field : CompletionItemKind.Folder); - // @ts-ignore - item.rule = rule; - // item.commitCharacters = ['.']; - item.filterText = generateFilterString(rule); - item.documentation = rule.regex ? `${rule.title}\n${rule.examples ? '\n示例:\n' + rule.examples.join('\n') : ''}` : undefined; - item.command = { - title: '插入正则', - command: 'functions.insertRegex', - arguments: [document, position, rule] - }; - return item; - }); - } - }, - resolveCompletionItem: (item: CompletionItem) => { - // @ts-ignore - const rule: IRule = item.rule; - if (rule.regex) { - return null; - } else { - item.insertText = item.label + '.'; - return item; - } - }, - }, '.'); - - this.context.subscriptions.push(this.disposable); - // window.showInformationMessage('AnyRule加载成功'); - } - - public reload() { - if (this.disposable) { - this.disposable.dispose(); - } - - this.load(); - } - - public update() { - loadRules(this.context.extensionPath, true).then(rules => { - this.rules = rules; - this.reload(); - window.showInformationMessage('正则库已更新'); - }); - } - - private commandRegisters(START_IDENTIFIER: string) { - commands.getCommands().then((commandList) => { - if (commandList.indexOf('functions.insertRegex') !== -1) { - return; - } - commands.registerCommand('functions.insertRegex', (document: TextDocument, position: Position, rule: IRule) => { - if (rule.regex) { - const editor = window.activeTextEditor; - editor?.edit(editBuilder => { - const line = document.lineAt(position); - const start = line.text.indexOf(START_IDENTIFIER); - if (start === -1) { - return; - } - - if (rule.regex) { - editBuilder.replace( - new Range(new Position(line.lineNumber, start), - new Position(line.lineNumber, line.text.length)), - String(rule.regex) - ); - // TODO 处理输入文本后选中字符串的问题 - setTimeout(() => { - const end = new Position(line.lineNumber, line.text.length + String(rule.regex).length); - editor.selection = new Selection(end, end); - }, 0); - } - }); - } else { - commands.executeCommand('editor.action.triggerSuggest'); - } - }); - }); - } - - /** - * 兼容旧的功能,大概率会在未来废弃,仅过度使用 - */ - private oldFunctionCompatible() { - this.rules?.forEach((rule, index) => { - commands.registerCommand(`extension.rule${index}`, () => { - const editor = window.activeTextEditor; - if (editor) { - const { selections } = editor; - - editor.edit(editBuilder => { - selections.forEach(selection => { - const { start, end } = selection; - const range = new Range(start, end); - editBuilder.replace(range, String(rule.regex)); - }); - }); - // Display a message box to the user - window.showInformationMessage(`已插入正则: ${rule.title}`); - } else { - window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!'); - } - }); - }); - } -} \ No newline at end of file diff --git a/src/constant.ts b/src/constant.ts index e69de29..9ea1fae 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -0,0 +1 @@ +export const COMPLETION_TRIGGER_ID = 'zz.'; \ No newline at end of file diff --git a/src/diagram/index.html b/src/diagram/index.html deleted file mode 100644 index d7989f7..0000000 --- a/src/diagram/index.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - 图解Regex - - - - - 图解Regex -
-
- -
star
-
-
-
- - - - - diff --git a/src/diagram/panel.ts b/src/diagram/panel.ts deleted file mode 100644 index 2911eb2..0000000 --- a/src/diagram/panel.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { WebviewPanel, window, ViewColumn, Uri, workspace, ExtensionContext } from "vscode"; -import { join } from 'path'; -import { readFileSync } from "fs"; - -export class RegexDiagram { - regex: string | null = null; - panel: WebviewPanel | null = null; - constructor(context: ExtensionContext) { - this.panel = window.createWebviewPanel('regexDiagram', '图解正则表达式', ViewColumn.Two, { - enableScripts: true, - retainContextWhenHidden: false, - }); - console.log(join(context.extensionPath, 'src/diagram', './index.html')); - this.panel.webview.html = readFileSync(join(context.extensionPath, 'src/diagram', './index.html')).toString(); - this.panel.webview.postMessage({ - regex: this.regex || '/aaaaab{1,3}/', - }); - } -} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index b87172d..9ee8765 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,61 +1,16 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import { - window, workspace, commands, - ExtensionContext, ConfigurationChangeEvent + ExtensionContext } from 'vscode'; -import { IRule } from './interface'; -import { AnyRule } from './anyrule'; +const RULES: { title: string, rule: RegExp, examples: string[] }[] = require('../packages/www/src/RULES.js'); +import useCommand from './useCommand'; +import useCompletion from './useCompletion'; + -// this method is called when your extension is activated -// your extension is activated the very first time the command is executed export function activate(context: ExtensionContext) { - - // Use the console to output diagnostic information (console.log) and errors (console.error) - // This line of code will only be executed once when your extension is activated - console.log('Congratulations, your extension "any-rule" is now active!'); - - // The command has been defined in the package.json file - // Now provide the implementation of the command with registerCommand - // The commandId parameter must match the command field in package.json - // let disposable = vscode.commands.registerCommand('extension.helloWorld', () => { - // // The code you place here will be executed every time your command is executed - - - - const anyRule = new AnyRule(context); - - workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => { - anyRule.reload(); - }); - - commands.registerCommand('extension.update', () => { - anyRule.update(); - }); - commands.registerCommand('extension.reload', () => { - anyRule.reload(); - window.showInformationMessage('重新加载插件成功'); - }); - commands.registerCommand('extension.support', () => { - const currentLanguage = window.activeTextEditor?.document.languageId; - if (currentLanguage) { - try { - const configuration = workspace.getConfiguration(); - const setting: string = configuration.get('anyRule.supportedLanguages') || 'javascript,typescirpt' as string; - const supportedLanguages = setting.split(','); - const set = new Set(supportedLanguages); - set.add(currentLanguage); - console.log(Array.from(set).join(',')); - configuration.update('anyRule.supportedLanguages', Array.from(set).join(',')).then(() => { - anyRule.reload(); - }); - window.showInformationMessage('更新关联语言成功'); - } catch(e) { - window.showInformationMessage('更新关联语言失败'); - } - } - }); + useCommand(context, RULES); + useCompletion(context, RULES); } -// this method is called when your extension is deactivated export function deactivate() { } diff --git a/src/interface.d.ts b/src/interface.d.ts index d944270..c9fec08 100644 --- a/src/interface.d.ts +++ b/src/interface.d.ts @@ -4,4 +4,10 @@ export interface IRule { regex?: RegExp | string; rules?: IRule[]; examples?: string[]; +} + +export interface Rule{ + title:string, + rule:RegExp, + examples:string[] } \ No newline at end of file diff --git a/src/loader.ts b/src/loader.ts deleted file mode 100644 index 92713f5..0000000 --- a/src/loader.ts +++ /dev/null @@ -1,45 +0,0 @@ -import axios from 'axios'; -import { IRule } from './interface'; -import { writeFileSync, readFileSync } from 'fs'; -import { join as pathJoin } from 'path'; - -async function loadRulesFromFile(path: string): Promise { - try { - const json = readFileSync(path); - return JSON.parse(json.toString()) as IRule[]; - } catch(e) { - return null; - } -} - -async function loadRulesFromWeb(): Promise { - const dataSources = [ - 'https://raw.githubusercontent.com/any86/any-rule/feature/vscode-refactor/rules.json' - ]; - let rules: IRule[] = []; - for (const source of dataSources) { - try { - const response = await axios.get(source); - const body = response.data; - rules = body as IRule[]; - } catch(e) { - console.log(e); - continue; - } - } - - return rules; -} - -export async function loadRules (extensionPath: string, force: boolean = false): Promise { - const rulePath = pathJoin(extensionPath, 'rules.json'); - let rules: IRule[] | null = null; - if (!force) { - rules = await loadRulesFromFile(rulePath); - } - if (!rules) { - rules = await loadRulesFromWeb(); - writeFileSync(rulePath, Buffer.from(JSON.stringify(rules))); - } - return rules; -} diff --git a/src/useCommand.ts b/src/useCommand.ts new file mode 100644 index 0000000..6106347 --- /dev/null +++ b/src/useCommand.ts @@ -0,0 +1,24 @@ +import * as vscode from "vscode"; +import { Rule } from './interface'; +export default function (context: vscode.ExtensionContext, RULES: Rule[]) { + RULES.forEach(({ title, rule }, index) => { + let disposable = vscode.commands.registerCommand(`extension.rule${index}`, () => { + const editor = vscode.window.activeTextEditor; + if (editor) { + const { selections } = editor; + + editor.edit(editBuilder => { + selections.forEach(selection => { + const { start, end } = selection; + const range = new vscode.Range(start, end); + editBuilder.replace(range, String(rule)); + }); + }); + vscode.window.showInformationMessage(`已插入正则: ${title}`); + } else { + vscode.window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!'); + } + }); + context.subscriptions.push(disposable); + }); +} \ No newline at end of file diff --git a/src/useCompletion.ts b/src/useCompletion.ts new file mode 100644 index 0000000..38bce2a --- /dev/null +++ b/src/useCompletion.ts @@ -0,0 +1,58 @@ +import { ExtensionContext, CompletionItem, CompletionItemKind, languages, Disposable, workspace, window, commands, TextDocument, Position, Range, Selection, MarkdownString } from "vscode"; +import { Rule } from './interface'; +import { COMPLETION_TRIGGER_ID } from './constant'; +export default function (context: ExtensionContext, RULES: Rule[]) { + registerCommand(); + const disposable = languages.registerCompletionItemProvider('plaintext', { + provideCompletionItems(document, position) { + const linePrefix = document.lineAt(position).text.substr(0, position.character); + if (!linePrefix.endsWith(COMPLETION_TRIGGER_ID)) return; + + return RULES.map(({ rule, title, examples }) => { + const item = new CompletionItem(title, CompletionItemKind.Method); + const ruleString = String(rule); + + item.insertText = ruleString; + item.documentation = new MarkdownString(`### 示例\r\n${examples.join(',')}`); + // item.filterText = '手'; + item.command = { + title: '插入正则', + command: 'functions.insertRegex', + arguments: [document, position, ruleString] + }; + return item; + }) + }, + + resolveCompletionItem(item) { + return item; + } + }, '.'); + context.subscriptions.push(disposable); +} + +function registerCommand() { + commands.registerCommand('functions.insertRegex', (document: TextDocument, position: Position, ruleString: string) => { + const editor = window.activeTextEditor; + if (void 0 === editor) return; + editor.edit(editBuilder => { + const line = document.lineAt(position); + // 起始 + const startPostion = new Position(line.lineNumber, line.text.indexOf(COMPLETION_TRIGGER_ID)); + + // 结束 + const endPostion = new Position(line.lineNumber, startPostion.character + ruleString.length + COMPLETION_TRIGGER_ID.length); + + // window.showInformationMessage( + // '' + startPostion.character + // , ''+endPostion.character + // ); + + editBuilder.replace(new Range(startPostion, endPostion), ruleString); + + setTimeout(() => { + editor.selection = new Selection(startPostion, endPostion); + }, 0); + }); + }); +} diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index 3c7e570..0000000 --- a/src/utils.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { IRule } from './interface'; -// import { convertToPinyin } from 'tiny-pinyin'; -import { slugify } from 'transliteration'; - -function preprocessText(START_IDENTIFIER: string, text: string): string[] | null { - const start = text.indexOf(START_IDENTIFIER); - if (start === -1) { - return null; - } - const pathString = text.substring(start, text.length); - const pathArray = pathString.split('.'); - return pathArray; -} - -/** - * 根据特定的字符串解析出当前可以用的规则列表 - * @param text 待解析的字符串 - */ -export function getRulesByText(START_IDENTIFIER: string, rules: IRule[], text: string): IRule[] { - const pathArray = preprocessText(START_IDENTIFIER, text); - if (!pathArray) { - return []; - } - let currentRules: IRule[] = []; - let targetRules = rules; - - for (const path of pathArray) { - if (path === START_IDENTIFIER) { - currentRules = rules; - } else if (path === '') { - break; - } else { - const searchRule = targetRules.find(rule => rule.title === path); - - if (!searchRule) { - return []; - } - - if (searchRule.regex) { - return []; - } - - currentRules = searchRule.rules || []; - targetRules = currentRules; - } - } - - return currentRules; -} - -export function getRuleByText(START_IDENTIFIER: string, rules: IRule[], text: string): IRule | null { - const pathArray = preprocessText(START_IDENTIFIER, text); - if (!pathArray) { - return null; - } - let targetRules = rules; - let searchRule: IRule | undefined; - for (const path of pathArray) { - if (path === START_IDENTIFIER) { - continue; - } - - searchRule = targetRules.find(rule => rule.title === path); - if (!searchRule) { - return null; - } - if (searchRule.regex) { - break; - } else { - targetRules = searchRule.rules || []; - } - } - - return searchRule || null; -} - -export function generateFilterString(rule: IRule) { - let filterString = ''; - filterString += rule.title; - const pinyin = slugify(rule.title).split('-'); - if (/.*[\u4e00-\u9fa5]+.*$/.test(rule.title)) { - filterString += ' ' + pinyin.join(''); - filterString += ' ' + pinyin.map(item => item.length ? item[0] : ''); - } - - if (rule.keywords) { - filterString += ' ' + rule.keywords.join(' '); - } - - return filterString; -} diff --git a/wip.zip b/wip.zip new file mode 100644 index 0000000..0a5187f Binary files /dev/null and b/wip.zip differ diff --git a/yarn.lock b/yarn.lock index cb8260c..5e10019 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,6 +18,11 @@ esutils "^2.0.2" js-tokens "^4.0.0" +"@types/color-name@^1.1.1": + version "1.1.1" + resolved "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" + integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== + "@types/events@*": version "3.0.0" resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" @@ -84,6 +89,11 @@ ansi-regex@^4.1.0: resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== +ansi-regex@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" + integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -91,6 +101,14 @@ ansi-styles@^3.2.1: dependencies: color-convert "^1.9.0" +ansi-styles@^4.0.0: + version "4.2.1" + resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359" + integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA== + dependencies: + "@types/color-name" "^1.1.1" + color-convert "^2.0.1" + argparse@^1.0.7: version "1.0.10" resolved "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -144,6 +162,15 @@ cliui@^4.0.0: strip-ansi "^4.0.0" wrap-ansi "^2.0.0" +cliui@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1" + integrity sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^6.2.0" + code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" @@ -156,11 +183,23 @@ color-convert@^1.9.0: dependencies: color-name "1.1.3" +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + color-name@1.1.3: version "1.1.3" resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + commander@^2.12.1: version "2.20.0" resolved "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" @@ -218,6 +257,11 @@ emoji-regex@^7.0.1: resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + end-of-stream@^1.1.0: version "1.4.1" resolved "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43" @@ -293,6 +337,14 @@ find-up@3.0.0, find-up@^3.0.0: dependencies: locate-path "^3.0.0" +find-up@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" + integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== + dependencies: + locate-path "^5.0.0" + path-exists "^4.0.0" + flat@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2" @@ -439,6 +491,11 @@ is-fullwidth-code-point@^2.0.0: resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + is-regex@^1.0.4: version "1.0.4" resolved "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" @@ -491,6 +548,13 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" +locate-path@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" + integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== + dependencies: + p-locate "^4.1.0" + lodash@^4.17.11: version "4.17.15" resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" @@ -673,6 +737,13 @@ p-limit@^2.0.0: dependencies: p-try "^2.0.0" +p-limit@^2.2.0: + version "2.2.2" + resolved "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz#61279b67721f5287aa1c13a9a7fbbc48c9291b1e" + integrity sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ== + dependencies: + p-try "^2.0.0" + p-locate@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" @@ -680,6 +751,13 @@ p-locate@^3.0.0: dependencies: p-limit "^2.0.0" +p-locate@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" + integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== + dependencies: + p-limit "^2.2.0" + p-try@^2.0.0: version "2.2.0" resolved "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" @@ -690,6 +768,11 @@ path-exists@^3.0.0: resolved "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" integrity sha1-zg6+ql94yxiSXqfYENe1mwEP1RU= +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -793,6 +876,15 @@ string-width@^3.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" +string-width@^4.1.0, string-width@^4.2.0: + version "4.2.0" + resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5" + integrity sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.0" + strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" @@ -814,6 +906,13 @@ strip-ansi@^5.1.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" + integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== + dependencies: + ansi-regex "^5.0.0" + strip-eof@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" @@ -838,6 +937,13 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" +transliteration@^2.1.8: + version "2.1.8" + resolved "https://registry.npmjs.org/transliteration/-/transliteration-2.1.8.tgz#b2a032107be42910dbb792ff96b39938114a4eb8" + integrity sha512-ds3uRxcS0yCxzP4xP30dz+ImEeVhgAwSaewhlApuYYTUuT8+wFFLoFfO1nHvfJzbpoRBp4lS52Ai3wm8IkemIQ== + dependencies: + yargs "^15.0.2" + tslib@^1.8.0, tslib@^1.8.1: version "1.10.0" resolved "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" @@ -909,6 +1015,15 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" +wrap-ansi@^6.2.0: + version "6.2.0" + resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -943,6 +1058,14 @@ yargs-parser@^13.0.0: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^16.1.0: + version "16.1.0" + resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-16.1.0.tgz#73747d53ae187e7b8dbe333f95714c76ea00ecf1" + integrity sha512-H/V41UNZQPkUMIT5h5hiwg4QKIY1RPvoBV4XcjUbRM8Bk2oKqqyZ0DIEbTFZB0XjbtSPG8SAa/0DxCQmiRgzKg== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-unparser@1.5.0: version "1.5.0" resolved "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz#f2bb2a7e83cbc87bb95c8e572828a06c9add6e0d" @@ -986,3 +1109,20 @@ yargs@^12.0.5: which-module "^2.0.0" y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" + +yargs@^15.0.2: + version "15.1.0" + resolved "https://registry.npmjs.org/yargs/-/yargs-15.1.0.tgz#e111381f5830e863a89550bd4b136bb6a5f37219" + integrity sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg== + dependencies: + cliui "^6.0.0" + decamelize "^1.2.0" + find-up "^4.1.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^4.2.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^16.1.0"