Back to Type Challenges

README

questions/19458-hard-snakecase/README.md

latest1.4 KB
Original Source
<!--info-header-start--><h1>SnakeCase </h1><blockquote><p>by Gabriel Vergnaud <a href="https://github.com/gvergnaud" target="_blank">@gvergnaud</a></p></blockquote><p><a href="https://tsch.js.org/19458/play" target="_blank"></a> </p><!--info-header-end-->

Create a SnakeCase<T> generic that turns a string formatted in camelCase into a string formatted in snake_case.

A few examples:

ts
type res1 = SnakeCase<"hello">; // => "hello"
type res2 = SnakeCase<"userName">; // => "user_name"
type res3 = SnakeCase<"getElementById">; // => "get_element_by_id"
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/19458/answer" target="_blank"></a> <a href="https://tsch.js.org/19458/solutions" target="_blank"></a> <!--info-footer-end-->