source: trip-planner-front/node_modules/globby/stream-utils.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 677 bytes
RevLine 
[6a3a178]1'use strict';
2const {Transform} = require('stream');
3
4class ObjectTransform extends Transform {
5 constructor() {
6 super({
7 objectMode: true
8 });
9 }
10}
11
12class FilterStream extends ObjectTransform {
13 constructor(filter) {
14 super();
15 this._filter = filter;
16 }
17
18 _transform(data, encoding, callback) {
19 if (this._filter(data)) {
20 this.push(data);
21 }
22
23 callback();
24 }
25}
26
27class UniqueStream extends ObjectTransform {
28 constructor() {
29 super();
30 this._pushed = new Set();
31 }
32
33 _transform(data, encoding, callback) {
34 if (!this._pushed.has(data)) {
35 this.push(data);
36 this._pushed.add(data);
37 }
38
39 callback();
40 }
41}
42
43module.exports = {
44 FilterStream,
45 UniqueStream
46};
Note: See TracBrowser for help on using the repository browser.