What is matchdep?
The matchdep npm package is used to filter dependencies by name patterns. It is particularly useful in build systems like Grunt to dynamically load tasks based on specific patterns.
What are matchdep's main functionalities?
Filter Dependencies by Pattern
This feature allows you to filter dependencies in your package.json that match a specific pattern. In this example, it filters all dependencies that start with 'grunt-'.
const matchdep = require('matchdep');
const matchedDeps = matchdep.filter('grunt-*');
console.log(matchedDeps);
Filter DevDependencies by Pattern
This feature allows you to filter devDependencies in your package.json that match a specific pattern. In this example, it filters all devDependencies that start with 'grunt-'.
const matchdep = require('matchdep');
const matchedDevDeps = matchdep.filterDev('grunt-*');
console.log(matchedDevDeps);
Filter All Dependencies by Pattern
This feature allows you to filter all dependencies (both dependencies and devDependencies) in your package.json that match a specific pattern. In this example, it filters all dependencies that start with 'grunt-'.
const matchdep = require('matchdep');
const matchedAllDeps = matchdep.filterAll('grunt-*');
console.log(matchedAllDeps);
Other packages similar to matchdep
glob
The glob package is used for matching files using the patterns the shell uses, like stars and stuff. While it is more general-purpose and not specifically for filtering dependencies, it can be used to achieve similar results by matching file paths.
multimatch
The multimatch package is a flexible matching library that supports multiple glob patterns. It is more versatile than matchdep as it can be used for a variety of matching tasks beyond just dependencies.
minimatch
The minimatch package is a minimal matching library that works with glob patterns. It is similar to matchdep in that it can be used to match patterns, but it is more lightweight and general-purpose.
matchdep
Use micromatch to filter npm module dependencies by name.
Examples
var matchdep = require('matchdep');
matchdep.filter('mini*');
matchdep.filterDev('grunt-contrib-*', './package.json');
matchdep.filterPeer('foo-{bar,baz}', './some-other.json');
matchdep.filterAll('*', require('./yet-another.json'));
matchdep.filterAll(['*','!grunt']);
Usage
filter(pattern, config)
filterDev(pattern, config)
filterPeer(pattern, config)
filterAll(pattern, config)
pattern
Type: String|Array
Default: 'none'
A micromatch compatible match pattern to filter dependencies.
config
Type: String
or Object
Default: Path to nearest package.json.
If config is a string, matchdep will attempt to require it. If it is an object, it will be used directly.
Release History
- 2017-08-18 - v2.0.0 - Upgrade major versions of dependencies, Upgrade devDeps
- 2016-02-09 - v1.0.1 - switch to micromatch, remove globule
- 2015-09-27 - v1.0.0 - throw when no package.json found, update dependencies, remove node 0.8 support
- 2013-10-09 - v0.3.0 - support multiple pattern matches using globule
- 2013-10-08 - v0.2.0 - refactor and support filtering peerDependencies
- 2012-11-27 - v0.1.0 - initial release