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
| /** | |
| * Converts array or tuple `T` to an object keyed by index. | |
| * | |
| * Example: | |
| * type ExampleTuple = ByIndex<[string, number]>; // { 0: string, 1: number } | |
| * type ExampleArray = ByIndex<(string | number)[]>; // { [x: number]: string | number } | |
| */ | |
| type ByIndex<T extends any[]> = { | |
| [K in Extract<keyof T, `${number}`>]: T[K]; | |
| }; |
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
| /** | |
| * A utility type that returns a union of space-separated words in a string. | |
| * | |
| * @example | |
| * ```ts | |
| * type Foo = Words<'foo bar baz'>; | |
| * // => 'foo' | 'bar' | 'baz' | |
| */ | |
| type Words<TString extends string> = | |
| TString extends `${infer Word} ${infer Rest}` ? Word | Words<Rest> : TString; |
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
| /** | |
| * Convert members of a union to an intersection. | |
| * | |
| * @example | |
| * ```ts | |
| * type Union = { a: number } | { b: string }; | |
| * type Intersection = UnionToIntersection<Union>; | |
| * // { a: number } & { b: string } | |
| * ``` | |
| * |
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 { useEffect, useState } from "react"; | |
| /** | |
| * A hook to observe the intersection of elements and return the IDs of those | |
| * that are intersecting. | |
| * @param ids The IDs of the elements to observe | |
| * @param options The options to pass to the IntersectionObserver | |
| * | |
| * @example | |
| * ```tsx |
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
| /** | |
| * Construct a type in which only a single member of `T` is valid at a time. | |
| * | |
| * @example | |
| * ```ts | |
| * type U = OneOf< | |
| * | { | |
| * a: string; | |
| * } | |
| * | { |
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
| // 🚧 WIP 🚧 // | |
| /** | |
| * Get the first member of a tuple, {@linkcode T}, that is more or as specific | |
| * as the member following it. | |
| * | |
| * @example | |
| * ```ts | |
| * type Status = "success" | "error" | "idle" | |
| * type ActiveStatus = "success" | "error" |
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
| /** | |
| * Creates a new type that only includes properties from `T` that match the | |
| * structure defined in `M`. Useful for creating a subset of an object type | |
| * based on a mask/template type. Handles special cases for built-in objects | |
| * (Functions, Maps, Sets, Arrays) by preserving their structure rather than | |
| * attempting to deeply map their properties. | |
| * | |
| * | |
| * @example | |
| * ```ts |
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 { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; | |
| const currentPath = []; | |
| const csvRows = ["test_name,duration,passed,error,skipped,skip_message,logs"]; | |
| let pendingRow; | |
| let diagnostics = []; | |
| /** | |
| * A test reporter that formats results as CSV and uploads to S3. | |
| * @see https://nodejs.org/api/test.html#custom-reporters |
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
| /** | |
| * Get a superset of `T` that allows for arbitrary properties. | |
| * | |
| * @example | |
| * | |
| * ```ts | |
| * interface Order { | |
| * account: `0x${string}`; | |
| * amount: bigint; | |
| * } |
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
| /** | |
| * Get the length of a string. | |
| * | |
| * @example | |
| * ```ts | |
| * type L = Length<"hello">; // 5 | |
| * ``` | |
| */ | |
| type Length< | |
| T extends string, |