JSPM

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

Find all require() calls. Fast and solid implementation backed with direct scanner and esprima AST parser

Package Exports

  • find-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 (find-requires) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

find-requires - Find all require() calls.

Made for modules-webmake. Fast and solid implementation of require calls parser. Plain cases are worked out by straightforward code walker, rest of the job is done by fastest in the field esprima AST parser.

Example

foo.js:

var one = require('one');
var two = require('two');
var slp = require('some/long' +
                        '/path');
var wrong = require(cannotTakeThat);

program.js:

var fs = require('fs');
var findRequires = require('find-requires')

var src = fs.readFileSync('foo.js', 'utf-8');

console.log(findRequires(src)); // => ['one', 'two', 'some/long/path'];

// or we can get more detailed data with `raw` option:
console.log(findRequires(src, { raw: true })); /* => [
    { value: 'one', raw: '\'one\'', point: 19, line: 1, column: 19 },
    { value: 'two', raw: '\'two\'', point: 45, line: 2, column: 19 },
    { value: 'some/long/path', raw: '\'some/long\' +\n\t\t\t\t\t\t\'/path\'',
        point: 71, line: 3, column: 19  },
    { raw: 'cannotTakeThat', point: 121, line: 5, column: 21 }
] */

Tests Build Status

Before running tests make sure you've installed project with dev dependencies npm install --dev

$ npm test