forked from type-challenges/type-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
type-challenges#19458 - SnakeCase (type-challenges#19459)
Co-authored-by: Gabriel Vergnaud <9265418+gvergnaud@users.noreply.github.com>
- Loading branch information
1 parent
e25c669
commit 4515e9c
Showing
4 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
difficulty: hard | ||
title: SnakeCase | ||
tags: template-literal,string | ||
author: | ||
github: gvergnaud | ||
name: Gabriel Vergnaud | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type SnakeCase<T> = any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Equal, Expect } from '@type-challenges/utils' | ||
import { ExpectFalse, NotEqual } from '@type-challenges/utils' | ||
|
||
type cases = [ | ||
Expect<Equal<SnakeCase<"hello">, "hello">>, | ||
Expect<Equal<SnakeCase<"userName">, "user_name">>, | ||
Expect<Equal<SnakeCase<"getElementById">, "get_element_by_id">>, | ||
Expect<Equal<SnakeCase<"getElementById" | "getElementByClassNames">, "get_element_by_id" | "get_element_by_class_names">>, | ||
] |