typescript - IntelliJ 实时模板。删除或替换文件名开头的数字

标签 typescript intellij-idea phpstorm webstorm live-templates

我有文件名开头带有时间戳的数据库迁移文件。例如: 1537865596694-create-config-table.migration.ts

可以使用表达式将文件名转换为 Typescript 类名: 大写(camelCase(fileNameWithoutExtension()))

但我找不到删除或替换号码的选项。

最佳答案

您可以尝试 groovyScript("groovy code") (请参阅 https://www.jetbrains.com/help/idea/2017.2/edit-template-variables-dialog.html#predefined_functionshttp://bartololeo.blogspot.ru/2014/01/idea-12-how-to-write-live-template-with.html 。例如:

groovyScript("def res=''; def fname=_editor.getVirtualFile().getNameWithoutExtension(); def index=fname.indexOf('-'); if
(index!=-1) res=fname.substring(index+1, fname.indexOf('.')).replaceAll('(-)([A-Za-z0-9])', { Object[] it -> it[2].toUpperCase() } ) else res=fname; return res")

关于typescript - IntelliJ 实时模板。删除或替换文件名开头的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52876961/

相关文章:

git - PHPStorm 和其他 JetBrains IDE 的 : how to change default git colors?

javascript - 我是否需要使用 TypeScript + React 将事件处理程序绑定(bind)到 `this`?

angular - 如何从 Modal 调用父方法

gradle - 为什么 kotlin gradle 插件无法使用 1.8 目标构建?

html - PhpStorm 到资源根目录的相对路径

javascript - 如何解决运行测试时代码覆盖率未找到函数的问题?

validation - Angular2/ Material 2 : md-input-container label is not resetting float when value is changed programmatically

javascript - 如何移除全屏模式? (在应用浏览器中)

java - 将构造函数替换为工厂/或构建器

java - 方法参数返回后 intellij 代码格式无法正确缩进(kotlin 和 Java)