Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

match-requires

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-requires - npm Package Compare versions

Comparing version
0.3.0
to
1.0.0
+6
-8
index.js
/*!
* match-requires <https://github.com/jonschlinkert/match-requires>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License

@@ -12,5 +12,3 @@ */

module.exports = function (str, stripComments) {
str = str.replace(/\r/g, '');
module.exports = function matchRequires(str, stripComments) {
if (stripComments === true) {

@@ -25,6 +23,6 @@ var strip = require('strip-comments');

var lines = str.split(/\n/g);
var lines = str.split('\n');
var len = lines.length;
var i = 0;
var arr = [];
var res = [];
var match;

@@ -35,3 +33,3 @@

if (match = regex().exec(line)) {
arr = arr.concat({
res.push({
line: i,

@@ -45,3 +43,3 @@ variable: match[2] || '',

return arr;
return res;
};
{
"name": "match-requires",
"description": "Match require statements in a string. Returns an array of matching require statements. Each match is an object with line number, variable name, and module name. Statements in code comments are ignored.",
"version": "0.3.0",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/match-requires",

@@ -17,8 +17,6 @@ "author": {

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/match-requires/blob/master/LICENSE-MIT"
}
],
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/match-requires/blob/master/LICENSE-MIT"
},
"main": "index.js",

@@ -28,2 +26,3 @@ "engines": {

},
"files": ["index.js"],
"scripts": {

@@ -37,2 +36,6 @@ "test": "mocha -R spec"

"devDependencies": {
"benchmarked": "^0.1.3",
"chalk": "^0.5.1",
"crequire": "^1.5.3",
"detective": "^4.0.0",
"mocha": "*",

@@ -39,0 +42,0 @@ "should": "^4.0.4"

+56
-11

@@ -5,15 +5,14 @@ # match-requires [![NPM version](https://badge.fury.io/js/match-requires.svg)](http://badge.fury.io/js/match-requires)

## Install
### Install with [npm](npmjs.org):
- [benchmarks](#benchmarks)
- [usage](#usage)
- [tests](#tests)
```bash
npm i match-requires --save-dev
```
## Run tests
## Install with [npm](npmjs.org)
```bash
npm test
npm i match-requires --save
```
## Usage

@@ -56,3 +55,3 @@

You may also pass a custom function for stripping code comments.
You may also pass a custom function for stripping code comments and/or quoted strings.

@@ -62,6 +61,52 @@ ```js

re(str, function(content) {
return content.replace(/foo/, '');
return require('my-own-comment-stripper')(content);
});
```
## Benchmarks
See the [generated output](https://gist.github.com/jonschlinkert/ed359fe882a5973ee86e) that each lib produces for each benchmark.
```bash
#1: after-return.js
crequire.js x 153,480 ops/sec ±0.71% (97 runs sampled)
detective.js x 55,015 ops/sec ±1.04% (91 runs sampled)
match-requires.js x 2,439,019 ops/sec ±0.77% (98 runs sampled)
#2: basic.js
crequire.js x 391,131 ops/sec ±0.63% (96 runs sampled)
detective.js x 102,594 ops/sec ±0.84% (99 runs sampled)
match-requires.js x 2,674,151 ops/sec ±0.83% (94 runs sampled)
#3: do-while.js
crequire.js x 102,220 ops/sec ±0.93% (96 runs sampled)
detective.js x 41,635 ops/sec ±0.81% (97 runs sampled)
match-requires.js x 1,535,496 ops/sec ±0.59% (99 runs sampled)
#4: if-statement.js
crequire.js x 121,816 ops/sec ±0.82% (93 runs sampled)
detective.js x 43,148 ops/sec ±1.02% (96 runs sampled)
match-requires.js x 1,750,488 ops/sec ±0.72% (98 runs sampled)
#5: in-method.js
crequire.js x 268,212 ops/sec ±0.64% (97 runs sampled)
detective.js x 55,454 ops/sec ±0.98% (96 runs sampled)
match-requires.js x 2,567,571 ops/sec ±0.77% (95 runs sampled)
#6: multiple.js
crequire.js x 70,591 ops/sec ±0.54% (96 runs sampled)
detective.js x 21,315 ops/sec ±0.96% (98 runs sampled)
match-requires.js x 893,286 ops/sec ±0.77% (96 runs sampled)
```
## Run tests
Install dev dependencies:
```bash
npm i -d && npm test
```
## Author

@@ -75,3 +120,3 @@

## License
Copyright (c) 2014 Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license

@@ -81,2 +126,2 @@

_This file was generated by [verb](https://github.com/assemble/verb) on November 23, 2014._
_This file was generated by [verb](https://github.com/assemble/verb) on January 22, 2015._
# Enforce Unix newlines
*.* text eol=lf
*.css text eol=lf
*.html text eol=lf
*.js text eol=lf
*.json text eol=lf
*.less text eol=lf
*.md text eol=lf
*.yml text eol=lf
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary
{
"esnext": true,
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"unused": true,
"globals": {
"define": true,
"before": true,
"after": true,
"describe": true,
"it": true
}
}

Sorry, the diff of this file is not supported yet

language: node_js
node_js:
- '0.10'
# {%= name %} {%= badge("fury") %}
> {%= description %}
## Install
{%= include("install") %}
## Run tests
```bash
npm test
```
## Usage
```js
var re = require('{%= name %}');
console.log(re('require(\'a-b-c\');\nvar fooBar = require(\'foo-bar\');'))
```
Returns:
```js
[ { line: 1,
variable: '',
module: 'a-b-c',
original: 'require(\'a-b-c\');' },
{ line: 2,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');' } ]
```
### Code comments
To ignore require statements found in code comments, pass `true` as the second arg:
```js
re('/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');');
```
Returns:
```js
[ { line: 2,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');' } ]
```
You may also pass a custom function for stripping code comments.
```js
var str = '/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');';
re(str, function(content) {
return content.replace(/foo/, '');
});
```
## Author
{%= include("author") %}
## License
{%= copyright() %}
{%= license() %}
***
{%= include("footer") %}

Sorry, the diff of this file is not supported yet

/*!
* match-requires <https://github.com/jonschlinkert/match-requires>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/
'use strict';
var should = require('should');
var req = require('./');
describe('matchRequires', function () {
it('should return an array of matching require statements:', function () {
var actual = req('require(\'a-b-c\');\nvar fooBar = require(\'foo-bar\');');
actual.should.eql([{
line: 1,
variable: '',
module: 'a-b-c',
original: 'require(\'a-b-c\');'
},
{
line: 2,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');'
}]);
});
it('should ignore statements in code comments:', function () {
var actual = req('/*require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');', true);
actual.should.eql([{
line: 1,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');'
}]);
});
it('should parse require statements in methods:', function () {
var actual = req('this.helper(\'copyright\', require(\'helper-copyright\'))');
actual.should.eql([{
line: 1,
variable: '',
module: 'helper-copyright',
original: 'this.helper(\'copyright\', require(\'helper-copyright\'))'
}]);
});
});