Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iahu
Created July 17, 2019 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iahu/7f41639713f74b0554b4d78aefad8e84 to your computer and use it in GitHub Desktop.
Save iahu/7f41639713f74b0554b4d78aefad8e84 to your computer and use it in GitHub Desktop.
Sublime Text 通过 RegReplace 实现对 Mock.js 到 TypeScript 类型声明语句的自动转换

Sublime Text 通过 RegReplace 实现对 Mock.js 到 TypeScript 类型声明语句的自动转换

使用方法

  • 安装 RegReplace 插件
  • 查看自定义规则文件,把下面reg_replace_rules.sublime_settings的内容合并到你的规则
  • 绑定快捷键,比如绑定到粘贴命令的快捷键上
// 绑定/修改 快捷键
[
{ "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"
}
]
}
]
// 用户规则
{
"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