-
-
Notifications
You must be signed in to change notification settings - Fork 47
Ignore
Eugene Lazutkin edited this page Jun 18, 2018
·
3 revisions
Ignore
is a token item filter based on Replace, which is used to remove values completely.
const {ignore} = require('stream-json/filters/Ignore');
const {parser} = require('stream-json/Parser');
const {streamArray} = require('stream-json/streamers/StreamArray');
const pipeline = chain([
fs.createReadStream('sample.json'),
parser(), // packs keys by default, otherwise {packKeys: true}
ignore({filter: /\bmeta\b/i}),
streamArray()
]);
pipeline.on('data', data => console.log(data));
In order to use this filter make sure that a filter gets packed keys.
This is a helper class based on Replace
. See Replace for more details.
The whole implementation is very simple:
class Ignore extends Replace {
constructor(options) {
super(options);
this._replacement = Replace.arrayReplacement([]);
this._allowEmptyReplacement = true;
}
}
Effectively it is Replace
with a replacement
set to []
, and allowEmptyReplacement
is set to true
.
The following options are used:
-
filter
- If it returns a truthy value, the current object is removed completely with all its possible subobjects.
- It is called only for the following tokens:
startObject
,startArray
,startString
,startNumber
,stringValue
,numberValue
,nullValue
,trueValue
,falseValue
.
pathSeparator
once
It uses the same set of static methods and properties as Replace. The differences:
- It uses
Ignore
as a class for all instances. - Its factory function is called
ignore()
instead ofreplace()
.