├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.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 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const got = require('got'); 3 | 4 | module.exports = username => { 5 | if (typeof username !== 'string') { 6 | return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof username}\``)); 7 | } 8 | 9 | const size = 250; 10 | let offset = 0; 11 | let ret = []; 12 | 13 | return (function loop() { 14 | const url = `https://api.npms.io/v2/search?q=maintainer:${username}&size=${size}&from=${offset}`; 15 | 16 | return got(url, {json: true}).then(res => { 17 | ret = ret.concat(res.body.results.map(x => x.package)); 18 | 19 | if (res.body.total > offset) { 20 | offset += size - 1; 21 | return loop(); 22 | } 23 | 24 | return ret; 25 | }); 26 | })(); 27 | }; 28 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Kevin Mårtensson (github.com/kevva) 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-user-packages", 3 | "version": "3.0.0", 4 | "description": "Get packages by a npm user", 5 | "license": "MIT", 6 | "repository": "kevva/npm-user-packages", 7 | "author": { 8 | "name": "Kevin Martensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "api", 23 | "homepage", 24 | "npm", 25 | "packages", 26 | "user", 27 | "version" 28 | ], 29 | "dependencies": { 30 | "got": "^7.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "*", 34 | "xo": "*" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # npm-user-packages [![Build Status](https://travis-ci.org/kevva/npm-user-packages.svg?branch=master)](https://travis-ci.org/kevva/npm-user-packages) 2 | 3 | > Get packages by a npm user 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install npm-user-packages 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const npmUserPackages = require('npm-user-packages'); 17 | 18 | npmUserPackages('kevva').then(data => { 19 | console.log(data); 20 | //=> [{name: 'advpng-bin', description: '...', ...}, ...] 21 | }); 22 | ``` 23 | 24 | 25 | ## API 26 | 27 | ### npmUserPackages(username) 28 | 29 | #### username 30 | 31 | Type: `string` 32 | 33 | User to fetch packages from. 34 | 35 | 36 | ## Related 37 | 38 | * [npm-user-packages-cli](https://github.com/kevva/npm-user-packages-cli) - CLI for this module 39 | * [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of a npm user 40 | * [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of a npm user 41 | * [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword 42 | 43 | 44 | ## License 45 | 46 | MIT © [Kevin Mårtensson](https://github.com/kevva) 47 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from '.'; 3 | 4 | test(async t => { 5 | const [pkg, ...pkgs] = await m('kevva'); 6 | t.true(pkgs.length > 100); 7 | t.truthy(pkg.name); 8 | t.truthy(pkg.description); 9 | }); 10 | --------------------------------------------------------------------------------