-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display built regexp in TS tooltip (#6)
- Loading branch information
Showing
8 changed files
with
174 additions
and
51 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
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
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,28 @@ | ||
import type { Input } from '../inputs' | ||
import { InputSource } from './sources' | ||
|
||
// prettier-ignore | ||
type ExactEscapeChar = '.' | '*' | '+' | '?' | '^' | '$' | '{' | '}' | '(' | ')' | '|' | '[' | ']' | '/' | ||
type Escape< | ||
T extends string, | ||
EscapeChar extends string | ||
> = T extends `${infer Start}${EscapeChar}${string}` | ||
? Start extends `${string}${EscapeChar}${string}` | ||
? never | ||
: T extends `${Start}${infer Char}${string}` | ||
? Char extends EscapeChar | ||
? T extends `${Start}${Char}${infer Rest}` | ||
? `${Start}\\${Char}${Escape<Rest, EscapeChar>}` | ||
: never | ||
: never | ||
: never | ||
: T | ||
|
||
type CharEscapeCharacter = '\\' | '^' | '-' | ']' | ||
export type EscapeChar<T extends string> = Escape<T, CharEscapeCharacter> | ||
|
||
export type GetValue<T extends InputSource<string>> = T extends string | ||
? Escape<T, ExactEscapeChar> | ||
: T extends Input<infer R> | ||
? R | ||
: never |
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 @@ | ||
export type Join< | ||
T extends string[], | ||
Prefix extends string = '', | ||
Joiner extends string = '|' | ||
> = T extends [infer F, ...infer R] | ||
? F extends string | ||
? `${Prefix}${F}${R extends string[] ? Join<R, Joiner, Joiner> : ''}` | ||
: '' | ||
: '' |
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,17 @@ | ||
import { Input } from '../internal' | ||
|
||
export type InputSource<S extends string = never, T extends string = never> = S | Input<S, T> | ||
export type MapToValues<T extends InputSource<any, any>[]> = T extends [infer First, ...infer Rest] | ||
? First extends InputSource<infer K> | ||
? [K, ...MapToValues<Rest>] | ||
: [] | ||
: [] | ||
|
||
export type MapToGroups<T extends InputSource<any, string>[]> = T extends [ | ||
infer First, | ||
...infer Rest | ||
] | ||
? First extends Input<any, infer K> | ||
? K | MapToGroups<Rest> | ||
: MapToGroups<Rest> | ||
: never |
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
Oops, something went wrong.