Skip to content

Commit

Permalink
add standard
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Dec 23, 2019
1 parent d787e48 commit 3310002
Show file tree
Hide file tree
Showing 5 changed files with 6,815 additions and 69 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# dependants-stream

Get a stream of node modules depending on a given module.
Expand All @@ -8,15 +7,15 @@ Get a stream of node modules depending on a given module.
## Example

```js
var dependants = require('dependants-stream');
var dependants = require('dependants-stream')

dependants('intersect')
.on('data', function(name) {
console.log(name);
.on('data', function (name) {
console.log(name)
})
.on('end', function() {
.on('end', function () {
// ...
});
})
```

## API
Expand All @@ -33,4 +32,4 @@ $ npm install dependants-stream

## License

MIT
MIT
75 changes: 39 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var JSONStream = require('JSONStream');
var http = require('http');
var qs = require('querystring');
var Transform = require('stream').Transform;
var JSONStream = require('JSONStream')
var http = require('http')
var qs = require('querystring')
var Transform = require('stream').Transform

/**
* Expose `dependants`.
*/

module.exports = dependants;
module.exports = dependants

/**
* Get all node modules depending on module `name`.
Expand All @@ -19,40 +19,43 @@ module.exports = dependants;
* @return {Stream}
*/

function dependants(name, opts) {
opts = opts || {};
function dependants (name, opts) {
opts = opts || {}

var registry = opts.registry || 'http://registry.npmjs.org';
var registry = opts.registry || 'http://registry.npmjs.org'
var query = qs.stringify({
group_level: 2,
startkey: '["' + name + '"]',
endkey: '["' + name + '",{}]'
});
var url = registry + '/-/_view/dependedUpon?' + query;

var out = Transform({ objectMode: true });
out._transform = function(row, _, done) {
done(null, row.key[1]);
};
out.destroy = function() {
req.abort();
parse.destroy();
process.nextTick(function() {
out.emit('close');
});
};

var req = http.get(url, function(res) {
if (res.statusCode != 200) {
return parse.emit('error', new Error('bad status: ' + res.status));
}

res.pipe(parse);
}).on('error', out.emit.bind(out, 'error'));

var parse = JSONStream.parse(['rows', true])
.on('error', out.emit.bind(out, 'error'));

return parse.pipe(out);
}
})
var url = registry + '/-/_view/dependedUpon?' + query

var out = Transform({ objectMode: true })
out._transform = function (row, _, done) {
done(null, row.key[1])
}
out.destroy = function () {
req.abort()
parse.destroy()
process.nextTick(function () {
out.emit('close')
})
}

var req = http
.get(url, function (res) {
if (res.statusCode !== 200) {
return parse.emit('error', new Error('bad status: ' + res.status))
}

res.pipe(parse)
})
.on('error', out.emit.bind(out, 'error'))

var parse = JSONStream.parse(['rows', true]).on(
'error',
out.emit.bind(out, 'error')
)

return parse.pipe(out)
}
Loading

0 comments on commit 3310002

Please sign in to comment.