Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

filter-npm-modules

1.0.0 • Public • Published

filter-npm-modules

stable

Filters a list of require paths down to a list of public and valid npm module names. The result will be sorted and de-duplicated.

var filter = require('filter-npm-modules')
 
var list = [
  'object-assign',
  'url',
  'xtend',
  '_invalid-module-name',
  'this-module-does-not-exist',
  'eases/linear.js',
  'eases/quadratic-in-out.js',
  './foo-bar',
  '../relative/module.js'
]
 
filter(list, function(names) {
  console.log(names)
  // -> ['eases', 'object-assign', 'url', 'xtend']
})

If errors were encountered searching the database, the search will continue but that entry will not be included in the resulting list.

Usage

NPM

filter(paths, [opt], callback)

Filters the list of require paths with the optional settings and provides the resulting sorted list to callback once all async operations are complete (i.e. searching database).

Options:

  • cache - an array of module names to assume exist already in the database

For example, you can use all-the-package-names to avoid queries for common packages.

var cache = require('all-the-package-names')
filter(paths, { cache: cache }, callback)

License

MIT, see LICENSE.md for details.

Install

npm i filter-npm-modules

DownloadsWeekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar