An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

Extract tagged template literals
==============================================================================

Search and extract tagged template literals from javascript/typescript file.
![The result](img/screenshot.jpg)

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`