Strip comments from code. Removes both line comments and/or block comments, with options to leave protected comments unharmed.
Install with npm:
npm i strip-comments --save-dev
npm test
var strip = require('strip-comments');
console.log(strip('Hey! // foo'));
//=> 'Hey !';
Strip all comments
str
{String}: file contents or string to strip.opts
{Object}: options are passed to.block
, and.line
returns
{String}: String without comments.
Example:
console.log(strip("foo // this is a comment\n/* me too */"));
//=> 'foo'
Strip only block comments, optionally leaving protected comments (e.g. /*!
) intact.
str
{String}: file content or string to strip toopts
{Object}: ifsafe:true
, strip only comments that do not start with/*!
or/**!
returns
{String}: String without block comments.
Example:
console.log(strip("foo // this is a comment\n/* me too */"));
//=> 'foo // this is a comment\n'
Strip only line comments
str
{String}: file content or string to strip toopts
{Object}: ifsafe:true
, strip all that not starts with//!
returns
{String}: String without line comments.
Example:
console.log(strip("foo /* me too */"));
//=> 'foo'
Jon Schlinkert
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on September 02, 2014.