Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Vergnaud <9265418+gvergnaud@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and gvergnaud authored Dec 13, 2022
1 parent e25c669 commit 4515e9c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions questions/19458-hard-snakecase/README.md
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"
```
7 changes: 7 additions & 0 deletions questions/19458-hard-snakecase/info.yml
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

1 change: 1 addition & 0 deletions questions/19458-hard-snakecase/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type SnakeCase<T> = any
9 changes: 9 additions & 0 deletions questions/19458-hard-snakecase/test-cases.ts
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">>,
]

0 comments on commit 4515e9c

Please sign in to comment.