JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 391
  • Score
    100M100P100Q89057F
  • License MIT

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.

Package Exports

  • match-requires

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (match-requires) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

match-requires NPM version NPM monthly downloads NPM total downloads Linux Build Status

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.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save match-requires

Usage

const matches = require('match-requires');
console.log(matches('require(\'a-b-c\');\nvar fooBar = require(\'foo-bar\');'));

Returns:

[ { string: 'require(\'a-b-c\');', 
    variable: '', 
    name: 'a-b-c' },
  { string: 'var fooBar = require(\'foo-bar\');',
    variable: 'fooBar',
    name: 'foo-bar' } ]

Ignore requires in code comments

To ignore require() statements found inside code comments, pass true as the second argument to strip comments before matching. Alternatively, you may pass a function as the second argument to use your own approach to stripping comments.

Without comments stripped

console.log(matches('/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');')); 
// [ { string: 'require(\'a-b-c\');', variable: '', name: 'a-b-c' },
//   { string: 'var fooBar = require(\'foo-bar\');',
//     variable: 'fooBar',
//     name: 'foo-bar' } ]

With comments stripped

console.log(matches('/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');', true));
// [ { string: 'var fooBar = require(\'foo-bar\');',
//     variable: 'fooBar',
//     name: 'foo-bar' } ]

With custom function

const str = '/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');';
const fn = require('some-comment-stripping-library');
console.log(matches(str, fn));
// [ { string: 'var fooBar = require(\'foo-bar\');',
//     variable: 'fooBar',
//     name: 'foo-bar' } ]

About

Contributing

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

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

You might also be interested in these projects:

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on April 15, 2018.