find-replace types added (#44151)

* find-replace types added

* Files regenerated

* Update types/find-replace/index.d.ts

Co-Authored-By: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
This commit is contained in:
Renat Zamaletdinov 2020-04-27 16:01:26 +03:00 committed by GitHub
parent 3cc65e925e
commit 392dc8e92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import findReplace = require("find-replace");
const numbers = [1, 2, 3, 4, 5];
const resultTyped = findReplace<number>(
numbers,
num => num === 3,
num => num * 2
);
const colours = ['red', 'white', 'blue', 'white'];
const resultAny = findReplace(
colours,
colour => colour === 'red',
(colour: any) => colour.split('')
);

24
types/find-replace/index.d.ts vendored Normal file
View File

@ -0,0 +1,24 @@
// Type definitions for find-replace 4.0
// Project: https://github.com/75lb/find-replace#readme
// Definitions by: Renat Zamaletdinov <https://github.com/Zamaletdinov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Replace or remove multiple items in an array
*
* `array` - The input array
*
* `findFn` - A predicate which, if returns true causes the current item to be operated on
*
* `...replaceWiths`:
*
* * If not specified, each found value will be removed.
* * If specified, each found value will be replaced with this value.
* * If the replaceWith value is a function, it will be invoked with the found value and its result used as the replace value.
* * If the replaceWith function returns an array, the found value will be replaced with each item in the array (not replaced with the array itself).
*/
declare function findReplace<T>(array: T[], findFn: (x: T) => boolean, ...replaceWiths: Array<T | ((x: T) => T)>): T[];
declare function findReplace(array: any[], findFn: (x: any) => boolean, ...replaceWiths: any[]): any[];
export as namespace findReplace;
export = findReplace;

View 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",
"find-replace-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }