【问题标题】:IntelliJ live template. Remove or replace number at the beginning of filenameIntelliJ 实时模板。删除或替换文件名开头的数字
【发布时间】:2018-10-18 14:59:24
【问题描述】:

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

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

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

【问题讨论】:

  • 您可以在 Live 模板中使用 GroovyScript。

标签: typescript intellij-idea phpstorm webstorm live-templates


【解决方案1】:

你可以试试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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-06
    • 2021-06-29
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多