New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

licenses

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

licenses - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

registry.js

56

github.js

@@ -59,7 +59,6 @@ 'use strict';

this.exists(data, function exists(err, url) {
if (err || !url) return next(err);
this.exists(data, function exists(err, github) {
if (err || !github) return next(err);
var github = parser.repo(url)
, license;
var license;

@@ -100,21 +99,2 @@ parser.root(github, function root(err, files) {

/**
* Get the repository information from the given URL.
*
* @param {String} github The full URL to the github repository.
* @returns {Object}
* @api private
*/
repo: function repo(github) {
if (!github) return {};
var parsed = url.parse(github)
, parts = parsed.pathname.split('/');
return {
user: parts[1],
repo: parts[2]
};
},
/**
* Get the raw data from github.

@@ -168,3 +148,14 @@ *

files = files.filter(function filter(file) {
return !!~parser.filenames.indexOf(file.name.toLowerCase()) && file.size > 0;
var name = file.name.toLowerCase();
// No size, not really useful for matching.
if (file.size <= 0) return false;
// Fast case, direct match.
if (!!~parser.filenames.indexOf(name)) return true;
// Slow case, partial match.
return parser.filenames.some(function some(filename) {
return !!~name.indexOf(filename);
});
});

@@ -192,4 +183,4 @@

*/
exists: function exists(url, next) {
var github = this.repo(url);
exists: function exists(github, next) {
var parser = this;

@@ -201,3 +192,4 @@ this.request({

if (err) return next(err);
next(undefined, res.request.href || url);
next(undefined, parser.get(res.request.href) || github);
});

@@ -225,11 +217,3 @@ },

*/
get: function get(data) {
return (this.url(data.repository, 'github')
|| this.url(data.issues, 'github')
|| this.url(data, 'github')
|| ''
).replace('git://github.com', 'https://github.com')
.replace('git@github.com:', 'https://github.com/')
.replace('.git', '');
}
get: require('extract-github')
});

@@ -22,3 +22,3 @@ 'use strict';

options.registry = options.registry || 'http://registry.nodejitsu.com';
options.order = options.order || ['npm', 'content', 'github'];
options.order = options.order || ['registry', 'content', 'github'];

@@ -100,14 +100,17 @@ async.waterfall([

//
// Expose our primary parsers that we can leverage to retrieve license content.
// Expose the Parser class so we easily add new parsers through third-party if
// needed. (Think bitbucket and other code hosting sites)
//
parse.parsers = {};
parse.parsers.content = new(require('./content'))(parse.parsers);
parse.parsers.github = new(require('./github'))(parse.parsers);
parse.parsers.npm = new(require('./npm'))(parse.parsers);
parse.Registry = require('./registry'); // Parse license out of package
parse.Content = require('./content'); // Parse license of out file content.
parse.Parser = require('./Parser'); // Base parser class.
parse.Github = require('./github'); // Parse license info from github.
//
// Expose the Parser class so we easily add new parsers through third-party if
// needed. (Think bitbucket and other code hosting sites)
// Expose our primary parsers that we can leverage to retrieve license content.
//
parse.Parser = require('./Parser');
parse.parsers = {};
parse.parsers.registry = new parse.Registry(parse.parsers);
parse.parsers.content = new parse.Content(parse.parsers);
parse.parsers.github = new parse.Github(parse.parsers);

@@ -114,0 +117,0 @@ //

{
"name": "licenses",
"version": "0.0.3",
"version": "0.0.4",
"description": "A small tool that detects licensing information for a given Node.js module",

@@ -11,3 +11,7 @@ "main": "index.js",

"licenses",
"license"
"licensing",
"license",
"legal",
"MIT",
"Open Source"
],

@@ -17,6 +21,7 @@ "author": "Arnout Kazemier",

"dependencies": {
"async": "0.2.x",
"debug": "0.7.x",
"extract-github": "0.0.x",
"fusing": "0.0.x",
"async": "0.2.x",
"request": "2.33.x",
"debug": "0.7.x"
"request": "2.33.x"
},

@@ -27,4 +32,4 @@ "devDependencies": {

"pre-commit": "0.0.x",
"argh": "~0.1.1"
"argh": "0.1.x"
}
}

@@ -93,2 +93,5 @@ 'use strict';

return license;
}).filter(function duplicate(item, index, all) {
if (!item) return false;
return all.indexOf(item) === index;
});

@@ -104,14 +107,4 @@ });

*/
Parser.readable('url', function url(data, contains) {
if (!data) return undefined;
Parser.readable('url', require('extract-github').url);
if ('string' === typeof data && ~data.indexOf(contains)) return data;
if ('object' === typeof data) {
if ('url' in data) return url(data.url, contains);
if ('web' in data) return url(data.web, contains);
}
return undefined;
});
/**

@@ -118,0 +111,0 @@ * Check for potential dual licensing in the given license arrays. Most people

@@ -28,5 +28,13 @@ # Licenses

However, this module isn't flawless as it tries to automate a task that usually
requires the interference and intelligence of a human. If you have module that
is incorrectly detected or not detected at all but does have licensing
information publicly available please create an issue about and we'll see if it
can get resolved.
<!-- many thanks stranger <script>alert('thanks')</script> -->
## Installation
The module is released through npm:
The module is released through npm and can therefor be installed using:

@@ -33,0 +41,0 @@ ```

@@ -13,4 +13,4 @@ 'use strict';

licensing('npm', { order: ['github', 'content'] }, function () {
licensing('primus', { order: ['github', 'content' ] }, function (err) {
console.log('license:', arguments);
});

@@ -58,3 +58,6 @@ 'use strict';

licenses(name, function detected(err, licenses, using) {
licenses(name, {
order: argh.order ? argh.order.split(',') : ['npm', 'content', 'github'],
registry: argh.registry
}, function detected(err, licenses, using) {
if (err) return next(err);

@@ -61,0 +64,0 @@

@@ -51,2 +51,60 @@ describe('Parser', function () {

});
describe('#url', function () {
it('detects urls in strings', function () {
expect(parser.url('http://github.com', 'github.com')).to.equal('http://github.com');
expect(parser.url('http://google.com', 'github.com')).to.equal(undefined);
});
it('looks for url properties', function () {
expect(parser.url({
url: 'http://github.com'
}, 'github.com')).to.equal('http://github.com');
expect(parser.url({ foo: 'github.com' }, 'github.com')).to.equal(undefined);
});
it('looks for web properties', function () {
expect(parser.url({
web: 'http://github.com'
}, 'github.com')).to.equal('http://github.com');
expect(parser.url({ foo: 'github.com' }, 'github.com')).to.equal(undefined);
});
it('ignores other types', function () {
parser.url([], 'github');
parser.url(function () {}, 'github');
parser.url(1, 'github');
});
});
describe('#tokenizer', function () {
it('it transforms it all to lowercase', function () {
expect(parser.tokenizer('foObAr')).to.equal('foobar');
expect(parser.tokenizer('h3lL0W0rlD')).to.equal('h3ll0w0rld');
});
it('removes all non chars', function () {
expect(parser.tokenizer('hello world')).to.equal('helloworld');
expect(parser.tokenizer('hello world.')).to.equal('helloworld');
expect(parser.tokenizer('hello,world/')).to.equal('helloworld');
expect(parser.tokenizer('hello,world')).to.equal('helloworld');
});
it('concats it all in to one line', function () {
expect(parser.tokenizer('hello\nworld')).to.equal('helloworld');
expect(parser.tokenizer('hello\r\nworld')).to.equal('helloworld');
expect(parser.tokenizer('hello\rworld')).to.equal('helloworld');
});
it('combines it in to arrays of concatinated words', function () {
expect(parser.tokenizer('hello WORLD', 2)).to.deep.equal([
'helloworld'
]);
expect(parser.tokenizer('hello WORLD', 1)).to.deep.equal([
'hello',
'world'
]);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc