Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

strip-comments

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strip-comments - npm Package Compare versions

Comparing version 0.3.2 to 0.3.4

.verb.md

26

bower.json
{
"name": "strip-comments",
"version": "0.3.1",
"description": "Strip comments from code. Removes both line comments and/or block comments, with options to leave protected comments unharmed.",
"repository": "jonschlinkert/strip-comments",
"license": "MIT",
"homepage": "https://github.com/jonschlinkert/strip-comments",
"authors": [
"Jon Schlinkert (https://github.com/jonschlinkert)"
],
"main": [
"index.js"
],
"devDependencies": {
"mocha": "*",
"should": "*"
},
"keywords": [
"block",
"comment",
"comments",
"expressions",
"line",
"protected",
"re",
"regex",
"regexp",
"regular",
"remove",
"strip"
]
}

31

index.js
/*!
* strip-comments <https://github.com/jonschlinkert/strip-comments>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Copyright (c) 2014-2015 Jon Schlinkert.
* Licensed under the MIT license.
*/
'use stric';
'use strict';
var reBlock = '\\/\\*';
var reBlockIgnore = '\\/\\*(?!\\*?\\!)';
var reBlockEnd = '(.|[\\r\\n]|\\n)*?\\*\\/\\n?\\n?';
var reBlock = /\/\*(?!\/)(.|[\r\n]|\n)+?\*\/\n?\n?/gm;
var reBlockIgnore = /\/\*(?!(\*?\/|\*?\!))(.|[\r\n]|\n)+?\*\/\n?\n?/gm;
var reLine = /(^|[^\S\n])(?:\/\/)([\s\S]+?)$/gm;
var reLineIgnore = /(^|[^\S\n])(?:\/\/[^!])([\s\S]+?)$/gm;
/**
* Strip all comments
*
* {%= docs("strip") %}
*
* @param {String} `str` file contents or string to strip.

@@ -28,7 +24,6 @@ * @param {Object} `opts` options are passed to `.block`, and `.line`

var strip = module.exports = function(str, opts) {
function strip(str, opts) {
return str ? strip.block(strip.line(str, opts), opts) : '';
};
}
/**

@@ -38,4 +33,2 @@ * Strip only block comments, optionally leaving protected comments

*
* {%= docs("block") %}
*
* @param {String} `str` file content or string to strip to

@@ -49,5 +42,5 @@ * @param {Object} `opts` if `safe:true`, strip only comments that do not start with `/*!` or `/**!`

opts = opts || {};
var re = new RegExp(reBlock + reBlockEnd, 'gm');
var re = reBlock; //new RegExp(reBlock + reBlockEnd, 'gm');
if(opts.safe) {
re = new RegExp(reBlockIgnore + reBlockEnd, 'gm');
re = reBlockIgnore; //new RegExp(reBlockIgnore + reBlockEnd, 'gm');
}

@@ -61,4 +54,2 @@ return str ? str.replace(re, '') : '';

*
* {%= docs("line") %}
*
* @param {String} `str` file content or string to strip to

@@ -78,1 +69,7 @@ * @param {Object} `opts` if `safe:true`, strip all that not starts with `//!`

};
/**
* Expose `strip`
*/
module.exports = strip;
{
"name": "strip-comments",
"description": "Strip comments from code. Removes both line comments and/or block comments, with options to leave protected comments unharmed.",
"version": "0.3.2",
"version": "0.3.4",
"homepage": "https://github.com/jonschlinkert/strip-comments",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "git://github.com/jonschlinkert/strip-comments.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/strip-comments",
"bugs": {
"url": "https://github.com/jonschlinkert/strip-comments/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/strip-comments/blob/master/LICENSE-MIT"
}
],
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
"test": "mocha"
},
"engines": {
"node": ">=0.10.0"
},
"devDependencies": {
"mocha": "*",
"should": "^4.0.4",
"verb": "^0.2.15",
"verb-tag-jscomments": "^0.2.2"
"should": "*"
},

@@ -47,5 +37,13 @@ "keywords": [

],
"engines": {
"node": ">=0.10.0"
"verb": {
"related": {
"list": [
"esprima-extract-comments",
"extract-comments",
"js-comments",
"parse-comments",
"parse-code-context"
]
}
}
}

@@ -1,17 +0,11 @@

