Skip to content

Instantly share code, notes, and snippets.

View neverUsedGithub's full-sized avatar

Never Used Github neverUsedGithub

View GitHub Profile
@neverUsedGithub
neverUsedGithub / brainfuck.d.ts
Created August 22, 2023 19:30
Type only brainfuck interpreter.
type StringToArray<str extends string> = str extends `${infer First}${infer Rest}`
? [ First, ...StringToArray<Rest> ]
: []
type NewArray<length extends number, arr extends any[] = []> = arr["length"] extends length
? arr
: NewArray<length, [ ...arr, any ]>;
type New2DArray<length extends number, arr extends any[][] = []> = arr["length"] extends length
? arr
@neverUsedGithub
neverUsedGithub / graphql-parser.d.ts
Created July 25, 2023 06:38
A type-level graphql lexer & parser & ts converter.
// Utility
type GetFirstCharacter<Text extends string> = Text extends `${infer First}${infer Rest}` ? First : never;
type StringStartsWith<Source extends string, Char extends string> = Source extends `${infer First}${infer Rest}`
? First extends Char
? true
: false
: false;
type SliceStringFirst<Source extends string> = Source extends `${infer First}${infer Rest}`
? Rest
: never;