Created
January 17, 2024 17:16
-
-
Save AlenVelocity/5df0bd72dfb9c10d479257ac3dd9e9d4 to your computer and use it in GitHub Desktop.
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
import { Add, Divide, IsEven, Subtract } from 'ts-arithmetic' | |
export type StrLen<S extends string> = S extends `${infer _}${infer R}` ? Add<1, StrLen<R>> : 0 | |
type OneToTwenty = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20] | |
export type ReduceNum<N extends number> = | |
N extends OneToTwenty[number] ? N : IsEven<N> extends 1 ? | |
ReduceNum<Divide<N, 2>> : 5 | |
type Replace< | |
T extends string, | |
From extends string, | |
To extends string, | |
> = From extends '' | |
? T | |
: T extends `${infer L}${From}${infer R}` | |
? `${L}${To}${R}` | |
: T | |
type ReplaceAll< | |
T extends string, | |
From extends string, | |
To extends string, | |
> = From extends '' | |
? T | |
: T extends Replace<T, From, To> | |
? T | |
: ReplaceAll<Replace<T, From, To>, From, To> | |
// 20 Faces | |
type _Faces = ['(・`ω´・)', ';;w;;', 'owo', 'UwU', '>w<', '(o・ω・o)', 'ÚwÚ', '^-^', ':3', 'x3', '>.<', '(* ^ ω ^)', '(⌒ω⌒)', '(o´∀`o)', '^w^', '\(^▽^)/', '(*^▽^)/', 'ヽ(*・ω・)ノ', '(o´・ω・)o', '(@^◡^)'] | |
type Face<I extends number> = _Faces[I] | |
type FaceBasedOnStrLen<T extends string> = T extends `${infer _}${infer R}` | |
? Face<ReduceNum<IsEven<StrLen<T>> extends true ? StrLen<T> : Subtract<StrLen<T>, 1>>> | |
: never | |
type AppendFace<T extends string> = `${T} ${FaceBasedOnStrLen<T>}` | |
type ReplaceRL<T extends string> = ReplaceAll< | |
ReplaceAll<ReplaceAll<ReplaceAll<T, 'R', 'W'>, 'r', 'w'>, 'L', 'W'>, | |
'l', | |
'w' | |
> | |
type Vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] | |
type ReplaceNVowels<T extends string> = T extends `${infer L}n${infer R}` | |
? R extends `${infer F}${infer _}` | |
? F extends Vowels[number] | |
? `${L}ny${R}` | |
: `${L}n${ReplaceNVowels<R>}` | |
: T | |
: T | |
type SpecificWords = { | |
love: 'wuv', | |
mr: 'mistuh', | |
dog: 'doggo', | |
cat: 'kitteh', | |
hello: 'henwo', | |
this: 'dis', | |
is: 'ish', | |
you: 'uu', | |
your: 'ur', | |
the: 'da', | |
an: 'a' | |
} | |
type Words = keyof SpecificWords | Uppercase<keyof SpecificWords> | Capitalize<keyof SpecificWords> | |
type ReplaceSpecificWords<T extends string> = T extends `${infer L} ${infer M} ${infer R}` ? | |
L extends Words ? `${SpecificWords[Lowercase<L>]} ${ReplaceSpecificWords<M>} ${ReplaceSpecificWords<R>}` : | |
M extends Words ? `${ReplaceSpecificWords<L>} ${SpecificWords[Lowercase<M>]} ${ReplaceSpecificWords<R>}` : | |
R extends Words ? `${ReplaceSpecificWords<L>} ${ReplaceSpecificWords<M>} ${SpecificWords[Lowercase<R>]}` : | |
`${ReplaceSpecificWords<L>} ${ReplaceSpecificWords<M>} ${ReplaceSpecificWords<R>}` : | |
T extends `${infer L} ${infer R}` ? | |
L extends Words ? `${SpecificWords[Lowercase<L>]} ${ReplaceSpecificWords<R>}` : | |
R extends Words ? `${ReplaceSpecificWords<L>} ${SpecificWords[Lowercase<R>]}` : | |
`${ReplaceSpecificWords<L>} ${ReplaceSpecificWords<R>}` : | |
T extends Words ? SpecificWords[Lowercase<T>] : T | |
type PunchuationFaces = { | |
'.': ' (・`ω´・)', | |
'!': ' (!・`ω´・)', | |
'?': ' (?・`ω´・)', | |
',': ' (・`ω´・,)' | |
':': ' (・`ω´・:)', | |
} | |
type ReplacePunchuation<T extends string> = T extends `${infer L}${infer R}` ? | |
L extends keyof PunchuationFaces ? `${PunchuationFaces[L]}${ReplacePunchuation<R>}` : | |
`${L}${ReplacePunchuation<R>}` : T | |
type OwOify<T extends string> = ReplaceRL<ReplaceSpecificWords<ReplacePunchuation<ReplaceNVowels<AppendFace<T>>>>> | |
type A = OwOify<'Hello! I am your worst nightmare'> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment