包详细信息

parse-literals

asyncLiz90kMIT1.2.1

Parse template literals from code

parse, extract, literal, literals

自述文件

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

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.2.1 (2021-02-12)

Bug Fixes

  • parse errors with JS comments at end of expressions (3bf9053)
  • support typescript v4 (9c00311)

1.2.0 (2020-02-08)

Features

  • allow partial strategy overrides (c970ac9)

Bug Fixes

  • failure when templates are prefixed with commentss (3f34507)
  • handle "return simple" style literals (f0e30ab)
  • support TS v3 #8 (a5d7460)

1.1.1 (2019-02-13)

Bug Fixes

  • failure when templates are prefixed with commentss (3f34507)

1.1.0 (2018-10-24)

Bug Fixes

  • handle "return simple" style literals (f0e30ab)

Features

  • allow partial strategy overrides (c970ac9)

1.0.3 (2018-09-27)

Bug Fixes

  • parse escaped characters properly (7a677bb)

1.0.2 (2018-07-24)

Bug Fixes

  • incorrect package main and types (3000afc)
  • unable to import TypescriptStrategy type (8d2e3e9)

Features

  • initial release with typescript strategy (a4ecdef)