mirror of
https://github.com/any86/any-rule.git
synced 2025-07-14 15:38:58 +08:00
Merge remote-tracking branch 'origin/develop'
* origin/develop: (47 commits)
0.2.0
chore: 修改版本和日志为0.2.0
0.1.4
chore(build): 使用webpack打包减小体积
chore:删除无用
0.1.3
chore: 修改忽略
chore: 修改文档生成器
0.1.1
refactor: 对点击按钮日志记录
chore: 更新日志
chore: 更新文档脚本
refactor: 增加"🦕图解正则"按钮
chore: 更新文档生成脚本
chore: 忽略node_modules
chore: 修改文档生成器和版本号
0.0.15
0.0.14
chore: 调整"scripts"字段顺序
chore: 更新文档生成脚本
...
# Conflicts:
# package.json
This commit is contained in:
commit
4a6dd1d5ee
@ -8,3 +8,4 @@ vsc-extension-quickstart.md
|
||||
**/tslint.json
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/node_modules
|
71
CHANGELOG.md
71
CHANGELOG.md
@ -1,43 +1,56 @@
|
||||
# 更新日志
|
||||
🚀 提交问题: https://github.com/any86/any-rule/issues/new
|
||||
🚀 [提交问题](https://github.com/any86/any-rule/issues/new)
|
||||
|
||||
- 0.0.13
|
||||
- [x] 给"统一社会信用代码"增加^$标记
|
||||
- [x] 修复图片/视频连接匹配不严谨
|
||||
- [x] 增加"机身码IMEI"正则
|
||||
- [x] 增加"火车车次"正则
|
||||
### 0.2.0 (2020-02-21)
|
||||
|
||||
- 0.0.12
|
||||
- [x] 增加"必须带端口号的网址(或ip)"正则
|
||||
- [x] 修复网址可以匹配"...."的错误
|
||||
- 优化"zz."体验, 改用"quickPick"组件以支持"模糊搜索".
|
||||

|
||||
- 增加"设置"功能, 可以在设置中搜索"any-rule".
|
||||
- 新增"🦕图解正则".
|
||||

|
||||
|
||||
- 0.0.11
|
||||
- [x] 增加"统一社会信用代码"正则
|
||||

|
||||
|
||||
- 0.0.10
|
||||
- [x] 迅雷正则增加thunderx规则的支持
|
||||
### 0.1.0
|
||||
- 新增支持在代码任意位置输入"zz."唤醒正则列表.
|
||||
|
||||
- 0.0.9
|
||||
- [x] 修复"ed2k"正则错误
|
||||
### 0.0.13
|
||||
- 给"统一社会信用代码"增加^$标记
|
||||
- 修复图片/视频连接匹配不严谨
|
||||
- 增加"机身码IMEI"正则
|
||||
- 增加"火车车次"正则
|
||||
|
||||
- 0.0.8
|
||||
- [x] 优化车牌号正则
|
||||
### 0.0.12
|
||||
- 增加"必须带端口号的网址(或ip)"正则
|
||||
- 修复网址可以匹配"...."的错误
|
||||
|
||||
- 0.0.7
|
||||
- [x] 更新"银行卡"的匹配长度为10-30位,参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1)
|
||||
### 0.0.11
|
||||
- 增加"统一社会信用代码"正则
|
||||
|
||||
- 0.0.6
|
||||
- [x] 修复"手机号(严禁)正则"错误.
|
||||
### 0.0.10
|
||||
- 迅雷正则增加thunderx规则的支持
|
||||
|
||||
- 0.0.5
|
||||
- [x] 增加正则"迅雷链接" / "ed2k连接" / "磁力链接" / "子网掩码" / "linux文件(夹)路径" / "window文件(夹)路径"
|
||||
### 0.0.9
|
||||
- 修复"ed2k"正则错误
|
||||
|
||||
### 0.0.8
|
||||
- 优化车牌号正则
|
||||
|
||||
### 0.0.7
|
||||
- 更新"银行卡"的匹配长度为10-30位,参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1)
|
||||
|
||||
### 0.0.6
|
||||
- 修复"手机号(严禁)正则"错误.
|
||||
|
||||
### 0.0.5
|
||||
- 增加正则"迅雷链接" / "ed2k连接" / "磁力链接" / "子网掩码" / "linux文件(夹)路径" / "window文件(夹)路径"
|
||||
|
||||
|
||||
- 0.0.4
|
||||
- [x] 优化"大于0, 小于150, 支持小数位出现5"减少没必要的捕获
|
||||
- [x] 修复"html注释"没有匹配换行符
|
||||
### 0.0.4
|
||||
- 优化"大于0, 小于150, 支持小数位出现5"减少没必要的捕获
|
||||
- 修复"html注释"没有匹配换行符
|
||||
|
||||
- 0.0.3
|
||||
### 0.0.3
|
||||
|
||||
- [x] 解决vscode低版本兼容问题
|
||||
- [x] 替换主页的git图地址
|
||||
- 解决vscode低版本兼容问题
|
||||
- 替换主页的git图地址
|
92
README.md
92
README.md
@ -1,18 +1,40 @@
|
||||
# 正则大全  [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule) [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule) [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)  [](https://circleci.com/gh/any86/any-rule)
|
||||
# 正则大全  [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule) [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule) [](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)  [](https://circleci.com/gh/any86/any-rule)
|
||||
|
||||
支持**图形界面** / **vscode插件**2种查询方式.
|
||||
支持**web** / **vscode插件**2种查询方式.
|
||||
|
||||
## :rocket:图形界面
|
||||
## :rocket:web版本
|
||||
https://any86.github.io/any-rule/
|
||||
|
||||
## 🍭vscode插件
|
||||
1. 安装vscode中插件搜索框输入**any-rule**
|
||||
2. 安装完毕后按**F1**(或者ctrl+shift+p).
|
||||
3. 输入"**zz**"可以看到正则列表.
|
||||
4. 或者**输入关键词**, 比如"手机".
|
||||
### 安装
|
||||
vscode应用商店中搜索"**any-rule**".
|
||||
|
||||
### 使用
|
||||
**方式1:**
|
||||
1. 安装完毕后按**F1**(或者ctrl+shift+p).
|
||||
2. 输入"**zz**"弹出正则列表.
|
||||
3. **输入关键词搜索**, 比如"手机".
|
||||
|
||||

