Skip to content
This repository was archived by the owner on Jan 11, 2019. It is now read-only.

Make it work again following the latest npmjs.com UI changes #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
language: "node_js"
node_js: [ "0.10", "0.12", "4", "5" ]
node_js: [ "8" ]
sudo: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Kyle E. Mitchell
Copyright (c) 2016, 2018 Kyle E. Mitchell, Gene Hazan

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
Expand Down
60 changes: 17 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
module.exports = npm1k

var cheerio = require('cheerio')
var concatSeries = require('async.concatseries')
var https = require('https')
var uniq = require('array-uniq')
const requestRetry = require('requestretry').defaults({ json: true, maxAttempts: 3, fullResponse: false })

var offsets = [ ]
function npm1k(callback, limit = 1000) {
process(limit)
.then(names => callback(null, names))
.catch(error => callback(error))
}

for (var i = 0; i <= 1050; i += 36) {
offsets.push(i) }

function npm1k(callback) {
concatSeries(
offsets,
function(offset, callback) {
getMostDependedPage(offset, function(error, html) {
if (error) {
callback(error) }
else {
callback(null, packageNames(html)) } }) },
function(error, packages) {
if (error) {
callback(error) }
else {
callback(null, uniq(packages).slice(0, 1000)) } }) }

function packageNames(html) {
var $ = cheerio.load(html)
return $('a.name')
.map(function() {
return cheerio(this).text() })
.get() }

function getMostDependedPage(offset, callback) {
https.get(
{ hostname: 'www.npmjs.com',
path: '/browse/depended?offset=' + offset },
function(response) {
var buffers = [ ]
response
.on('data', function(buffer) {
buffers.push(buffer) })
.on('error', function(error) {
callback(error) })
.on('end', function() {
callback(null, Buffer.concat(buffers).toString()) }) }) }
async function process(limit) {
let names = []
for (let offset = 0; offset < limit; offset += 36) {
const response = await requestRetry.get(`https://www.npmjs.com/browse/depended?offset=${offset}`, {
headers: { 'x-spiferack': 1 }
})
const namesPage = response.packages.map(pkg => pkg.name)
names = names.concat(namesPage)
}
return names.slice(0, limit)
}
Loading