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 { useMemo, useReducer } from 'react'; | |
| const isProxy = Symbol('is_proxy'); | |
| function setNestedValue<T extends object>(obj: T, path: string, value: any): T { | |
| const parts = path.split('.'); | |
| let current: any = obj; | |
| for (let i = 0; i < parts.length; i++) { | |
| const part = parts[i]; |
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
| // Game setup | |
| type BoardPosition = [number, number]; | |
| type Space<Location extends BoardPosition, X extends BoardPosition[], Y extends BoardPosition[]> = Location extends X[number] ? 1 : Location extends Y[number] ? 2 : 0; | |
| type Board<X extends BoardPosition[], Y extends BoardPosition[]> = [ | |
| [Space<[0,0], X, Y>,Space<[0,1], X, Y>,Space<[0,2], X, Y>], | |
| [Space<[1,0], X, Y>,Space<[1,1], X, Y>,Space<[1,2], X, Y>], | |
| [Space<[2,0], X, Y>,Space<[2,1], X, Y>,Space<[2,2], X, Y>] |
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
| type DeepPartial<T> = Partial<{ | |
| [key in keyof T]: DeepPartial<T[key]> | ((obj: T[key]) => boolean) | |
| }> | ((obj: T) => boolean); | |
| type MatchHandlerFunc<T> = (obj: T) => void; | |
| interface IMatch<T> { | |
| when (matchObj: DeepPartial<T>, cb?: MatchHandlerFunc<T>): IMatch<T>; | |
| default (cb: MatchHandlerFunc<T>): IMatch<T>; | |
| evaluate (): 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
| /****************Data model type***************/ | |
| interface Endpoint< | |
| T_Path extends string = string, | |
| > { | |
| path: T_Path | |
| } | |
| // Examples |
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
| export type MaybeAbortablePromise<T> = AbortablePromise<T> | Promise<T>; | |
| export class AbortablePromise<T> implements PromiseLike<T> { | |
| readonly promise: Promise<T>; | |
| readonly abortController: AbortController; | |
| static resolve<T>(value: T, abortController?: AbortController): AbortablePromise<T>; | |
| static resolve(abortController?: AbortController): AbortablePromise<void>; | |
| static resolve<T>(value: T | undefined, abortController: AbortController = new AbortController()) { | |
| return new AbortablePromise(Promise.resolve(value), abortController) |
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
| type CompareNumbers< | |
| T extends number, | |
| U extends number, | |
| A extends any[] = [], | |
| > = T extends U | |
| ? 0 : A['length'] extends T | |
| ? -1 | |
| : A['length'] extends U | |
| ? 1 | |
| : CompareNumbers<T, U, ['a', ...A]> |
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
| /** | |
| * Exposes internal promise methods on the class that resolves a result of type T | |
| */ | |
| abstract class PromiseBuilder<T> implements Promise<T> { | |
| /** | |
| * Result to be returned when builder is resolved | |
| */ | |
| protected abstract _fetchResult(): Promise<T> |
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
| /** | |
| * The purpose of this decorator is to re-assign the default value when the incoming value is null or undefined. | |
| * This can be modified to ignore null or undefined as an incoming value. | |
| */ | |
| type UseDefaultOptions = { | |
| whenNull?: boolean; | |
| whenUndefined?: boolean; | |
| }; |
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
| npm r -g $(node -e "console.log(process.argv.filter((e) => e !== '├──' && e !== '└──').filter((_, i) => i > 1).map((e) => e.split('@')[0]).filter((e) => e !== 'npm').join(' '))" $(npm list -g -depth 0)) |
NewerOlder