You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@literals/parser

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@literals/parser

Parse template literals from code

2.0.1
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

parse-literals

Because sometimes you literally need to parse template literals.

npm

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

[!IMPORTANT]
All @literals/* packages are published as ESM-only!

import * as pl from '@literals/parser';

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

Keywords

parse

FAQs

Package last updated on 17 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts