froebel
Version:
TypeScript utility library
12 lines (11 loc) • 643 B
TypeScript
import type { Prefix, StringCase } from "./types";
/**
* Returns `str` prefixed with `prefix`. Optionally, allows prefxing in camel
* case, i.e. `prefix('foo', 'bar', 'camel') => 'fooBar'`, or snake case, i.e.
* `prefix('foo', 'bar', 'snake') => 'foo_bar'`.
*
* The result is strictly typed, so `prefix('foo', 'bar')` will return the type
* `'foobar'`, not just a generic `string`.
*/
declare const prefix: <T0 extends string, T1 extends string, C extends void | StringCase = void>(prefix: T0, str: T1, caseMod?: C | undefined) => `${T0}${C extends "snake" ? "_" : ""}${C extends "camel" ? Capitalize<T1> : T1}`;
export default prefix;