typedash
Version:
modern, type-safe collection of utility functions
16 lines (14 loc) • 590 B
TypeScript
/**
* Ensures that the string ends with the given suffix.
* @param string The string to ensure the suffix of.
* @param suffix The suffix to ensure.
* @returns The string with the given suffix.
* @example
* ```ts
* ensureSuffix('foo', 'bar'); // 'foobar'
* ensureSuffix('foobar', 'bar'); // 'foobar'
* ```
*/
declare function ensureSuffix<S extends string, Suffix extends string>(string: S, suffix: Suffix): EnsureSuffix<S, Suffix>;
type EnsureSuffix<S extends string, Suffix extends string> = S extends `${infer _Prefix}${Suffix}` ? S : `${S}${Suffix}`;
export { ensureSuffix };