|
||||
|
||||
**方式2:**
|
||||
|
||||
1. 在代码的任意位置输入"**zz.**"弹出正则列表.
|
||||
2. **输入关键词搜索**, 比如"手机".
|
||||
|
||||

|
||||
|
||||
## 🦕图解正则
|
||||
在vscode中选择正则后, 可点击"🦕图解正则".
|
||||
|
||||

|
||||
|
||||
点击后可以看到正则解析, 方便大家学习.
|
||||
|
||||

|
||||
|
||||
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
||||
|
||||
## :fire:关于PR
|
||||
欢迎大家PR, 步骤如下:
|
||||
1. **正则**请在**packages/www/src/RULES.js**中添加.
|
||||
@ -60,7 +82,7 @@ https://any86.github.io/any-rule/
|
||||
|
||||
### 网址(支持端口和"?+参数"和"#+参数)
|
||||
```javascript
|
||||
/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?$/
|
||||
/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?$/
|
||||
```
|
||||
|
||||
### 统一社会信用代码
|
||||
@ -90,15 +112,15 @@ https://any86.github.io/any-rule/
|
||||
|
||||
### linux"文件夹"路径
|
||||
```javascript
|
||||
/^(\/[^\/]+)+\/?$/
|
||||
/^(\/[^/]+)+\/?$/
|
||||
```
|
||||
|
||||
### linux"文件"路径
|
||||
```javascript
|
||||
/^(\/[^\/]+)+$/
|
||||
/^(\/[^/]+)+$/
|
||||
```
|
||||
|
||||
### window下"文件夹"路径
|
||||
### window"文件夹"路径
|
||||
```javascript
|
||||
/^[a-zA-Z]:\\(?:\w+\\?)*$/
|
||||
```
|
||||
@ -108,7 +130,7 @@ https://any86.github.io/any-rule/
|
||||
/^[a-zA-Z]:\\(?:\w+\\)*\w+\.\w+$/
|
||||
```
|
||||
|
||||
### A股代码
|
||||
### 股票代码(A股)
|
||||
```javascript
|
||||
/^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$/
|
||||
```
|
||||
@ -155,7 +177,7 @@ https://any86.github.io/any-rule/
|
||||
|
||||
### base64格式
|
||||
```javascript
|
||||
/^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i
|
||||
/^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*?)\s*$/i
|
||||
```
|
||||
|
||||
### 数字/货币金额(支持负数、千分位分隔符)
|
||||
@ -183,12 +205,12 @@ https://any86.github.io/any-rule/
|
||||
/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/
|
||||
```
|
||||
|
||||
### 新能源车牌号
|
||||
### 车牌号(新能源)
|
||||
```javascript
|
||||
/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$/
|
||||
```
|
||||
|
||||
### 非新能源车牌号
|
||||
### 车牌号(非新能源)
|
||||
```javascript
|
||||
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/
|
||||
```
|
||||
@ -198,17 +220,17 @@ https://any86.github.io/any-rule/
|
||||
/^(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(?:(?:[0-9]{5}[DF])|(?:[DF](?:[A-HJ-NP-Z0-9])[0-9]{4})))|(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9 挂学警港澳]{1})$/
|
||||
```
|
||||
|
||||
### 中国手机号(严谨), 根据工信部2019年最新公布的手机号段
|
||||
### 手机号中国(严谨), 根据工信部2019年最新公布的手机号段
|
||||
```javascript
|
||||
/^(?:(?:\+|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}$/
|
||||
```
|
||||
|
||||
### 中国手机号(宽松), 只要是13,14,15,16,17,18,19开头即可
|
||||
### 手机号中国(宽松), 只要是13,14,15,16,17,18,19开头即可
|
||||
```javascript
|
||||
/^(?:(?:\+|00)86)?1[3-9]\d{9}$/
|
||||
```
|
||||
|
||||
### 中国手机号(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条
|
||||
### 手机号中国(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条
|
||||
```javascript
|
||||
/^(?:(?:\+|00)86)?1\d{10}$/
|
||||
```
|
||||
@ -218,22 +240,22 @@ https://any86.github.io/any-rule/
|
||||
/^\d{4}(-)(1[0-2]|0?\d)\1([0-2]\d|\d|30|31)$/
|
||||
```
|
||||
|
||||
### 邮箱地址(email)
|
||||
### email(邮箱)
|
||||
```javascript
|
||||
/^[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])?)*$/
|
||||
/^[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])?)*$/
|
||||
```
|
||||
|
||||
### 国内座机电话,如: 0341-86091234
|
||||
### 座机电话(国内),如: 0341-86091234
|
||||
```javascript
|
||||
/\d{3}-\d{8}|\d{4}-\d{7}/
|
||||
```
|
||||
|
||||
### 一代身份证号(15位数字)
|
||||
### 身份证号(1代,15位数字)
|
||||
```javascript
|
||||
/^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$/
|
||||
```
|
||||
|
||||
### 二代身份证号(18位数字),最后一位是校验位,可能为数字或字符X
|
||||
### 身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符X
|
||||
```javascript
|
||||
/^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}[\dXx]$/
|
||||
```
|
||||
@ -253,47 +275,47 @@ https://any86.github.io/any-rule/
|
||||
/^[a-zA-Z]\w{4,15}$/
|
||||
```
|
||||
|
||||
### 纯中文/汉字
|
||||
### 中文/汉字
|
||||
```javascript
|
||||
/^(?:[\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])+$/
|
||||
```
|
||||
|
||||
### 是否小数
|
||||
### 小数
|
||||
```javascript
|
||||
/^\d+\.\d+$/
|
||||
```
|
||||
|
||||
### 纯数字
|
||||
### 数字
|
||||
```javascript
|
||||
/^\d{1,}$/
|
||||
```
|
||||
|
||||
### 是否html标签(宽松匹配)
|
||||
### html标签(宽松匹配)
|
||||
```javascript
|
||||
/<(\w+)[^>]*>(.*?<\/\1>)?/
|
||||
```
|
||||
|
||||
### 是否qq号格式正确
|
||||
### qq号格式正确
|
||||
```javascript
|
||||
/^[1-9][0-9]{4,10}$/
|
||||
```
|
||||
|
||||
### 是否由数字和字母组成
|
||||
### 数字和字母组成
|
||||
```javascript
|
||||
/^[A-Za-z0-9]+$/
|
||||
```
|
||||
|
||||
### 纯英文字母
|
||||
### 英文字母
|
||||
```javascript
|
||||
/^[a-zA-Z]+$/
|
||||
```
|
||||
|
||||
### 纯小写英文字母组成
|
||||
### 小写英文字母组成
|
||||
```javascript
|
||||
/^[a-z]+$/
|
||||
```
|
||||
|
||||
### 纯大写英文字母
|
||||
### 大写英文字母
|
||||
```javascript
|
||||
/^[A-Z]+$/
|
||||
```
|
||||
@ -328,12 +350,12 @@ https://any86.github.io/any-rule/
|
||||
/^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/
|
||||
```
|
||||
|
||||
### 中国邮政编码
|
||||
### 邮政编码(中国)
|
||||
```javascript
|
||||
/^(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}$/
|
||||
```
|
||||
|
||||
### 只包含中文和数字
|
||||
### 中文和数字
|
||||
```javascript
|
||||
/^((?:[\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))+$/
|
||||
```
|
||||
@ -343,7 +365,7 @@ https://any86.github.io/any-rule/
|
||||
/^[^A-Za-z]*$/
|
||||
```
|
||||
|
||||
### Android 包名校验
|
||||
### java包名
|
||||
```javascript
|
||||
/^([a-zA-Z_][a-zA-Z0-9_]*)+([.][a-zA-Z_][a-zA-Z0-9_]*)+$/
|
||||
```
|
||||
|
@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
const vscode = require("vscode");
|
||||
const RULES = require('../packages/www/src/RULES.js');
|
||||
// this method is called when your extension is activated
|
||||
// your extension is activated the very first time the command is executed
|
||||
function activate(context) {
|
||||
// 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
|
||||
// Display a message box to the user
|
||||
// vscode.window.showInformationMessage('Hello World123!');
|
||||
// });
|
||||
// context.subscriptions.push(disposable);
|
||||
RULES.forEach(({ title, rule }, index) => {
|
||||
let disposable = vscode.commands.registerCommand(`extension.rule${index}`, () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
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));
|
||||
});
|
||||
});
|
||||
// Display a message box to the user
|
||||
vscode.window.showInformationMessage(`已插入正则: ${title}`);
|
||||
}
|
||||
else {
|
||||
vscode.window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!');
|
||||
}
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
}
|
||||
exports.activate = activate;
|
||||
// this method is called when your extension is deactivated
|
||||
function deactivate() {
|
||||
vscode.window.showWarningMessage('any-rule: 已关闭!');
|
||||
}
|
||||
exports.deactivate = deactivate;
|
||||
//# sourceMappingURL=extension.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAAA,6DAA6D;AAC7D,8EAA8E;AAC9E,iCAAiC;AACjC,MAAM,KAAK,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AACtD,yDAAyD;AACzD,0EAA0E;AAC1E,SAAgB,QAAQ,CAAC,OAAgC;IACxD,4FAA4F;IAC5F,gFAAgF;IAChF,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;IAEzE,wDAAwD;IACxD,qEAAqE;IACrE,uEAAuE;IAGvE,mFAAmF;IACnF,+EAA+E;IAE/E,oCAAoC;IACpC,2DAA2D;IAC3D,MAAM;IACN,0CAA0C;IAE1C,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAoD,EAAE,KAAa,EAAE,EAAE;QAClG,IAAI,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,EAAE,EAAE,GAAG,EAAE;YAC/E,+EAA+E;YAC/E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAC9C,IAAI,MAAM,EAAE;gBACX,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;gBAE9B,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;oBACzB,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;wBAC9B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;wBACjC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;wBAC3C,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC1C,CAAC,CAAC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBACH,oCAAoC;gBACpC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;aACxD;iBAAM;gBACN,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,CAAC;aAC/D;QACF,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AAIJ,CAAC;AA3CD,4BA2CC;AAED,2DAA2D;AAC3D,SAAgB,UAAU;IACzB,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AACpD,CAAC;AAFD,gCAEC"}
|
@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path = require("path");
|
||||
const vscode_test_1 = require("vscode-test");
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
yield vscode_test_1.runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
main();
|
||||
//# sourceMappingURL=runTest.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"runTest.js","sourceRoot":"","sources":["../../src/test/runTest.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,6BAA6B;AAE7B,6CAAuC;AAEvC,SAAe,IAAI;;QAClB,IAAI;YACH,4DAA4D;YAC5D,yCAAyC;YACzC,MAAM,wBAAwB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAEnE,0BAA0B;YAC1B,iCAAiC;YACjC,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YAEpE,0DAA0D;YAC1D,MAAM,sBAAQ,CAAC,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,CAAC,CAAC;SACjE;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;IACF,CAAC;CAAA;AAED,IAAI,EAAE,CAAC"}
|
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert = require("assert");
|
||||
const mocha_1 = require("mocha");
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
const vscode = require("vscode");
|
||||
// import * as myExtension from '../extension';
|
||||
suite('Extension Test Suite', () => {
|
||||
mocha_1.before(() => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
});
|
||||
test('Sample test', () => {
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=extension.test.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../../src/test/suite/extension.test.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AACjC,iCAA+B;AAE/B,0DAA0D;AAC1D,8CAA8C;AAC9C,iCAAiC;AACjC,+CAA+C;AAE/C,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,cAAM,CAAC,GAAG,EAAE;QACX,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
@ -1,38 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path = require("path");
|
||||
const Mocha = require("mocha");
|
||||
const glob = require("glob");
|
||||
function run() {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
});
|
||||
mocha.useColors(true);
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
// Add files to the test suite
|
||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run(failures => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
}
|
||||
else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.run = run;
|
||||
//# sourceMappingURL=index.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/suite/index.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAE7B,SAAgB,GAAG;IAClB,wBAAwB;IACxB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;QACvB,EAAE,EAAE,KAAK;KACT,CAAC,CAAC;IACH,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEhD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,IAAI,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxD,IAAI,GAAG,EAAE;gBACR,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;aACd;YAED,8BAA8B;YAC9B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAE9D,IAAI;gBACH,qBAAqB;gBACrB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBACpB,IAAI,QAAQ,GAAG,CAAC,EAAE;wBACjB,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,QAAQ,gBAAgB,CAAC,CAAC,CAAC;qBAC1C;yBAAM;wBACN,CAAC,EAAE,CAAC;qBACJ;gBACF,CAAC,CAAC,CAAC;aACH;YAAC,OAAO,GAAG,EAAE;gBACb,CAAC,CAAC,GAAG,CAAC,CAAC;aACP;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAhCD,kBAgCC"}
|
233
package.json
233
package.json
@ -3,7 +3,17 @@
|
||||
"publisher": "russell",
|
||||
"displayName": "any-rule",
|
||||
"description": "你要的\"正则\"都在这!",
|
||||
"version": "0.0.14",
|
||||
"version": "0.2.0",
|
||||
"scripts": {
|
||||
"build:md": "node ./scripts/md.js",
|
||||
"build": "npm run test:rules && npm version patch && node ./scripts/genCommond.js && vsce package && npm run build:md",
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "webpack --mode production",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile",
|
||||
"test": "node ./out/test/runTest.js",
|
||||
"test:rules": "node __test__/rule"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.12.0"
|
||||
},
|
||||
@ -19,327 +29,273 @@
|
||||
"url": "git+https://github.com/any86/any-rule.git"
|
||||
},
|
||||
"activationEvents": [
|
||||
"onCommand:extension.rule0",
|
||||
"onCommand:extension.rule1",
|
||||
"onCommand:extension.rule2",
|
||||
"onCommand:extension.rule3",
|
||||
"onCommand:extension.rule4",
|
||||
"onCommand:extension.rule5",
|
||||
"onCommand:extension.rule6",
|
||||
"onCommand:extension.rule7",
|
||||
"onCommand:extension.rule8",
|
||||
"onCommand:extension.rule9",
|
||||
"onCommand:extension.rule10",
|
||||
"onCommand:extension.rule11",
|
||||
"onCommand:extension.rule12",
|
||||
"onCommand:extension.rule13",
|
||||
"onCommand:extension.rule14",
|
||||
"onCommand:extension.rule15",
|
||||
"onCommand:extension.rule16",
|
||||
"onCommand:extension.rule17",
|
||||
"onCommand:extension.rule18",
|
||||
"onCommand:extension.rule19",
|
||||
"onCommand:extension.rule20",
|
||||
"onCommand:extension.rule21",
|
||||
"onCommand:extension.rule22",
|
||||
"onCommand:extension.rule23",
|
||||
"onCommand:extension.rule24",
|
||||
"onCommand:extension.rule25",
|
||||
"onCommand:extension.rule26",
|
||||
"onCommand:extension.rule27",
|
||||
"onCommand:extension.rule28",
|
||||
"onCommand:extension.rule29",
|
||||
"onCommand:extension.rule30",
|
||||
"onCommand:extension.rule31",
|
||||
"onCommand:extension.rule32",
|
||||
"onCommand:extension.rule33",
|
||||
"onCommand:extension.rule34",
|
||||
"onCommand:extension.rule35",
|
||||
"onCommand:extension.rule36",
|
||||
"onCommand:extension.rule37",
|
||||
"onCommand:extension.rule38",
|
||||
"onCommand:extension.rule39",
|
||||
"onCommand:extension.rule40",
|
||||
"onCommand:extension.rule41",
|
||||
"onCommand:extension.rule42",
|
||||
"onCommand:extension.rule43",
|
||||
"onCommand:extension.rule44",
|
||||
"onCommand:extension.rule45",
|
||||
"onCommand:extension.rule46",
|
||||
"onCommand:extension.rule47",
|
||||
"onCommand:extension.rule48",
|
||||
"onCommand:extension.rule49",
|
||||
"onCommand:extension.rule50",
|
||||
"onCommand:extension.rule51",
|
||||
"onCommand:extension.rule52",
|
||||
"onCommand:extension.rule53",
|
||||
"onCommand:extension.rule54",
|
||||
"onCommand:extension.rule55",
|
||||
"onCommand:extension.rule56",
|
||||
"onCommand:extension.rule57",
|
||||
"onCommand:extension.rule58",
|
||||
"onCommand:extension.rule59",
|
||||
"onCommand:extension.rule60"
|
||||
"*"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "any-rule",
|
||||
"properties": {
|
||||
"AnyRule.triggerString": {
|
||||
"type": "string",
|
||||
"default": "zz.",
|
||||
"description": "触发字符串"
|
||||
},
|
||||
"AnyRule.supportedLanguages": {
|
||||
"type": "string",
|
||||
"default": "*, javascript, typescript, javascriptreact, typescriptreact, markdown, jsx, vue, html, json, plaintext, coffeescript",
|
||||
"description": "如果您的文件格式未被支持, 请在此处添加(⚡添加成功后需要重启vscode)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.rule0",
|
||||
"title": "zz: 火车车次"
|
||||
"title": "$(rocket) zz: 火车车次"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule1",
|
||||
"title": "zz: 手机机身码(IMEI)"
|
||||
"title": "$(rocket) zz: 手机机身码(IMEI)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule2",
|
||||
"title": "zz: 必须带端口号的网址(或ip)"
|
||||
"title": "$(rocket) zz: 必须带端口号的网址(或ip)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule3",
|
||||
"title": "zz: 网址(支持端口和\"?+参数\"和\"#+参数)"
|
||||
"title": "$(rocket) zz: 网址(支持端口和\"?+参数\"和\"#+参数)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule4",
|
||||
"title": "zz: 统一社会信用代码"
|
||||
"title": "$(rocket) zz: 统一社会信用代码"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule5",
|
||||
"title": "zz: 迅雷链接"
|
||||
"title": "$(rocket) zz: 迅雷链接"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule6",
|
||||
"title": "zz: ed2k链接(宽松匹配)"
|
||||
"title": "$(rocket) zz: ed2k链接(宽松匹配)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule7",
|
||||
"title": "zz: 磁力链接(宽松匹配)"
|
||||
"title": "$(rocket) zz: 磁力链接(宽松匹配)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule8",
|
||||
"title": "zz: 子网掩码"
|
||||
"title": "$(rocket) zz: 子网掩码"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule9",
|
||||
"title": "zz: linux\"文件夹\"路径"
|
||||
"title": "$(rocket) zz: linux\"文件夹\"路径"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule10",
|
||||
"title": "zz: linux\"文件\"路径"
|
||||
"title": "$(rocket) zz: linux\"文件\"路径"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule11",
|
||||
"title": "zz: window下\"文件夹\"路径"
|
||||
"title": "$(rocket) zz: window\"文件夹\"路径"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule12",
|
||||
"title": "zz: window下\"文件\"路径"
|
||||
"title": "$(rocket) zz: window下\"文件\"路径"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule13",
|
||||
"title": "zz: A股代码"
|
||||
"title": "$(rocket) zz: 股票代码(A股)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule14",
|
||||
"title": "zz: 大于等于0, 小于等于150, 支持小数位出现5, 如145.5, 用于判断考卷分数"
|
||||
"title": "$(rocket) zz: 大于等于0, 小于等于150, 支持小数位出现5, 如145.5, 用于判断考卷分数"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule15",
|
||||
"title": "zz: html注释"
|
||||
"title": "$(rocket) zz: html注释"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule16",
|
||||
"title": "zz: md5格式(32位)"
|
||||
"title": "$(rocket) zz: md5格式(32位)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule17",
|
||||
"title": "zz: 版本号格式必须为X.Y.Z"
|
||||
"title": "$(rocket) zz: 版本号格式必须为X.Y.Z"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule18",
|
||||
"title": "zz: 视频链接地址(视频格式可按需增删)"
|
||||
"title": "$(rocket) zz: 视频链接地址(视频格式可按需增删)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule19",
|
||||
"title": "zz: 图片链接地址(图片格式可按需增删)"
|
||||
"title": "$(rocket) zz: 图片链接地址(图片格式可按需增删)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule20",
|
||||
"title": "zz: 24小时制时间(HH:mm:ss)"
|
||||
"title": "$(rocket) zz: 24小时制时间(HH:mm:ss)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule21",
|
||||
"title": "zz: 12小时制时间(hh:mm:ss)"
|
||||
"title": "$(rocket) zz: 12小时制时间(hh:mm:ss)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule22",
|
||||
"title": "zz: base64格式"
|
||||
"title": "$(rocket) zz: base64格式"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule23",
|
||||
"title": "zz: 数字/货币金额(支持负数、千分位分隔符)"
|
||||
"title": "$(rocket) zz: 数字/货币金额(支持负数、千分位分隔符)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule24",
|
||||
"title": "zz: 数字/货币金额 (只支持正数、不支持校验千分位分隔符)"
|
||||
"title": "$(rocket) zz: 数字/货币金额 (只支持正数、不支持校验千分位分隔符)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule25",
|
||||
"title": "zz: 银行卡号(10到30位, 覆盖对公/私账户, 参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1))"
|
||||
"title": "$(rocket) zz: 银行卡号(10到30位, 覆盖对公/私账户, 参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1))"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule26",
|
||||
"title": "zz: 中文姓名"
|
||||
"title": "$(rocket) zz: 中文姓名"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule27",
|
||||
"title": "zz: 英文姓名"
|
||||
"title": "$(rocket) zz: 英文姓名"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule28",
|
||||
"title": "zz: 新能源车牌号"
|
||||
"title": "$(rocket) zz: 车牌号(新能源)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule29",
|
||||
"title": "zz: 非新能源车牌号"
|
||||
"title": "$(rocket) zz: 车牌号(非新能源)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule30",
|
||||
"title": "zz: 车牌号(新能源+非新能源)"
|
||||
"title": "$(rocket) zz: 车牌号(新能源+非新能源)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule31",
|
||||
"title": "zz: 中国手机号(严谨), 根据工信部2019年最新公布的手机号段"
|
||||
"title": "$(rocket) zz: 手机号中国(严谨), 根据工信部2019年最新公布的手机号段"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule32",
|
||||
"title": "zz: 中国手机号(宽松), 只要是13,14,15,16,17,18,19开头即可"
|
||||
"title": "$(rocket) zz: 手机号中国(宽松), 只要是13,14,15,16,17,18,19开头即可"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule33",
|
||||
"title": "zz: 中国手机号(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条"
|
||||
"title": "$(rocket) zz: 手机号中国(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule34",
|
||||
"title": "zz: 日期"
|
||||
"title": "$(rocket) zz: 日期"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule35",
|
||||
"title": "zz: 邮箱地址(email)"
|
||||
"title": "$(rocket) zz: email(邮箱)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule36",
|
||||
"title": "zz: 国内座机电话,如: 0341-86091234"
|
||||
"title": "$(rocket) zz: 座机电话(国内),如: 0341-86091234"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule37",
|
||||
"title": "zz: 一代身份证号(15位数字)"
|
||||
"title": "$(rocket) zz: 身份证号(1代,15位数字)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule38",
|
||||
"title": "zz: 二代身份证号(18位数字),最后一位是校验位,可能为数字或字符X"
|
||||
"title": "$(rocket) zz: 身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符X"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule39",
|
||||
"title": "zz: 身份证号, 支持1/2代(15位/18位数字)"
|
||||
"title": "$(rocket) zz: 身份证号, 支持1/2代(15位/18位数字)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule40",
|
||||
"title": "zz: 护照(包含香港、澳门)"
|
||||
"title": "$(rocket) zz: 护照(包含香港、澳门)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule41",
|
||||
"title": "zz: 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线组合"
|
||||
"title": "$(rocket) zz: 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线组合"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule42",
|
||||
"title": "zz: 纯中文/汉字"
|
||||
"title": "$(rocket) zz: 中文/汉字"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule43",
|
||||
"title": "zz: 是否小数"
|
||||
"title": "$(rocket) zz: 小数"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule44",
|
||||
"title": "zz: 电话(座机)"
|
||||
"title": "$(rocket) zz: 数字"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule45",
|
||||
"title": "zz: 纯数字"
|
||||
"title": "$(rocket) zz: html标签(宽松匹配)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule46",
|
||||
"title": "zz: 是否html标签(宽松匹配)"
|
||||
"title": "$(rocket) zz: qq号格式正确"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule47",
|
||||
"title": "zz: 是否qq号格式正确"
|
||||
"title": "$(rocket) zz: 数字和字母组成"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule48",
|
||||
"title": "zz: 是否由数字和字母组成"
|
||||
"title": "$(rocket) zz: 英文字母"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule49",
|
||||
"title": "zz: 纯英文字母"
|
||||
"title": "$(rocket) zz: 小写英文字母组成"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule50",
|
||||
"title": "zz: 纯小写英文字母组成"
|
||||
"title": "$(rocket) zz: 大写英文字母"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule51",
|
||||
"title": "zz: 纯大写英文字母"
|
||||
"title": "$(rocket) zz: 密码强度校验,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule52",
|
||||
"title": "zz: 密码强度校验,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符"
|
||||
"title": "$(rocket) zz: 用户名校验,4到16位(字母,数字,下划线,减号)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule53",
|
||||
"title": "zz: 用户名校验,4到16位(字母,数字,下划线,减号)"
|
||||
"title": "$(rocket) zz: ip-v4"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule54",
|
||||
"title": "zz: ip-v4"
|
||||
"title": "$(rocket) zz: ip-v6"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule55",
|
||||
"title": "zz: ip-v6"
|
||||
"title": "$(rocket) zz: 16进制颜色"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule56",
|
||||
"title": "zz: 16进制颜色"
|
||||
"title": "$(rocket) zz: 微信号,6至20位,以字母开头,字母,数字,减号,下划线"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule57",
|
||||
"title": "zz: 微信号,6至20位,以字母开头,字母,数字,减号,下划线"
|
||||
"title": "$(rocket) zz: 邮政编码(中国)"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule58",
|
||||
"title": "zz: 中国邮政编码"
|
||||
"title": "$(rocket) zz: 中文和数字"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule59",
|
||||
"title": "zz: 只包含中文和数字"
|
||||
"title": "$(rocket) zz: 不能包含字母"
|
||||
},
|
||||
{
|
||||
"command": "extension.rule60",
|
||||
"title": "zz: 不能包含字母"
|
||||
"title": "$(rocket) zz: java包名"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"build:md": "node ./scripts/md.js",
|
||||
"build": "npm run test:rules && npm version patch && node ./scripts/genCommond.js && vsce package && npm run build:md",
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile",
|
||||
"test": "node ./out/test/runTest.js",
|
||||
"test:rules": "node __test__/rule"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/mocha": "^5.2.6",
|
||||
@ -347,8 +303,15 @@
|
||||
"@types/vscode": "^1.12.0",
|
||||
"glob": "^7.1.4",
|
||||
"mocha": "^6.1.4",
|
||||
"typescript": "^3.3.1",
|
||||
"ts-loader": "^6.2.1",
|
||||
"tslint": "^5.12.1",
|
||||
"vscode-test": "^1.0.2"
|
||||
"typescript": "^3.3.1",
|
||||
"vscode-test": "^1.0.2",
|
||||
"webpack": "^4.41.6",
|
||||
"webpack-cli": "^3.3.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.19.2",
|
||||
"transliteration": "^2.1.8"
|
||||
}
|
||||
}
|
||||
|
@ -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: ['<div id="app"> 2333 </div>', '<input type="text">', '<br>']
|
||||
},
|
||||
{
|
||||
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']
|
||||
}
|
||||
|
@ -3,16 +3,11 @@ const pkg = require('../package.json');
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
|
||||
pkg.contributes.commands = [];
|
||||
pkg.activationEvents = [];
|
||||
RULES.forEach((rule, index) => {
|
||||
pkg.contributes.commands.push({
|
||||
command: 'extension.rule' + index,
|
||||
title: `zz: ${rule.title}`
|
||||
});
|
||||
|
||||
pkg.activationEvents.push('onCommand:extension.rule'+index);
|
||||
})
|
||||
pkg.activationEvents = ['*'];
|
||||
pkg.contributes.commands = RULES.map((rule, index) => ({
|
||||
command: 'extension.rule' + index,
|
||||
title: `$(rocket) zz: ${rule.title}`
|
||||
}));
|
||||
|
||||
// console.log(JSON.stringify(pkg));
|
||||
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 4), 'utf8');
|
||||
|
@ -5,35 +5,60 @@ const VSC_URL = 'https://marketplace.visualstudio.com/items?itemName=russell.any
|
||||
const badges = [
|
||||
// ``,
|
||||
|
||||
``,
|
||||
``,
|
||||
|
||||
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
`[](https://marketplace.visualstudio.com/items?itemName=russell.any-rule)`,
|
||||
|
||||
``,
|
||||
``,
|
||||
|
||||
`[](https://circleci.com/gh/any86/any-rule)`
|
||||
|
||||
// vscode上传不让用svg
|
||||
// `[](https://github.com/any86/any-rule/actions)`
|
||||
];
|
||||
|
||||
let content = `# 正则大全 ${badges.join(' ')}
|
||||
|
||||
支持**图形界面** / **vscode插件**2种查询方式.
|
||||
支持**web** / **vscode插件**2种查询方式.
|
||||
|
||||
## :rocket:图形界面
|
||||
## :rocket:web版本
|
||||
https://any86.github.io/any-rule/
|
||||
|
||||
## 🍭vscode插件
|
||||
1. 安装vscode中插件搜索框输入**any-rule**
|
||||
2. 安装完毕后按**F1**(或者ctrl+shift+p).
|
||||
3. 输入"**zz**"可以看到正则列表.
|
||||
4. 或者**输入关键词**, 比如"手机".
|
||||
### 安装
|
||||
vscode应用商店中搜索"**any-rule**".
|
||||
|
||||
### 使用
|
||||
**方式1:**
|
||||
1. 安装完毕后按**F1**(或者ctrl+shift+p).
|
||||
2. 输入"**zz**"弹出正则列表.
|
||||
3. **输入关键词搜索**, 比如"手机".
|
||||
|
||||

|
||||
|
||||
**方式2:**
|
||||
|
||||
1. 在代码的任意位置输入"**zz.**"弹出正则列表.
|
||||
2. **输入关键词搜索**, 比如"手机".
|
||||
|
||||

|
||||
|
||||
## 🦕图解正则
|
||||
在vscode中选择正则后, 可点击"🦕图解正则".
|
||||
|
||||

|
||||
|
||||
点击后可以看到正则解析, 方便大家学习.
|
||||
|
||||

|
||||
|
||||
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
||||
|
||||
## :fire:关于PR
|
||||
欢迎大家PR, 步骤如下:
|
||||
1. **正则**请在**packages/www/src/RULES.js**中添加.
|
||||
|
@ -1,55 +1,15 @@
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
const RULES = require('../packages/www/src/RULES.js');
|
||||
// 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: vscode.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
|
||||
|
||||
// Display a message box to the user
|
||||
// vscode.window.showInformationMessage('Hello World123!');
|
||||
// });
|
||||
// context.subscriptions.push(disposable);
|
||||
|
||||
RULES.forEach(({ title, rule }: { title: string, rule: RegExp, example: string }, index: string) => {
|
||||
let disposable = vscode.commands.registerCommand(`extension.rule${index}`, () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
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));
|
||||
});
|
||||
});
|
||||
// Display a message box to the user
|
||||
vscode.window.showInformationMessage(`已插入正则: ${title}`);
|
||||
} else {
|
||||
vscode.window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!');
|
||||
}
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
|
||||
|
||||
import {
|
||||
ExtensionContext
|
||||
} from 'vscode';
|
||||
const RULES: { title: string, rule: RegExp, examples: string[] }[] = require('../packages/www/src/RULES.js');
|
||||
import useCommand from './useCommand';
|
||||
import useQuickPick from './useQuickPick';
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
useCommand(context, RULES);
|
||||
useQuickPick(context, RULES);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() {
|
||||
vscode.window.showWarningMessage('any-rule: 已关闭!');
|
||||
}
|
||||
export function deactivate() { }
|
||||
|
28
src/insertLog.ts
Normal file
28
src/insertLog.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import axios from 'axios';
|
||||
import {version ,env} from 'vscode';
|
||||
import {getCodeLanguage,getExtensionVersion} from './shared';
|
||||
const http = axios.create({
|
||||
baseURL: 'https://leancloud.cn:443/1.1/classes/',
|
||||
timeout: 1000,
|
||||
headers: {
|
||||
"X-LC-Id": "BKaqtaJScQuqKtkAyl5jeloo-gzGzoHsz",
|
||||
"X-LC-Key": "y41qiVPTwnzLIgbDcEzcwHit",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 插入日志
|
||||
*/
|
||||
export default function ({ rule, title, method }: { rule: string, title: string, method: string }) {
|
||||
const {language,machineId} = env;
|
||||
http.post('https://leancloud.cn:443/1.1/classes/Log', {
|
||||
vscodeVersion: version,
|
||||
codeLanguage: getCodeLanguage(),
|
||||
language,
|
||||
machineId,
|
||||
rule,
|
||||
title,
|
||||
extensionVersion:getExtensionVersion(),
|
||||
method
|
||||
});
|
||||
};
|
13
src/interface.d.ts
vendored
Normal file
13
src/interface.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
export interface IRule {
|
||||
title: string;
|
||||
keywords?: string[];
|
||||
regex?: RegExp | string;
|
||||
rules?: IRule[];
|
||||
examples?: string[];
|
||||
}
|
||||
|
||||
export interface Rule{
|
||||
title:string,
|
||||
rule:RegExp,
|
||||
examples:string[]
|
||||
}
|
16
src/shared.ts
Normal file
16
src/shared.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { extensions, window} from 'vscode';
|
||||
|
||||
/**
|
||||
* 获取编程语言
|
||||
*/
|
||||
export function getCodeLanguage():string{
|
||||
return window.activeTextEditor ? window.activeTextEditor.document.languageId as string : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取插件版本号
|
||||
*/
|
||||
export function getExtensionVersion():string|void {
|
||||
const e = extensions.getExtension('russell.any-rule');
|
||||
return e && e.packageJSON.version;
|
||||
}
|
45
src/showResultMessage.ts
Normal file
45
src/showResultMessage.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { extensions, window, version, env, Uri, languages } from 'vscode';
|
||||
import { getCodeLanguage, getExtensionVersion } from './shared'
|
||||
import insertLog from './insertLog';
|
||||
|
||||
const BUTTON_FEEDBACK = '🚀反馈问题';
|
||||
const BUTTON_DIAGRAMMATIZE = '🦕图解正则';
|
||||
const BUTTON_CANCEL = '关闭';
|
||||
|
||||
export default function (title: string, rule: string): void {
|
||||
// window.setStatusBarMessage(`已插入正则: "${title}", 点击查看更多🔥`)
|
||||
window.showInformationMessage(`已插入正则: "${title}"`, BUTTON_DIAGRAMMATIZE, BUTTON_FEEDBACK, BUTTON_CANCEL).then(value => {
|
||||
if (BUTTON_FEEDBACK === value) {
|
||||
insertLog({
|
||||
rule,
|
||||
title,
|
||||
method: BUTTON_FEEDBACK
|
||||
});
|
||||
const URL = Uri.parse(genGithubIssueURL(title));
|
||||
env.openExternal(URL);
|
||||
} else if (BUTTON_DIAGRAMMATIZE === value) {
|
||||
insertLog({
|
||||
rule,
|
||||
title,
|
||||
method: BUTTON_DIAGRAMMATIZE
|
||||
});
|
||||
const URL = Uri.parse(`https://regexper.com/#${rule}`);
|
||||
env.openExternal(URL);
|
||||
}
|
||||
});
|
||||
}
|
||||
// gihub issue模板
|
||||
function genGithubIssueURL(title: string): string {
|
||||
const BASE_URL = 'https://github.com/any86/any-rule/issues/new';
|
||||
const TITLE = `title=[vscode feedback] ${title}`;
|
||||
// const BODY = `body=### vscode version
|
||||
// ${version}
|
||||
// ### extension version
|
||||
// ${getExtensionVersion()}
|
||||
// ### code language
|
||||
// ${getCodeLanguage()}
|
||||
// ### comment
|
||||
// 请留言...
|
||||
// `;
|
||||
return BASE_URL + '?' + TITLE;
|
||||
}
|
36
src/useCommand.ts
Normal file
36
src/useCommand.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { window, commands, Range, ExtensionContext } from "vscode";
|
||||
import { Rule } from './interface';
|
||||
import insertLog from './insertLog';
|
||||
import showResultMessage from './showResultMessage';
|
||||
|
||||
export default function (context: ExtensionContext, RULES: Rule[]) {
|
||||
RULES.forEach(({ title, rule }, index) => {
|
||||
const ruleString = String(rule);
|
||||
const disposable = 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, ruleString);
|
||||
});
|
||||
});
|
||||
|
||||
// 日志
|
||||
insertLog({
|
||||
rule: ruleString,
|
||||
title,
|
||||
method: 'Command'
|
||||
});
|
||||
|
||||
showResultMessage(title, ruleString);
|
||||
} else {
|
||||
window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!');
|
||||
}
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
}
|
92
src/useQuickPick.ts
Normal file
92
src/useQuickPick.ts
Normal file
@ -0,0 +1,92 @@
|
||||
import { ExtensionContext, workspace, languages, window, TextDocument, Position, Range, Selection } from "vscode";
|
||||
import { Rule } from './interface';
|
||||
// import { slugify } from 'transliteration';
|
||||
import insertLog from './insertLog';
|
||||
import showResultMessage from './showResultMessage';
|
||||
|
||||
export default function (context: ExtensionContext, RULES: Rule[]) {
|
||||
// commands.registerCommand('functions.insertRegex', insertRule);
|
||||
// 不确定是不是都兼容"*", 保守
|
||||
const { supportedLanguages, triggerStringEnd } = getConfig();
|
||||
const disposable = languages.registerCompletionItemProvider(supportedLanguages.split(','), {
|
||||
provideCompletionItems(document, position) {
|
||||
const { triggerString } = getConfig();
|
||||
// 如果为空表示关闭
|
||||
if (!triggerString) return [];
|
||||
|
||||
const linePrefix = document.lineAt(position).text.substr(0, position.character);
|
||||
if (!linePrefix.endsWith(triggerString)) return [];
|
||||
|
||||
// 滞后执行
|
||||
setTimeout(() => {
|
||||
// showQuickPick
|
||||
window.showQuickPick(RULES.map(({ examples, title, rule }) => {
|
||||
// const match = title.match(/\((.+)\)/);
|
||||
return {
|
||||
label: title,
|
||||
// description: null !== match ? match[1] : '',
|
||||
rule: String(rule), // 非标准字段, 仅仅为了传值
|
||||
detail: `例如: ${examples.join(' 或 ')}`
|
||||
};
|
||||
}), {
|
||||
placeHolder: '请输入关键词',
|
||||
// onDidSelectItem(item){
|
||||
// console.log(item)
|
||||
// }
|
||||
}).then(item => {
|
||||
if (!item) return
|
||||
insertRule(document, position, item.rule);
|
||||
|
||||
// 日志
|
||||
insertLog({
|
||||
rule: item.rule,
|
||||
title: item.label,
|
||||
method: 'QuickPick'
|
||||
});
|
||||
showResultMessage(item.label,item.rule);
|
||||
});
|
||||
}, 10)
|
||||
return [];
|
||||
},
|
||||
|
||||
resolveCompletionItem(item) {
|
||||
return item;
|
||||
}
|
||||
}, triggerStringEnd);
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
|
||||
function insertRule(document: TextDocument, position: Position, ruleString: string) {
|
||||
const { triggerString } = getConfig();
|
||||
|
||||
const editor = window.activeTextEditor;
|
||||
if (void 0 === editor) return;
|
||||
editor.edit(editBuilder => {
|
||||
const line = document.lineAt(position);
|
||||
|
||||
// 起始, "zz."前面的位置
|
||||
const startPostion = position.translate(0, -triggerString.length);
|
||||
|
||||
editBuilder.replace(new Range(startPostion, position), ruleString);
|
||||
|
||||
setTimeout(() => {
|
||||
// 全选正则字符串
|
||||
const endPostion = new Position(line.lineNumber, startPostion.character + ruleString.length);
|
||||
editor.selection = new Selection(startPostion, endPostion);
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
function getConfig() {
|
||||
const configuration = workspace.getConfiguration();
|
||||
const { triggerString, supportedLanguages = '*' } = configuration.AnyRule;
|
||||
const { length } = triggerString;
|
||||
const triggerStringStart = triggerString.substr(0, length - 1);
|
||||
const triggerStringEnd = triggerString.substr(-1);
|
||||
|
||||
return {
|
||||
triggerStringStart, triggerStringEnd, triggerString, supportedLanguages
|
||||
}
|
||||
}
|
42
webpack.config.js
Normal file
42
webpack.config.js
Normal file
@ -0,0 +1,42 @@
|
||||
// @ts-check
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
/**@type {import('webpack').Configuration}*/
|
||||
const config = {
|
||||
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
|
||||
|
||||
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
|
||||
output: {
|
||||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
|
||||
path: path.resolve(__dirname, 'out'),
|
||||
filename: 'extension.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
devtoolModuleFilenameTemplate: '../[resource-path]'
|
||||
},
|
||||
devtool: 'source-map',
|
||||
externals: {
|
||||
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
|
||||
},
|
||||
resolve: {
|
||||
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'ts-loader'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
Loading…
x
Reference in New Issue
Block a user