A package.json utility for comparing keywords across multiple files.
Install the module with: npm install matchkeys --save
var keys = require('matchkeys');
keys.match(arrayOne, arrayTwo));
var keys = require('matchkeys');
var pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
// => keywords: ['gruntplugin', 'handlebars-helper', 'assemble']
//
var pkgTwo = JSON.parse(fs.readFileSync('package.json', 'utf8'));
// => keywords: ['foo', 'bar', 'assemble']
console.log(keys.match(pkg, pkgTwo));
// => ['assemble']
Match an array of keywords to multiple arrays of keywords returning the package.json
object for each match.
keys.matchPkgs(Array, ArrayofObjects));
Parameters:
Array
: Thepackage.json
containing thekeywords
property to match against.Array
: An array ofpackage.json
files, each containing an array of keywords.
Note that you do not need to specify the keywords
property, just the object containing the keywords property.
Given the following:
var keys = require('matchkeys');
var one = ['apple', 'lime', 'watermelon']
var two = [
{
name: 'citrus',
keywords: ['lemon', 'lime', 'orange']
},
{
name: 'grains',
keywords: ['wheat', 'oats', 'barley']
},
{
name: 'fruit',
keywords: ['apple', 'peach', 'strawberry']
}
];
keys.matchPkgs(one, two));
Returns:
[
{
name: 'citrus',
keywords: ['lemon', 'lime', 'orange']
},
{
name: 'fruit',
keywords: ['apple', 'peach', 'strawberry']
}
]
Same as matchPkgs
but returns true
or false
.
var keys = require('matchkeys');
keys.isMatch(Array, ArrayofObjects));
Parameters:
Array
: The keywords to match against.Array
: Array of objects (package.json
files), each containing an array of keywords.
Using the same example as keys.matchPkgs
, this would return:
[false, false, true]
Returns a list of keywords matching the given minimatch pattern.
var keys = require('matchkeys');
keys.filter('*')
keys.resolve('*')
// specify a different config object besides package.json
keys.resolve('*', config))
Returns the resolved paths to any npm modules that:
- Are listed in the
dependencies
of the project'spackage.json
, and - A keyword is defined matching the name of the module
keys.resolveDev('*')
// specify a different config object besides package.json
keys.resolveDev('*', config))
Returns the resolved paths to any npm modules that:
- Are listed in the
devDependencies
of the project'spackage.json
, and - A keyword is defined matching the name of the module
keys.resolveAll('*')
// specify a different config object besides package.json
keys.resolveAll('*', config))
Returns the resolved paths to any npm modules that:
- Are listed in the
dependencies
ordevDependencies
of the project'spackage.json
, and - A keyword is defined matching the name of the module
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
Jon Schlinkert
Copyright (c) 2013 Jon Schlinkert, contributors. Licensed under the MIT license.