# strip-comments [![NPM version](https://badge.fury.io/js/strip-comments.svg)](http://badge.fury.io/js/strip-comments)
# strip-comments [![NPM version](https://badge.fury.io/js/strip-comments.svg)](http://badge.fury.io/js/strip-comments) [![Build Status](https://travis-ci.org/jonschlinkert/strip-comments.svg)](https://travis-ci.org/jonschlinkert/strip-comments)
> Strip comments from code. Removes both line comments and/or block comments, with options to leave protected comments unharmed.
## Install
#### Install with [npm](npmjs.org):
```bash
npm i strip-comments --save-dev
```
Install with [npm](https://www.npmjs.com/)
## Run tests
```bash
npm test
```sh
$ npm i strip-comments --save
```

@@ -28,12 +22,15 @@

## API
### [strip](index.js#L28)
### [strip](index.js#L24)
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.
**Params**
**Example:**
* `str` **{String}**: file contents or string to strip.
* `opts` **{Object}**: options are passed to `.block`, and `.line`
* `returns` **{String}**: String without comments.
**Example**
```js

@@ -44,12 +41,14 @@ console.log(strip("foo // this is a comment\n/* me too */"));

### [.block](index.js#L38)
### [.block](index.js#L45)
Strip only block comments, optionally leaving protected comments
(e.g. `/*!`) intact.
Strip only block comments, optionally leaving protected comments (e.g. `/*!`) intact.
**Params**
* `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.
* `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:**
**Example**

@@ -61,13 +60,14 @@ ```js

### [.line](index.js#L57)
### [.line](index.js#L66)
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.
**Params**
**Example:**
* `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**
```js

@@ -78,17 +78,36 @@ console.log(strip("foo /* me too */"));

## Related projects
* [esprima-extract-comments](https://www.npmjs.com/package/esprima-extract-comments): Extract code comments from string or from a glob of files using esprima. | [homepage](https://github.com/jonschlinkert/esprima-extract-comments)
* [extract-comments](https://www.npmjs.com/package/extract-comments): Extract code comments from string or from a glob of files. | [homepage](https://github.com/jonschlinkert/extract-comments)
* [js-comments](https://www.npmjs.com/package/js-comments): Parse JavaScript code comments and generate API documentation. | [homepage](https://github.com/jonschlinkert/js-comments)
* [parse-code-context](https://www.npmjs.com/package/parse-code-context): Parse code context in a single line of javascript, for functions, variable declarations, methods, prototype… [more](https://www.npmjs.com/package/parse-code-context) | [homepage](https://github.com/jonschlinkert/parse-code-context)
* [parse-comments](https://www.npmjs.com/package/parse-comments): Parse code comments from JavaScript or any language that uses the same format. | [homepage](https://github.com/jonschlinkert/parse-comments)
## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/strip-comments/issues/new).
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 02, 2014._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 22, 2015._

@@ -20,2 +20,6 @@ 'use strict';

var fun = false;
var fun = false;
var path = '/path/to/*/something/that/not/be/stripped.js';
var globstar = '/path/to/globstar/not/be/stripped/**/*.js';

@@ -28,2 +28,6 @@ /*!

// line comment
var fun = false;
var fun = false;
var path = '/path/to/*/something/that/not/be/stripped.js';
var globstar = '/path/to/globstar/not/be/stripped/**/*.js';

@@ -28,2 +28,5 @@ /**

var but = 'not'; //! that comment
};
};
var path = '/path/to/*/something/that/not/be/stripped.js';
var globstar = '/path/to/globstar/not/be/stripped/**/*.js';

@@ -33,2 +33,4 @@ /*!

// line comment
var fun = false;
var fun = false;
var path = '/path/to/*/something/that/not/be/stripped.js';
var globstar = '/path/to/globstar/not/be/stripped/**/*.js';

@@ -28,2 +28,5 @@ /**

var but = 'not'; //! that comment
};
};
var path = '/path/to/*/something/that/not/be/stripped.js';
var globstar = '/path/to/globstar/not/be/stripped/**/*.js';

@@ -5,2 +5,4 @@ 'use strict';

var strip = require('../index');
require('should');
require('mocha');

@@ -33,2 +35,39 @@ function read(src) {

});
it('should strip all but not `/*/`', function() {
var actual = strip("/* I will be stripped */\nvar path = '/and/this/*/not/be/stripped';")
var expected = "\nvar path = '/and/this/*/not/be/stripped';"
normalize(actual).should.eql(normalize(expected));
})
it('should strip all but not globstars `/**/*` #1', function() {
var actual = strip("var path = './path/to/scripts/**/*.js';")
var expected = "var path = './path/to/scripts/**/*.js';"
normalize(actual).should.eql(normalize(expected));
})
it('should strip all but not globstars `/**/` #2 and `//!` line comments (safe:true)', function() {
var actual = strip("var partPath = './path/*/to/scripts/**/'; //! line comment", {safe:true})
var expected = "var partPath = './path/*/to/scripts/**/'; //! line comment"
normalize(actual).should.eql(normalize(expected));
})
it('should strip all but not `/*/*something` from anywhere', function() {
var actual = strip("var partPath = './path/*/*something/test.txt';")
var expected = "var partPath = './path/*/*something/test.txt';"
normalize(actual).should.eql(normalize(expected));
})
it('should strip all but not `/*/*something/*.js` from anywhere (globstar-like)', function() {
var actual = strip("var partPath = './path/*/*something/*.js';")
var expected = "var partPath = './path/*/*something/*.js';"
normalize(actual).should.eql(normalize(expected));
})
it('should leave alone code without any comments', function() {
var fixture = read('test/fixtures/no-comment.js');
var actual = strip(fixture);
var expected = fixture;
actual.should.eql(expected);
})
});

@@ -113,3 +152,20 @@

it('should not strip URLs in a variable.', function () {
var actual = strip.line('var foo = "http://github.com"; // this should be stripped');
var expected = 'var foo = "http://github.com";';
normalize(actual).should.eql(normalize(expected));
});
it('should strip URLs in a line comment.', function () {
var actual = strip.line('// http://github.com"');
var expected = '';
normalize(actual).should.eql(normalize(expected));
});
it('should strip URLs in a block comment.', function () {
var actual = strip.block('/**\n* http://github.com\n *\n */');
var expected = '';
normalize(actual).should.eql(normalize(expected));
});
it('should strip line comments before a function, and not block comments.', function () {

@@ -116,0 +172,0 @@ var actual = strip.line('/* this is a comment */\n//this is a comment\nvar bar = function(/*this is a comment*/) {return;};');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc