mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Merge pull request #31427 from BendingBender/replace-string
[replace-string] Add types
This commit is contained in:
Vendored
+26
@@ -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 });
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user