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
function base64ToBytes(base64: string): Uint8Array { | |
const binString = atob(base64); | |
return Uint8Array.from(binString, (m) => m.codePointAt(0) || 0); | |
} | |
function bytesToBase64(bytes: Uint8Array): string { | |
const binString = String.fromCodePoint(...bytes); | |
return btoa(binString); | |
} |
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 { z } from "zod"; | |
type ParsedFormData<T extends z.AnyZodObject> = { | |
data: null; | |
errors: z.typeToFlattenedError<z.infer<T>>['fieldErrors'] | |
} | { | |
data: z.infer<T>; | |
errors: null; | |
} |
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 type { ActionFunctionArgs, ActionFunction } from "@remix-run/node"; | |
import type { AnyZodObject, z } from "zod" | |
export type FormActionHandler<T extends AnyZodObject> = (data: z.infer<T>, args: ActionFunctionArgs) => Promise<Response | null> | |
export type FormAction<T extends AnyZodObject> = { | |
schema: T | |
} & { | |
handler: FormActionHandler<T> | |
} |
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
type Delimiter = ",\n"|"," | "." | "?" | "!" | "\n" | |
type IsTemplateTag<Word> = Word extends `{${infer TagName}}${Delimiter}${string}` ? TagName : never; | |
// type IsTemplateTag<Word> = Word extends `{${infer TagName}}` ? TagName : isTemplateTagWithComma<Word>; | |
// type isTemplateTagWithComma<Word> = Word extends `{${infer Tagname}},` ? Tagname : isTemplateTagWithPeriod<Word>; | |
// type isTemplateTagWithPeriod<Word> = Word extends `{${infer Tagname}}.` ? Tagname : never; | |
type TemplateTags<TemplateString> = TemplateString extends | |
`${infer PartA} ${infer PartB}` ? IsTemplateTag<PartA> | TemplateTags<PartB> | |
: IsTemplateTag<TemplateString>; |
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 {toHashString} from 'https://deno.land/std@0.201.0/crypto/to_hash_string.ts'; | |
import {parse} from 'https://deno.land/std@0.201.0/flags/mod.ts'; | |
const args = parse(Deno.args, { | |
boolean: ['help'], | |
alias: { | |
help: 'h', | |
encoding: 'e', | |
}, | |
string: ['encoding'], |
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 { unified } from "https://esm.sh/unified@10.1.2"; | |
import remarkParse from "https://esm.sh/remark-parse@10.0.2"; | |
import remarkFrontmatter from "https://esm.sh/remark-frontmatter@4.0.1"; | |
import remarkGfm from "https://esm.sh/remark-gfm@3.0.1"; | |
import remarkRehype from "https://esm.sh/remark-rehype@10.1.0"; | |
import rehypeStringify from "https://esm.sh/rehype-stringify@9.0.3"; | |
import rehypeSlug from "https://esm.sh/rehype-slug@5.1.0"; | |
import rehypeAutolinkHeadings from "https://esm.sh/rehype-autolink-headings@6.1.1"; | |
import remarkGemoji from "https://esm.sh/remark-gemoji@7.0.1"; | |
import rehypeStarryNight from "https://esm.sh/@microflash/rehype-starry-night@2.1.1"; |
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 type { ConnInfo, Handler } from "https://deno.land/std@0.194.0/http/server.ts"; | |
type RemoveModifier<Pattern> = Pattern extends `${infer P}?` ? P | |
: Pattern; | |
type RemoveMatchingRule<Pattern> = Pattern extends `${infer P}(${infer R})` ? P | |
: Pattern; | |
type ExtractGroupName<Pattern> = RemoveModifier<RemoveMatchingRule<Pattern>>; | |
type PatternParamValue<Key> = Key extends `${infer PatternString}?` | |
? string | undefined |
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
/** | |
* A generic class that allows for the creation of events and listeners. | |
* | |
* @template T - An object type that defines the events and their data types. | |
*/ | |
export default class EventEmitter<T> { | |
private events: { [K in keyof T]: Array<(data: T[K]) => void> } = {} as unknown as { [K in keyof T]: Array<(data: T[K]) => void> }; | |
/** | |
* Adds a listener to an event. |
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
div[data-autogrow]:has(textarea) { | |
display: grid; | |
} | |
div[data-autogrow]:has(textarea)::after { | |
content: attr(data-autogrow) ' '; | |
white-space: pre-wrap; | |
visibility: hidden; | |
} |
NewerOlder