https://github.com/flashios09/extract-tagged-template-literals
Search and extract tagged template literals from javascript/typescript file.
https://github.com/flashios09/extract-tagged-template-literals
ember extract inline-templates tagged-template-literals
Last synced: 3 days ago
JSON representation
Search and extract tagged template literals from javascript/typescript file.
- Host: GitHub
- URL: https://github.com/flashios09/extract-tagged-template-literals
- Owner: flashios09
- Created: 2019-09-10T19:26:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:00:11.000Z (almost 3 years ago)
- Last Synced: 2025-09-03T17:58:35.305Z (about 1 month ago)
- Topics: ember, extract, inline-templates, tagged-template-literals
- Language: TypeScript
- Homepage:
- Size: 272 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Extract tagged template literals
==============================================================================Search and extract tagged template literals from javascript/typescript file.
Installation
------------------------------------------------------------------------------```bash
yarn add extract-tagged-template-literals
```Usage
------------------------------------------------------------------------------
It's possible to use more than one tag via the `|` (regex **or** separator), valid tags:
- `hbs`
- `hbs|handlebars`
- `hbs|handlebars|dotted.string`
```ts
searchAndExtract(documentContent: string, tag: string): string;
// or the hbs wrapper
searchAndExtractHbs(documentContent: string): string;
```
### Example
```ts
import { searchAndExtract } from 'extract-tagged-template-literals';const tag = 'hbs';
const documentContent = `
import GlimmerComponent from '@glimmer/component';
// @ts-ignore
import hbs from 'ember-cli-htmlbars-inline-precompile';const template = hbs\`
{{yield}}
\`;interface IComponentArgs {
type: string;
value?: any;
}class MyInputComponent extends GlimmerComponent {
type: string = 'text';
};// @ts-ignore
export default Ember._setComponentTemplate(template, MyInputComponent);
`;const extractedTaggedTemplateLiterals = searchAndExtract(documentContent, tag);
console.log(extractedTaggedTemplateLiterals);
```
Output:
```hbs
{{yield}}
{{yield}}
\`;const myButtonTemplate = handlebars\`{{yield}}\`;
interface IComponentArgs {
type: string;
value?: any;
}class MyInputComponent extends GlimmerComponent {
type: string = 'text';
layout = dotted.string\`This is just an example with **dotted.string** as a tag name and **escaped backtick** char \\\` inside the literal template \`;
};// @ts-ignore
export default Ember._setComponentTemplate(template, MyInputComponent);
`;
const extractedTaggedTemplateLiterals = searchAndExtract(documentContent, tag);
console.log(extractedTaggedTemplateLiterals);
```
Output:
```hbs
{{yield}}
{{yield}}
This is just an example with **dotted.string** as a tag name and **escaped backtick** char \` inside the literal template
```Contributing
------------------------------------------------------------------------------### Installation
* `git clone `
* `cd extract-tagged-template-literals`
* `yarn install`### Linting
* `yarn lint`
### Running test
* `yarn test`