mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
31 lines
800 B
TypeScript
31 lines
800 B
TypeScript
import {expectType} from 'tsd';
|
|
import type {Split} from '../index';
|
|
|
|
declare function split<
|
|
S extends string,
|
|
Delimiter extends string,
|
|
>(string: S, separator: Delimiter): Split<S, Delimiter>;
|
|
|
|
const items = 'foo,bar,baz,waldo';
|
|
|
|
// General use.
|
|
expectType<['foo', 'bar', 'baz', 'waldo']>(split(items, ','));
|
|
|
|
// Missing replacement character in original string.
|
|
expectType<['foo,bar,baz,waldo']>(split(items, ' '));
|
|
|
|
// Empty string split (every character).
|
|
expectType<[
|
|
'f', 'o', 'o', ',', 'b', 'a', 'r', ',',
|
|
'b', 'a', 'z', ',', 'w', 'a', 'l', 'd', 'o',
|
|
]>(split(items, ''));
|
|
|
|
// Split single same character.
|
|
expectType<['', '']>(split(' ', ' '));
|
|
|
|
// Split empty string by empty string.
|
|
expectType<[]>(split('', ''));
|
|
|
|
// Split empty string by any string.
|
|
expectType<['']>(split('', ' '));
|