0

How do I convert my file name company-controller.js

To this:

class CompanyController extends BaseController {
  constructor() {
    super(Company);
  }
}

1 Answer 1

2

You have to transform the variable TM_FILENAME_BASE

  "ctrl": {
    "scope": "javascript",
    "prefix": "base",
    "body": [
      "class ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/} extends BaseController {",
      "\tconstructor() {",
      "\t\tsuper(${TM_FILENAME_BASE/(.*)-\\w+/${1:/pascalcase}/});",
      "\t}",
      "}"
    ],
    "description": "Extend BaseController"
  }
Sign up to request clarification or add additional context in comments.

3 Comments

I would suggest changing the second usage of pascalcase to $1:/capitalize} to avoid confusion. While pascalcase does work here, it is really meant to deal with multiple words with separators between them, which isn't the case in the super line. I just think a new user might be confused why pascalcase is necessary in the second usage.
@Mark It is needed if the filename is like company-wood-controller.js
Good catch. "\t\tsuper(${TM_FILENAME_BASE/(.*?)-|.*$/${1:/capitalize}/g});" will also work to strip off whatever is the last part of the filename and capitalize the other parts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.