Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
Created January 20, 2013 21:50
Show Gist options
  • Save tgvashworth/4582024 to your computer and use it in GitHub Desktop.
Save tgvashworth/4582024 to your computer and use it in GitHub Desktop.
nick cdnjs
var https = require('https');
var find_by = function (key, search, array) {
var matches = [];
array.some(function (item) {
if( item[key] ) {
if( (''+item[key]).toLowerCase().indexOf(search) !== -1 ) {
matches.push(item);
}
}
});
return matches;
};
var find_by_name = find_by.bind(null, 'name');
var find_by_filename = find_by.bind(null, 'filename');
var find_by_description = find_by.bind(null, 'description');
var process = function (raw) {
var packages = JSON.parse(raw);
console.log( find_by_name('require', packages.packages) );
console.log( find_by_filename('jquery', packages.packages) );
console.log( find_by_description('raphael', packages.packages) );
};
https.get('https://raw.github.com/cdnjs/website/gh-pages/packages.json', function (res) {
var file = '';
res.on('data', function (data) {
file += data;
});
res.on('end', function (data) {
if( data ) file += data;
process(file);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment