timepiece/node_modules/parse-literals
2024-05-14 09:54:12 -05:00
..
node_modules Initial code commit 2024-05-14 09:54:12 -05:00
src Initial code commit 2024-05-14 09:54:12 -05:00
CHANGELOG.md Initial code commit 2024-05-14 09:54:12 -05:00
index.d.ts Initial code commit 2024-05-14 09:54:12 -05:00
index.js Initial code commit 2024-05-14 09:54:12 -05:00
index.js.map Initial code commit 2024-05-14 09:54:12 -05:00
LICENSE.md Initial code commit 2024-05-14 09:54:12 -05:00
package.json Initial code commit 2024-05-14 09:54:12 -05:00
README.md Initial code commit 2024-05-14 09:54:12 -05:00

parse-literals

Because sometimes you literally need to parse template literals.

npm Build Status Coverage Status

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

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