Skip to content

Retrieve accurate license information for a given npm package.

Notifications You must be signed in to change notification settings

givankin/licenses

 
 

Repository files navigation

Licenses

Fork of https://github.com/3rd-Eden/licenses designed to run against pre-fetched node_modules/ instead of fetching info from registry and Github. So you need to do npm install for your main project before using it.

Why fork?

  • This approach required a significant rewrite of the logic.
  • It was not planned by 3rd-eden (see 3rd-Eden#14 (comment)).

As I needed to fetch data for all devDependencies, and there were often hundreds of them, initial code ran too slow for me.

API differences

The main difference is that licenses() accept an object as the first parameter. The object must have 2 properties:

So the call may look like this:

'use strict';

var licenses = require('licenses');

licenses({
  path: 'C:\My Project\node_modules\grunt-contrib-connect\',
  data: {/* package.json contents*/}
}, function fetched(err, license) {
  console.log(license.join(',')); // MIT
});

Or, combined with read-package-tree, like this:

'use strict';

var licenses = require('licenses'),
  readPackageTree = require('read-package-tree');
  
readPackageTree('./node_modules/grunt-contrib-connect', function(err, data) {
  if (err) throw err;
  licences({
    path: data.realpath,
    data: data.package
  }, function fetched(err, license) {
    console.log(license.join(',')); // MIT
  });
});

Getting additional info about licenses

The great thing about the initial licenses module is that it stores a lot of knowledge about existing licenses. To get it, use the static licenses.info() method:

'use strict';

var licenses = require('licenses');

licenses({
  path: 'C:\My Project\node_modules\grunt-contrib-connect\',
  data: {/* package.json contents*/}
}, function fetched(err, license) {
  var info = licenses.info(license[0]/*MIT*/);
  console.log(Object.keys(info)); // id,name,full,url,tldr,file,content
  console.log(info.url); // http://opensource.org/licenses/MIT
});

License

MIT

About

Retrieve accurate license information for a given npm package.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%