mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 20:39:31 +08:00
R=jacktfranklin@chromium.org Bug: 1213034 Change-Id: I5da8225f60b53870a1c67d6b5d02a464c08f4eb2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2917088 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
51 lines
1.2 KiB
Markdown
51 lines
1.2 KiB
Markdown
# parse-literals
|
|
|
|
_Because sometimes you literally need to parse template literals._
|
|
|
|
[](https://www.npmjs.com/package/parse-literals)
|
|
[](https://travis-ci.com/asyncLiz/parse-literals)
|
|
[](https://coveralls.io/github/asyncLiz/parse-literals?branch=master)
|
|
|
|
## Why?
|
|
|
|
Template literals are often used in JavaScript for HTML and CSS. This library allows developers to extract the strings from the literals for post processing, such as minifying or linting.
|
|
|
|
## Usage
|
|
|
|
```js
|
|
import * as pl from 'parse-literals';
|
|
// const pl = require('parse-literals');
|
|
|
|
const templates = pl.parseLiterals(`
|
|
render() {
|
|
return html\`
|
|
<h1>\${"Hello World"}</h1>
|
|
\`;
|
|
}
|
|
`);
|
|
|
|
console.log(templates);
|
|
// [
|
|
// {
|
|
// "tag": "html",
|
|
// "parts": [
|
|
// {
|
|
// "text": "\n <h1>",
|
|
// "start": 30,
|
|
// "end": 41
|
|
// },
|
|
// {
|
|
// "text": "</h1>\n ",
|
|
// "start": 57,
|
|
// "end": 67
|
|
// }
|
|
// ]
|
|
// }
|
|
// ]
|
|
```
|
|
|
|
## Supported Source Syntax
|
|
|
|
- JavaScript
|
|
- TypeScript
|