diff --git a/types/replace-string/index.d.ts b/types/replace-string/index.d.ts new file mode 100644 index 0000000000..7819754746 --- /dev/null +++ b/types/replace-string/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for replace-string 2.0 +// Project: https://github.com/sindresorhus/replace-string#readme +// Definitions by: 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; + } +} diff --git a/types/replace-string/replace-string-tests.ts b/types/replace-string/replace-string-tests.ts new file mode 100644 index 0000000000..385ae1f023 --- /dev/null +++ b/types/replace-string/replace-string-tests.ts @@ -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 }); diff --git a/types/replace-string/tsconfig.json b/types/replace-string/tsconfig.json new file mode 100644 index 0000000000..ef0dcb7937 --- /dev/null +++ b/types/replace-string/tsconfig.json @@ -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" + ] +} diff --git a/types/replace-string/tslint.json b/types/replace-string/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/replace-string/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }