type-fest/test-d/replace.ts
2022-07-03 21:52:44 +02:00

30 lines
864 B
TypeScript

import {expectType} from 'tsd';
import type {Replace} from '../index';
declare function replace<
Input extends string,
Search extends string,
Replacement extends string,
>(
input: Input,
search: Search,
replacement: Replacement
): Replace<Input, Search, Replacement>;
declare function replaceAll<
Input extends string,
Search extends string,
Replacement extends string,
>(
input: Input,
search: Search,
replacement: Replacement
): Replace<Input, Search, Replacement, {all: true}>;
expectType<'hello 🦄'>(replace('hello ?', '?', '🦄'));
expectType<'hello ❓?'>(replace('hello ??', '?', '❓'));
expectType<'10-42-00'>(replaceAll('10:42:00', ':', '-'));
expectType<'userName'>(replaceAll('__userName__', '__', ''));
expectType<'MyCoolTitle'>(replaceAll('My Cool Title', ' ', ''));
expectType<'fobarfobar'>(replaceAll('foobarfoobar', 'ob', 'b'));