UNPKG

typedash

Version:

modern, type-safe collection of utility functions

49 lines (48 loc) 1.75 kB
import { KebabCase } from "type-fest"; //#region src/functions/kebabCase/kebabCase.d.ts /** * Changes the casing of a string to kebab case. * @param string The input string to change the casing of. * @returns A new string with the casing changed to kebab case. * @example * ```ts * kebabCase('fooBar') // 'foo-bar' * kebabCase('foo bar') // 'foo-bar' * kebabCase('foo-bar') // 'foo-bar' * kebabCase('fooBar42') // 'foo-bar42' * ``` */ declare function kebabCase<S extends string>(string: S): KebabCase$1<S>; /** * Changes the casing of a string to kebab case. * @see {@link kebabCase}. */ type KebabCase$1<S extends string> = TrimDashes<ReduceDashes<KebabCase<S>>>; /** * Reduces multiple dashes to a single dash. * @param S The input string. * @returns A new string with multiple dashes reduced to a single dash. * @example * ```ts * ReduceDashes<'foo--bar'> // 'foo-bar' * ReduceDashes<'foo-bar'> // 'foo-bar' * ReduceDashes<'foo---bar'> // 'foo-bar' * ``` */ type ReduceDashes<S extends string> = S extends `${infer L}--${infer R}` ? ReduceDashes<`${L}-${R}`> : S extends `${infer L}${infer D}--${infer R}` ? ReduceDashes<`${L}${D}-${R}`> : S; /** * Trims dashes from the start and end of a string. * @param S The input string. * @returns A new string with dashes trimmed from the start and end. * @example * ```ts * TrimDashes<'-foo-bar-'> // 'foo-bar' * TrimDashes<'foo-bar-'> // 'foo-bar' * TrimDashes<'-foo-bar'> // 'foo-bar' * TrimDashes<'foo-bar'> // 'foo-bar' * ``` */ type TrimDashes<S extends string> = S extends `-${infer R}` ? TrimDashes<R> : S extends `${infer L}-` ? TrimDashes<L> : S; //#endregion export { kebabCase as n, KebabCase$1 as t }; //# sourceMappingURL=kebabCase-BvbaWZcq.d.cts.map