ext
Learn how to extract the file extension from a path.
Returns the file extension from a path, without the leading dot.
Example
The following template prints the detected language based on a file extension:
template.json5
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Language detector", "description": "Detects the language from a file path.", "options": { "file": { "type": "string", "description": "The path to a source file.", "default": "src/App.tsx" } }, "actions": [ { "name": "print", "message": "Detected language: ${ext(options.file) === 'ts' || ext(options.file) === 'tsx' ? 'TypeScript' : 'JavaScript'}" } ]}With the default value, ext(options.file) returns tsx, so the template prints Detected language: TypeScript.
Parameters
- pathstring
The file path to extract the extension from.
Return
The file extension without the leading dot.
For example, ext('Button.tsx') returns tsx. If the path has no extension, returns an empty string.