Created
May 7, 2022 04:27
-
-
Save Grubba27/5f006b5076e95d3391dfa0fde5d77e05 to your computer and use it in GitHub Desktop.
A simple typescript program to verify if the word is a portuguese proparoxitítona
This file contains hidden or 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
type Reverse<A> = | |
`${A}` extends `${infer AH}${infer AT}` | |
? `${Reverse<AT>}${AH}` : A | |
type Digs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
type DigsNext<I = Digs, R = {}> = | |
I extends [infer Head, infer Next, ...infer Tail] | |
? DigsNext<[Next, ...Tail], R & Record<Head, Next>> | |
: { [K in keyof R]: R[K] } | |
type DigsPrev = { [K in keyof DigsNext as DigsNext[K]]: K } | |
type AddOne<A> = | |
A extends `${infer AH}${infer AT}` | |
? AH extends '9' ? `0${AddOne<AT>}` : `${DigsNext[AH]}${AT}` | |
: `1` | |
type ReverseText | |
<Str extends string, Rev extends string = ''> | |
= Str extends `${infer L}${infer R}` ? ReverseText<R, `${L}${Rev}`> : Rev; | |
const rev: ReverseText<'bússola'> = 'alossúb' | |
type Vogals = {a: 'á', e:'é', i:'í', o:'ó', u:'ú'} | |
type KeyOfVogals<Key extends string> = Key extends keyof Vogals ? Vogals[Key] : never; | |
const b: KeyOfVogals<'a'> | |
type ProparocítonaMaker< | |
Word extends string, | |
Acc extends string = '', | |
Counter extends string = '0' | |
> = | |
Word extends `${infer L}${infer R}` | |
? KeyOfVogals<L> extends never | |
? ProparocítonaMaker<R, `${Acc}${L}`, Counter> | |
: Counter extends '2' | |
? ProparocítonaMaker<R, `${Acc}${KeyOfVogals<L>}`, AddOne<Counter>> | |
: ProparocítonaMaker<R, `${Acc}${L}`, AddOne<Counter>> | |
: ReverseText<Acc> | |
const prop: ProparocítonaMaker<ReverseText<'atomo'>>= 'átomo' | |
const prop: ProparocítonaMaker<ReverseText<'brocolis'>> = 'brócolis' | |
const prop: ProparocítonaMaker<ReverseText<'decima'>> ='décima' |
agora que eu vi que é com type system que isso
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oxitona paroxitona proparoxitona