utilities.js 462 B

1234567891011121314151617
  1. import {fileURLToPath} from 'node:url';
  2. import {Transform} from 'node:stream';
  3. export const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
  4. export class FilterStream extends Transform {
  5. constructor(filter) {
  6. super({
  7. objectMode: true,
  8. transform(data, encoding, callback) {
  9. callback(undefined, filter(data) ? data : undefined);
  10. },
  11. });
  12. }
  13. }
  14. export const isNegativePattern = pattern => pattern[0] === '!';