mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-26 10:14:26 +08:00
replacestream: new typings (#29608)
* replacestream: new typings * replacestream: fix "Exceeds maximum line length of 200" * replacestream: use `export =` syntax
This commit is contained in:
54
types/replacestream/index.d.ts
vendored
Normal file
54
types/replacestream/index.d.ts
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// Type definitions for replacestream 4.0
|
||||
// Project: https://github.com/eugeneware/replacestream#readme
|
||||
// Definitions by: Piotr Roszatycki <https://github.com/dex4er>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace ReplaceStream {
|
||||
interface Options {
|
||||
/**
|
||||
* Sets a limit on the number of times the replacement will be made. This
|
||||
* is forced to one when a regex without the global flag is provided.
|
||||
*
|
||||
* Default: `Infinity`
|
||||
*/
|
||||
limit?: number;
|
||||
/**
|
||||
* The text encoding used during search and replace.
|
||||
*
|
||||
* Default: `"utf8"`
|
||||
*/
|
||||
encoding?: string;
|
||||
/**
|
||||
* When doing cross-chunk replacing, this sets the maximum length match
|
||||
* that will be supported.
|
||||
*
|
||||
* Default: `100`
|
||||
*/
|
||||
maxMatchLen?: number;
|
||||
/**
|
||||
* When doing string match (not relevant for regex matching) whether to do a
|
||||
* case insensitive search.
|
||||
*
|
||||
* Default: `true`
|
||||
*/
|
||||
ignoreCase?: boolean;
|
||||
/**
|
||||
* When provided, these flags will be used when creating the search regexes
|
||||
* internally.
|
||||
*
|
||||
* @deprecated as the flags set on the regex provided are no longer mutated
|
||||
* if this is not provided.
|
||||
*/
|
||||
regExpOptions?: string;
|
||||
}
|
||||
|
||||
type ReplaceFunction = (match: string, p1: string, offset: number, string: string) => string;
|
||||
}
|
||||
|
||||
declare function ReplaceStream(
|
||||
search: RegExp | string,
|
||||
replace: ReplaceStream.ReplaceFunction | string,
|
||||
options?: ReplaceStream.Options
|
||||
): any;
|
||||
|
||||
export = ReplaceStream;
|
||||
27
types/replacestream/replacestream-tests.ts
Normal file
27
types/replacestream/replacestream-tests.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/// <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);
|
||||
23
types/replacestream/tsconfig.json
Normal file
23
types/replacestream/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"replacestream-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/replacestream/tslint.json
Normal file
1
types/replacestream/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user