mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
30 lines
864 B
TypeScript
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'));
|