Socket
Book a DemoInstallSign in
Socket

strip-comment

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strip-comment

Strip js, css, and html comments

latest
Source
npmnpm
Version
1.1.3
Version published
Maintainers
1
Created
Source

strip-comment

Strip js, css, and html comments.

Install

npm install strip-comment --save

test

mocha

demo

<style>
p {
    color: red;
    /* Css line comment */
    text-align: center;
}
/*
 * Css block comment 
 */
</style>
<!-- html comment -->
<p>This is a paragraph.</p>
// html content

<script>
/*
 * Js block comemnt
 */
function displayMsg() {
  // Js line comment
  alert("Hello World!")
}
</script>

var fs = require('fs');
var html = fs.readFileSync('./index.html', { encoding: 'utf8' });
var strip = require('strip-comment');

strip(html);  // Strip js css and html comments.

API

strip(code, keep)

Strip html css and js comments

  • {string} code required
  • {boolean} keep [keep = false]
    Keep the source code lines and columns

.js(code, keep)

Strip js comments

  • {string} code required
  • {boolean} keep [keep = false]
var js = 'var a = 3; // comment'
strip.js(js);
strip.js(js, true);     // keep code lines

.css(code, keep)

Strip css comments

  • {string} code required
  • {boolean} keep [keep = false]
var css = 'h2 { /* comment */ font-size : 18px; }'
strip.css(css);

.html(code, keep)

Strip html comments

  • {string} code required
  • {boolean} keep [keep = false]
var html = '<!-- html comment --><div></div>'
strip.html(html);

Keywords

strip

FAQs

Package last updated on 09 Mar 2015

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