UNPKG

npm-count

Version:

a npm/download-counts wrapper

87 lines (65 loc) 2.34 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: fetchPublications.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: fetchPublications.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>// dependencies import request from 'request'; import Promise from 'bluebird'; import immutable from 'immutable'; // private const requestAsync = Promise.promisify(request); const api = 'https://www.npmjs.com/profile'; /** * fetch the author's publications * * @module fetchPublications * @param &lt;string> author - npm user name * @returns {promise&lt;collection>} author's publications summary * @see https://www.npmjs.com/profile/substack/packages?offset=0 */ export default (author) => ( Promise.all( immutable.Range(0, 11).map((offset) => ( requestAsync(`${api}/${author}/packages?offset=${offset}`, { json: true, gzip: true, }) .then(({ statusCode, body }) => { if (typeof body === 'string') { return Promise.reject(new Error(`${statusCode}: ${body}`)); } return body.items; }) )) ) .then((pages) => pages.reduce((prev, current) => current.concat(prev), [])) ); </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-fetchBulkQuery.html">fetchBulkQuery</a></li><li><a href="module-fetchLastDay.html">fetchLastDay</a></li><li><a href="module-fetchPublications.html">fetchPublications</a></li><li><a href="module-fetchTrending.html">fetchTrending</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 10 2016 02:45:20 GMT+0000 (UTC) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>