Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Created May 7, 2022 04:27
Show Gist options
  • Save Grubba27/5f006b5076e95d3391dfa0fde5d77e05 to your computer and use it in GitHub Desktop.
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
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'
@scarletquasar
Copy link

oxitona paroxitona proparoxitona

@scarletquasar
Copy link

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