- 安装 RegReplace 插件
- 查看自定义规则文件,把下面
reg_replace_rules.sublime_settings
的内容合并到你的规则 - 绑定快捷键,比如绑定到
粘贴
命令的快捷键上
Created
July 17, 2019 07:16
-
-
Save iahu/7f41639713f74b0554b4d78aefad8e84 to your computer and use it in GitHub Desktop.
Sublime Text 通过 RegReplace 实现对 Mock.js 到 TypeScript 类型声明语句的自动转换
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// 绑定/修改 快捷键 | |
[ | |
{ "keys": ["super+v"], "command": "chain", | |
"args": { | |
"commands": [ | |
["paste"], | |
["reg_replace", {"replacements": ["mock_to_number", "mock_to_string", "fix_key_argument", "fix_array_type"]}] | |
] | |
}, | |
"context": [ | |
{ | |
"operand": "source.ts", | |
"operator": "equal", | |
"match_all": true, | |
"key": "selector" | |
} | |
] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 用户规则 | |
{ | |
"replacements": | |
{ | |
"fix_array_type": | |
{ | |
"find": "\\[(\\w+)\\]", | |
"greedy": true, | |
"name": "fix_array_type", | |
"replace": "\\1[]" | |
}, | |
"fix_key_argument": | |
{ | |
"find": "'(\\w+)\\|([\\d+-]+)':", | |
"greedy": true, | |
"name": "fix_key_argument", | |
"replace": "\\1:" | |
}, | |
"js_class": | |
{ | |
"case": false, | |
"find": " class=", | |
"greedy": true, | |
"replace": " className=" | |
}, | |
"mock_to_number": | |
{ | |
"find": "'@natural\\(.+'", | |
"name": "mock_to_number", | |
"replace": "number" | |
}, | |
"mock_to_string": | |
{ | |
"find": "'@\\w+\\(.+\\'", | |
"name": "mock_to_type", | |
"replace": "string" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment