Files
memecoin-botV2/.pnpm-store/v10/files/73/c59253c000316289178ee94cc253709945b93be0419e66eedcbf902b3b0ab2e2fd6433ac9db9a6b9e1ebb9e97f7a8dc8019dc321996bcace85c0da730cc036

47 lines
1.2 KiB
Plaintext

'use strict';
const {Transform} = require('stream');
const alwaysFalse = () => false;
class SkipWhile extends Transform {
constructor(options) {
super(Object.assign({}, options, {writableObjectMode: true, readableObjectMode: true}));
this._condition = alwaysFalse;
if (options) {
'condition' in options && (this._condition = options.condition);
}
}
_transform(chunk, encoding, callback) {
const result = this._condition.call(this, chunk);
if (result && typeof result.then == 'function') {
result.then(
flag => {
if (!flag) {
this._transform = this._passThrough;
this.push(chunk);
}
callback(null);
},
error => callback(error)
);
} else {
if (!result) {
this._transform = this._passThrough;
this.push(chunk);
}
callback(null);
}
}
_passThrough(chunk, encoding, callback) {
this.push(chunk);
callback(null);
}
static make(condition) {
return new SkipWhile(typeof condition == 'object' ? condition : {condition});
}
}
SkipWhile.make.Constructor = SkipWhile;
module.exports = SkipWhile.make;