npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

module-calls

v1.0.0

Published

Find all places a node module is used in a string of code

Downloads

17

Readme

module-calls

Find all places a node module is used in a string of code.

build status

testling badge

Example

Print usage info for the node modules this modules depends on:

var fs = require('fs');
var calls = require('module-calls');

var source = fs.readFileSync(__dirname + '/index.js', 'utf8');

console.log('Usage of `astw`:');
console.log(calls('astw', source));
console.log();

console.log('Usage of `escodegen`:');
console.log(calls('escodegen', source));
console.log();

console.log('Usage of `debug`:');
console.log(calls('debug', source));

The output is:

$ node example.js
Usage of `astw`:
[ { code: 'var astw = require(\'astw\');' },
  { code: 'var walk = astw(code);' } ]

Usage of `escodegen`:
[ { code: 'var codegen = require(\'escodegen\').generate;' },
  { code: '\'var \' + codegen(node.parent)' },
  { code: '\'var \' + codegen(node.parent.parent)' },
  { code: 'codegen(node.parent.parent) + \';\'' },
  { code: 'codegen(node.parent) + \';\'' },
  { code: '\'var \' + codegen(node.parent.parent)' },
  { code: 'codegen(node.parent.parent) + \';\'' },
  { code: 'var code = codegen(node.parent.parent);' },
  { code: 'var code = codegen(node.parent);' },
  { code: '\'var \' + codegen(node.parent)' },
  { code: 'codegen(node.parent) + \';\'' },
  { code: 'var code = codegen(node.parent);' } ]

Usage of `debug`:
[ { code: 'var debug = require(\'debug\')(\'module-calls\');' },
  { code: 'debug(\'declaration require: %s\', code);' },
  { code: 'debug(\'require member declaration: %s\', code);' },
  { code: 'debug(\'require member assignment: %s\', code);' },
  { code: 'debug(\'assignemt require: %s\', code);' },
  { code: 'debug(\'require call declaration: %s\', code);' },
  { code: 'debug(\'require call assignment: %s\', code);' },
  { code: 'debug(\'require call: %s\', code);' },
  { code: 'debug(\'require: %s\', code);' },
  { code: 'debug(\'declaration: %s\', code);' },
  { code: 'debug(\'assignment: %s\', code);' },
  { code: 'debug(\'call: %s\', code);' } ]

This still needs improvement, e.g. here calls to walk should be tracked too.

API

calls(name, source)

Find all places module name is used in source.

Returns an array of objects with keys

  • code: The code as string
  • node: The ast node, generated by esprima

Installation

$ npm install module-calls

License

MIT