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

andreashuetter/strip-comments

 
 

Repository files navigation

strip-comments NPM version Build Status

Strip comments from code. Removes line comments, block comments, the first comment only, or all comments. Optionally leave protected comments unharmed.

Install

Install with npm

$ npm i strip-comments --save

Usage

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

API

Strip comments from the given string.

Params

  • string {String}
  • options {Object}: Pass safe: true to keep comments with !
  • returns {String}

Example

//example.strip
console.log(strip("foo // this is a comment\n/* me too *\/"));
//=> 'foo'

Strip block comments from the given string.

Params

  • string {String}
  • options {Object}: Pass safe: true to keep comments with !
  • returns {String}

Example

console.log(strip.block("foo // this is a comment\n/* me too */"));
//=> 'foo // this is a comment\n'

Strip line comments from the given string.

Params

  • string {String}
  • options {Object}: Pass safe: true to keep comments with !
  • returns {String}

Example

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

Strip the first comment from the given string.

Params

  • string {String}
  • options {Object}: Pass safe: true to keep comments with !
  • returns {String}

Options

options.preserveNewlines

Preserve newlines after comments are stripped.

Type: boolean

Default: undefined

Example

strip(commentString, { preserveNewlines: true });

Related projects

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb on December 25, 2015.

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%