Comparing version 3.11.0 to 4.0.0-alpha.1
55
index.js
@@ -8,5 +8,4 @@ 'use strict' | ||
const sink = require('stream-sink') | ||
const pump = require('pump') | ||
const file = path.join(__dirname, 'data.ndjson') | ||
@@ -25,32 +24,30 @@ | ||
const lines = (...args) => { | ||
const pattern = args.pop() | ||
const promised = !!args.shift() | ||
const chain = [ | ||
fs.createReadStream(file), | ||
ndjson.parse() | ||
] | ||
if ('string' === typeof pattern) { | ||
if (pattern !== 'all') { | ||
const filter = filterStream.obj(filterById(pattern)) | ||
chain.push(filter) | ||
} | ||
} else if (pattern !== undefined) { | ||
const filter = filterStream.obj(filterByKeys(pattern)) | ||
chain.push(filter) | ||
} | ||
const lines = function (/* promised, filter */) { | ||
const args = Array.prototype.slice.call(arguments) | ||
let pattern = args.pop() | ||
let promised = !!args.shift() | ||
const reader = fs.createReadStream(file) | ||
const parser = reader.pipe(ndjson.parse()) | ||
let filter | ||
if (pattern === 'all' || pattern === undefined) filter = parser // no filter | ||
else if ('string' === typeof pattern) | ||
filter = parser.pipe(filterStream.obj(filterById(pattern))) | ||
else filter = parser.pipe(filterStream.obj(filterByKeys(pattern))) | ||
if (promised === true) return new Promise((resolve, reject) => { | ||
reader.on('error', reject) | ||
parser.on('error', reject) | ||
filter.on('error', reject) | ||
const results = filter.pipe(sink('object')) | ||
results.catch(reject) | ||
results.then(resolve) | ||
}) | ||
else return filter | ||
if (promised === true) { | ||
const out = sink('object') | ||
pump(...chain, out, () => {}) | ||
return out | ||
} | ||
return pump(...chain, () => {}) | ||
} | ||
module.exports = Object.assign(lines, {filterById, filterByKeys}) | ||
lines.filterById = filterById | ||
lines.filterByKeys = filterByKeys | ||
module.exports = lines |
{ | ||
"name": "vbb-lines", | ||
"description": "VBB lines and their stations.", | ||
"version": "3.11.0", | ||
"version": "4.0.0-alpha.1", | ||
"main": "index.js", | ||
@@ -33,2 +33,3 @@ "files": [ | ||
"ndjson": "^1.5.0", | ||
"pump": "^3.0.0", | ||
"stream-filter": "^2.1.0", | ||
@@ -35,0 +36,0 @@ "stream-sink": "^2.0.0" |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4717420
44
4
1
+ Addedpump@^3.0.0
+ Addedend-of-stream@1.4.4(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)