DefinitelyTyped/types/replacestream/replacestream-tests.ts
Piotr Roszatycki abb6102c14 replacestream: new typings (#29608)
* replacestream: new typings

* replacestream: fix "Exceeds maximum line length of 200"

* replacestream: use `export =` syntax
2018-10-11 10:44:22 -07:00

28 lines
889 B
TypeScript

/// <reference types="node"/>
import * as fs from 'fs';
import * as path from 'path';
import replaceStream = require('replacestream');
fs.createReadStream(path.join(__dirname, 'happybirthday.txt'))
.pipe(replaceStream('birthday', 'earthday'))
.pipe(process.stdout);
fs.createReadStream(path.join(__dirname, 'happybirthday.txt'))
.pipe(replaceStream('birthday', 'earthday', { limit: 2 }))
.pipe(process.stdout);
fs.createReadStream(path.join(__dirname, 'happybirthday.txt'))
.pipe(replaceStream(/birthday/, 'earthday'))
.pipe(process.stdout);
const words = ['Awesome', 'Good', 'Super', 'Joyous'];
function replaceFn(match: string, p1: string, offset: number, string: string): string {
return words.shift() || 'Happy';
}
fs.createReadStream(path.join(__dirname, 'happybirthday.txt'))
.pipe(replaceStream('Happy', replaceFn))
.pipe(process.stdout);