This file contains hidden or 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
| /** | |
| * @param {TemplateStringsArray} strings | |
| * @param {...any} values | |
| * @returns {DocumentFragment} | |
| */ | |
| function html(strings, ...values) { | |
| let out = '' | |
| for (let index = 0; index < strings.length; index++) { | |
| out += strings[index] |
This file contains hidden or 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
| class GitBatchCat { | |
| repoPath: string | |
| process: ChildProcess | |
| queue: Array<{ | |
| resolve: ( | |
| value: { sha: string; type: string; content: string } | null | |
| ) => void | |
| reject: (error: Error) => void | |
| }> |
This file contains hidden or 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
| const callStack: string[] = [] | |
| const MAX_DEPTH = 1500 | |
| const SNIPPET_LEN = 60 | |
| function snippet(text: string) { | |
| return text.replace(/\s+/g, ' ').slice(0, SNIPPET_LEN) | |
| } | |
| /** Traces the type and its enclosing node. */ | |
| function traceType(type: Type, node?: Node) { |
This file contains hidden or 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
| /** Returns a list of the type's flags. */ | |
| function typeIs(type: tsMorph.Type) { | |
| return Object.entries({ | |
| Anonymous: type.isAnonymous(), | |
| Array: type.isArray(), | |
| Boolean: type.isBoolean() || type.isBooleanLiteral(), | |
| String: type.isString() || type.isStringLiteral(), | |
| Number: type.isNumber() || type.isNumberLiteral(), | |
| BigInt: type.isBigInt() || type.isBigIntLiteral(), | |
| Symbol: isSymbolType(type), |
This file contains hidden or 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 React, { cache } from 'react' | |
| import 'server-only' | |
| type ContextType<Value> = React.FC<{ | |
| /** The children of the context provider. */ | |
| children: React.ReactNode | |
| /** Sets the context value for its descendants. */ | |
| value: Value | |
| }> & { |
This file contains hidden or 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 { Project, ts } from 'ts-morph' | |
| import * as tsMorph from 'ts-morph' | |
| const printerCache = new WeakMap<Project, ts.Printer>() | |
| const LineFeed = tsMorph.ts.NewLineKind.LineFeed | |
| /** Get a ts.Printer configured to match the project’s `compilerOptions`. */ | |
| export function getPrinter( | |
| project: Project, | |
| overrides?: Partial<ts.PrinterOptions> |
This file contains hidden or 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 { Identifier } from 'ts-morph' | |
| const referenceCache = new WeakMap<Identifier, boolean>() | |
| /** Determines if an identifier is a reference. */ | |
| export function isReferenceIdentifier(node: Identifier) { | |
| const cached = referenceCache.get(node) | |
| if (cached !== undefined) { | |
| return cached |
This file contains hidden or 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 compareHashPerformance(input = 'body { margin: 0; padding: 0; }', iterations = 100000) { | |
| // FNV-1a Hash Function (with Base36 Encoding) | |
| function fnvHash(str) { | |
| let h = 0 ^ 0x811c9dc5; | |
| for (let i = 0; i < str.length; i++) { | |
| h ^= str.charCodeAt(i); | |
| h = (h * 0x01000193) >>> 0; | |
| } | |
| const letters = 'abcdefghijklmnopqrstuvwxyz'; | |
| const base36 = '0123456789' + letters; |
This file contains hidden or 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 { GitHubSponsors } from './GitHubSponsors' | |
| export function GitHubSponsorTiers() { | |
| return ( | |
| <GitHubSponsors | |
| tiers={{ | |
| 100: { | |
| title: 'Bronze', | |
| icon: '🥉', | |
| }, |
This file contains hidden or 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
| const seenStyleElements = new Set<HTMLStyleElement>() | |
| const cache = new Set<string>() | |
| function processStyleRule( | |
| rule: CSSStyleRule, | |
| sheet: CSSStyleSheet, | |
| index: number | |
| ) { | |
| const selector = rule.selectorText | |
| const className = selector.match(/\.([a-zA-Z0-9_-]+)/)![1]! |
NewerOlder