npm-registry-fetch
Advanced tools
Comparing version 3.6.0 to 3.7.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="3.7.0"></a> | ||
# [3.7.0](https://github.com/npm/registry-fetch/compare/v3.6.0...v3.7.0) (2018-08-23) | ||
### Features | ||
* **json.stream:** add utility function for streamed JSON parsing ([051d969](https://github.com/npm/registry-fetch/commit/051d969)) | ||
<a name="3.6.0"></a> | ||
@@ -7,0 +17,0 @@ # [3.6.0](https://github.com/npm/registry-fetch/compare/v3.5.0...v3.6.0) (2018-08-22) |
14
index.js
@@ -9,3 +9,5 @@ 'use strict' | ||
const fetch = require('make-fetch-happen') | ||
const JSONStream = require('JSONStream') | ||
const npa = require('npm-package-arg') | ||
const {PassThrough} = require('stream') | ||
const qs = require('querystring') | ||
@@ -114,2 +116,14 @@ const url = require('url') | ||
module.exports.json.stream = fetchJSONStream | ||
function fetchJSONStream (uri, jsonPath, opts) { | ||
const parser = JSONStream.parse(jsonPath) | ||
const pt = parser.pipe(new PassThrough({objectMode: true})) | ||
parser.on('error', err => pt.emit('error', err)) | ||
regFetch(uri, opts).then(res => { | ||
res.body.on('error', err => parser.emit('error', err)) | ||
res.body.pipe(parser) | ||
}, err => pt.emit('error', err)) | ||
return pt | ||
} | ||
module.exports.pickRegistry = pickRegistry | ||
@@ -116,0 +130,0 @@ function pickRegistry (spec, opts) { |
{ | ||
"name": "npm-registry-fetch", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"description": "Fetch-based http client for use with npm registry APIs", | ||
@@ -32,2 +32,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"JSONStream": "^1.3.4", | ||
"bluebird": "^3.5.1", | ||
@@ -41,2 +42,3 @@ "figgy-pudding": "^3.4.1", | ||
"cacache": "^11.0.2", | ||
"get-stream": "^4.0.0", | ||
"mkdirp": "^0.5.1", | ||
@@ -43,0 +45,0 @@ "nock": "^9.4.3", |
@@ -85,2 +85,23 @@ # npm-registry-fetch [![npm version](https://img.shields.io/npm/v/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![license](https://img.shields.io/npm/l/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![Travis](https://img.shields.io/travis/npm/npm-registry-fetch/latest.svg)](https://travis-ci.org/npm/npm-registry-fetch) [![AppVeyor](https://img.shields.io/appveyor/ci/zkat/npm-registry-fetch/latest.svg)](https://ci.appveyor.com/project/npm/npm-registry-fetch) [![Coverage Status](https://coveralls.io/repos/github/npm/npm-registry-fetch/badge.svg?branch=latest)](https://coveralls.io/github/npm/npm-registry-fetch?branch=latest) | ||
#### <a name="fetch-json-stream"></a> `> fetch.json.stream(url, jsonPath, [opts]) -> Stream` | ||
Performs a request to a given registry URL and parses the body of the response | ||
as JSON, with each entry being emitted through the stream. | ||
The `jsonPath` argument is a [`JSONStream.parse()` | ||
path](https://github.com/dominictarr/JSONStream#jsonstreamparsepath), and the | ||
returned stream (unlike default `JSONStream`s), has a valid | ||
`Symbol.asyncIterator` implementation. | ||
For available options, please see the section on [`fetch` options](#fetch-opts). | ||
##### Example | ||
```javascript | ||
console.log('https://npm.im/~zkat has access to the following packages:') | ||
for await (let {key, value} of fetch.json.stream('/-/user/zkat/package', '$*')) { | ||
console.log(`https://npm.im/${key} (perms: ${value})`) | ||
} | ||
``` | ||
#### <a name="fetch-opts"></a> `fetch` Options | ||
@@ -87,0 +108,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40997
508
600
6
12
+ AddedJSONStream@^1.3.4
+ AddedJSONStream@1.3.5(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addedthrough@2.3.8(transitive)