Skip to content

Strip block comments or line comments from code. The tests remove comments from JavaScript, but this will work with any language that uses the same syntax for comments.

License

Notifications You must be signed in to change notification settings

kgryte/strip-comments

 
 

Repository files navigation

strip-comments NPM version

Strip comments from code. Removes both line comments and/or block comments, with options to leave protected comments unharmed.

Install

Install with npm:

npm i strip-comments --save-dev

Run tests

npm test

Usage

var strip = require('strip-comments');
console.log(strip('Hey! // foo'));
//=> 'Hey !';

API

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 to
  • opts {Object}: if safe: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 to
  • opts {Object}: if safe:true, strip all that not starts with //!
  • returns {String}: String without line comments.

Example:

console.log(strip("foo /* me too */"));
//=> 'foo'

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on September 02, 2014.

About

Strip block comments or line comments from code. The tests remove comments from JavaScript, but this will work with any language that uses the same syntax for comments.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%