├── .gitattributes
├── .npmrc
├── .gitignore
├── .travis.yml
├── test.js
├── .editorconfig
├── package.json
├── readme.md
├── index.js
└── license
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - '8'
5 | - '6'
6 | - '4'
7 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | import test from 'ava';
2 | import m from '.';
3 |
4 | test('should return object', async t => {
5 | t.is(typeof await m('gillstrom'), 'object');
6 | });
7 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [*.yml]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "dpn",
3 | "version": "3.0.0",
4 | "description": "Get the dependents of a users npm modules",
5 | "license": "MIT",
6 | "repository": "gillstrom/dpn",
7 | "author": {
8 | "name": "Andreas Gillström",
9 | "email": "andreasgillstrom@gmail.com",
10 | "url": "github.com/gillstrom"
11 | },
12 | "engines": {
13 | "node": ">=4"
14 | },
15 | "scripts": {
16 | "test": "xo && ava"
17 | },
18 | "files": [
19 | "index.js"
20 | ],
21 | "keywords": [
22 | "depend",
23 | "dependent",
24 | "dependents",
25 | "get",
26 | "module",
27 | "modules",
28 | "npm",
29 | "use",
30 | "user",
31 | "username",
32 | "users",
33 | "using"
34 | ],
35 | "dependencies": {
36 | "npm-stats": "^1.1.0",
37 | "sort-object": "^3.0.0"
38 | },
39 | "devDependencies": {
40 | "ava": "*",
41 | "xo": "*"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # dpn [](https://travis-ci.org/gillstrom/dpn)
2 |
3 | > Get the dependents of a users npm modules
4 |
5 | ## Install
6 |
7 | ```
8 | $ npm install dpn
9 | ```
10 |
11 |
12 | ## Usage
13 |
14 | ```js
15 | const dpn = require('dpn');
16 |
17 | dpn('gillstrom').then(result => {
18 | console.log(result);
19 | //=> {'app-size': ['osx-app'], 'array-max-length': ['get-arrows'], 'battery-level': ['evac'], ...}
20 | });
21 | ```
22 |
23 |
24 | ## API
25 |
26 | ### dpn(username)
27 |
28 | Returns a promise that resolves to an object.
29 |
30 | #### username
31 |
32 | *Required*
33 | Type: `string`
34 |
35 | The username to look up.
36 |
37 |
38 | ## Related
39 |
40 | * [dpn-cli](https://github.com/gillstrom/dpn-cli) - CLI for this module
41 |
42 |
43 | ## License
44 |
45 | MIT © [Andreas Gillström](https://github.com/gillstrom)
46 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | const npmStats = require('npm-stats');
3 | const sortObject = require('sort-object');
4 |
5 | const getDependents = el => new Promise((resolve, reject) => {
6 | npmStats()
7 | .module(el)
8 | .dependents((err, res) => {
9 | if (err) {
10 | reject(err);
11 | }
12 |
13 | resolve(res);
14 | });
15 | });
16 |
17 | const getPackages = user => new Promise((resolve, reject) => {
18 | npmStats()
19 | .user(user)
20 | .list((err, res) => {
21 | if (err) {
22 | reject(err);
23 | }
24 |
25 | resolve(res);
26 | });
27 | });
28 |
29 | module.exports = user => {
30 | const ret = {};
31 |
32 | if (!user) {
33 | return Promise.reject(new Error('You have to provide a user'));
34 | }
35 |
36 | return getPackages(user)
37 | .then(data => Promise.all(data.map(el => getDependents(el).then(res => {
38 | if (res.length === 0) {
39 | return;
40 | }
41 |
42 | ret[el] = res;
43 | })))
44 | .then(() => sortObject(ret)));
45 | };
46 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Andreas Gillström (github.com/gillstrom)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------