Merge pull request #31427 from BendingBender/replace-string

[replace-string] Add types
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 09:42:41 -08:00
committed by GitHub
4 changed files with 71 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for replace-string 2.0
// Project: https://github.com/sindresorhus/replace-string#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = replaceString;
declare function replaceString(
input: string,
needle: string,
replacement: string | replaceString.ReplacementFn,
options?: replaceString.Options
): string;
declare namespace replaceString {
type ReplacementFn = (
needle: string,
matchCount: number,
input: string,
matchIndex: number
) => string;
interface Options {
fromIndex?: number;
}
}
@@ -0,0 +1,21 @@
import replaceString = require('replace-string');
const input = 'My friend has a 🐑. I want a 🐑 too!';
// $ExpectType string
replaceString(input, '🐑', '🦄');
// $ExpectType string
replaceString(input, '🐑', (needle, matchCount, input, matchIndex) => {
// $ExpectType string
needle;
// $ExpectType number
matchCount;
// $ExpectType string
input;
// $ExpectType number
matchIndex;
return '🦄';
});
// $ExpectType string
replaceString(input, '🐑', '🦄', { fromIndex: 1 });
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"replace-string-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }