tagged-template-literal-comments
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

tagged-template-literal-comments

npm Linux Build Status Windows Build Status Code Coverage

About

Adds comments to tagged template literals.

Features

  • Removes commented out strings and values
  • Supports single line and multiline comments
  • Trims excess whitespace and new lines

Installation

npm install tagged-template-literal-comments

Usage

import { createCommentParser } from 'tagged-template-literal-comments';
 
// defaults to javascript parser
const jsCommentParser = createCommentParser();
 
const jsWithComments = jsCommentParser`
    a    | b    | expected
 
    // test a subset of issues
    ${0} | ${1} | ${1}
 
    // test another subset of issues
    ${1} | ${1} | ${2}
    ${2} | ${2} | ${4} // fix for: https://github.com/facebook/jest/pull/8717
    ${3} | ${3} | ${6} // some random note
 
    // enable later
    // ${1} | ${1} | ${2}
    // ${1} | ${1} | ${2}
`;
 
const jsWithoutComments = `
    a    | b    | expected
    ${0} | ${1} | ${1}
    ${1} | ${1} | ${2}
    ${2} | ${2} | ${4}
    ${3} | ${3} | ${6}
`;
 
// jsWithComments === jsWithoutComments
 
const htmlCommentParser = createCommentParser({ language: 'html' });
 
const htmlWithComments = htmlCommentParser`
    <!-- remove comment -->
    <!--<p>${1}</p>-->
    <p>${2}</p>
`;
 
const htmlWithoutComments = `
    <p>${2}</p>
`;
 
// htmlWithComments === htmlWithoutComments

Options

const parser = createCommentParser({
    /**
     * Comment language parser
     *
     * available: javascript, html, ignore
     * default: 'javascript'
     */
    language: 'javascript',
 
    /**
     * Set single line comment marker
     *
     * disable single line comments by setting to false
     */
    singleLine: '//',
 
    /**
     * Set multiline comment marker
     *
     * disable multiline comments by setting to false
     */
    multiline: { open: '/*', close: '*/' },
 
    /**
     * Throw on invalid syntax
     *
     * default: true
     */
    throwOnSyntaxError: true,
});

Package Sidebar

Install

npm i tagged-template-literal-comments

Weekly Downloads

3

Version

2.0.0

License

MIT

Unpacked Size

78.5 kB

Total Files

26

Last publish

Collaborators

  • chrisblossom