A ts function that takes a string and returns a concatenation of the interfaces and types associated with the matches inside of the string. Its hyper expensive, unnecessary, but a fun experiment with Typescript. It checks longest strings first, but it can be modified to check shorter by reversing our integer assignments.
- Initializes and checks for the string length; if its greater than zero, proceed
- Sets two axis - one at the beginning (x1) one at the end (x2)
- Recursively reduces
x2by 1 integer on every pass, and compares the string fromx1tox2against the given type(s) - If there is a match, its added to the stack and the length of the match (
Len) is replaced with a nullish char.x2is reduced byLen,x1is reset to 1 - Continues until
x2has reached the beginning of the string - Leftover strings between nullish chars are then tested for matches where
x1andx2are relative to the beginning and end of a string between nullish chars - when
x1has reached the length of the given string, checking is stopped and the type stack is concatenated and turned into a Union type