Attempts to get the path to the file that called the function that called this function.
npm i gist:b82256d70c5d9bed769b94a8d72bb38a| // 🚧 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" |
| /** | |
| * Construct a type in which only a single member of `T` is valid at a time. | |
| * | |
| * @example | |
| * ```ts | |
| * type U = OneOf< | |
| * | { | |
| * a: string; | |
| * } | |
| * | { |
| 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 |
| /** | |
| * Convert members of a union to an intersection. | |
| * | |
| * @example | |
| * ```ts | |
| * type Union = { a: number } | { b: string }; | |
| * type Intersection = UnionToIntersection<Union>; | |
| * // { a: number } & { b: string } | |
| * ``` | |
| * |
| /** | |
| * 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; |
| /** | |
| * 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]; | |
| }; |
| /** | |
| * Converts a hyphenated string to camel case. | |
| * | |
| * @example | |
| * camelCase('foo-bar') // 'fooBar' | |
| */ | |
| export function camelCase<S>(str: S): CamelCase<S> { | |
| return ( | |
| typeof str === 'string' | |
| ? str.toLowerCase().replace(/-+([^-])/g, (_, c) => c.toUpperCase()) |
| import os from "node:os"; | |
| import path from "node:path"; | |
| /** | |
| * Get the path to an app specific config directory based on operating system | |
| * standards. | |
| * @param projectName | |
| * @returns | |
| */ | |
| export function getOSConfigDir(projectName: string): string { |
| /** | |
| * Conducts a binary search on a sorted array of items to find the index of a | |
| * specific target. If the target is not found, it returns the nearest index | |
| * based on the comparator function. | |
| * | |
| * @param items - The sorted array of items to search within. | |
| * @param compare - A comparator function that returns: | |
| * - a negative number if `item` is less than the target, | |
| * - a positive number if `item` is greater than the target, | |
| * - and 0 if `item` is equal to the target. |