/** * Given a set of `records` with known `columns`, format them into a pretty markdown table using the order from `columns`. * If a record does not have a specified value (it is null or undefined) it will be replaced with the `fallback` value. * * ```js * const table = formatMarkdownTable( * [ * { name: 'Geoff Testington', age: 42 }, * { name: "Jess Smith", age: 32 }, * { name: "Tyler Rockwell" }, * ], * ['name', 'age'], * '~' * ) * ``` * * Which will generate: * * ``` * | name | age | * | ---------------- | --- | * | Geoff Testington | 42 | * | Jess Smith | 32 | * | Tyler Rockwell | ~ | * ``` */ export declare function formatMarkdownTable>(records: T[], columns: (keyof T)[], fallback: string): string; /** * @unstable * * `loader` let's you memoize the result of a function to create a singleton from it. * It works synchronously or with promises. * * ```js * let index = 1 * const useMessage = loader(() = 'hello there ${i++}') * * useMessage() // hello there 1 * useMessage() // hello there 1 * useMessage() // hello there 1 * ``` */ export declare function loader(factory: () => T): () => T; /** * @internal * * `trimIndentation` takes a template literal (with values) and takes out the common whitespace. * Very heavily based on [dedent](https://github.com/dmnd/dedent/tree/main) * * ```js * import { trimIndentation } from "gruber"; * * console.log( * trimIndentation` * Hello there! * My name is Geoff * `, * ); * ``` * * Which will output this, without any extra whitespace: * * ``` * Hello there! * My name is Geoff * ``` * */ export declare function trimIndentation(input: string | TemplateStringsArray, ...args: unknown[]): string; /** * @internal * * Turn arguments from a string template literal back into a string * * ```js * // 'I have 2 dogs' * reconstructTemplateString(['I have ', ' dogs'], 2) * ``` * * or via template tags * * ```js * // 'I have 2 dogs' * reconstructTemplateString`I have ${2} dogs` * ``` */ export declare function reconstructTemplateString(input: string | TemplateStringsArray, ...args: unknown[]): string; /** * @internal * * A dynamic list of promises that are automatically removed when they resolve * * ```js * const list = new PromiseList() * * // Add a promise that waits for 5 seconds * list.push(async () => { * await new Promise(r => setTimeout(r, 5_000)) * * // Add dependant promises too * list.push(async () => { * await somethingElse() * }) * }) * * // Wait for all promises and dependants to resolve in one go * await promises.all() * * ``` */ export declare class PromiseList { #private; /** * Add a promise to the list using a factory method, * the `factory` just needs to return a promise * * ```js * list.push(async () => { * // ... * }) * ``` */ push(fn: () => Promise): void; /** * Wait for all promises to be resolved using `Promise.all`. * If new promises are added as a result of waiting, they are also awaited. * * ```js * await list.all() * ``` */ all(): Promise; /** * Get the current number of promises in the list * * ```js * list.length // 5 * ``` */ get length(): number; } /** * @unstable * * Take steps to prevent an object from being extracted from the app, * inspired by crypto.subtle.importKey's [extractable](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#extractable) parameter. * * This will: * - throw an error if the value are passed to JSON.stringify * - it recursively applies to nested objects, arrays and items within arrays * - [seal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) and [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) the value and all nested objects & arrays * * ```js * const config = preventExtraction({ * name: "Geoff Testington", * pets: [ * { name: "Hugo" }, * { name: "Helga" }, * ], * favourite: { * mountain: "Cheviot" * } * }) * * // Any attempt to JSON-ify will result in an error * console.log(JSON.stringify(config)) // throws a TypeError * console.log(JSON.stringify(config.pets)) // throws a TypeError * console.log(JSON.stringify(config.pets[0])) // throws a TypeError * console.log(JSON.stringify(config.pets[1])) // throws a TypeError * console.log(JSON.stringify(config.favourite)) // throws a TypeError * ``` * * The value will also be frozen and sealed, so any properties cannot be added, removed or modified. */ export declare function preventExtraction(input: T): T; /** * @unstable * * **DANGER** undo a {@link preventExtraction} to allow values to be exposed. * This removes all of the precations that `preventExtraction` add. * * ```js * console.log( * JSON.stringify( * dangerouslyExpose(appConfig.meta) * ) * ) * ``` */ export declare function dangerouslyExpose(input: T): T; export declare namespace dangerouslyExpose { var custom: symbol; } /** * Create a subset of an object by picking off specific keys * * ```js * const object = { * name: "Geoff Testington", * age: 42, * pets: ["Hugo", "Florence"] * } * pickProperties(object, ["name", "age"]) * ``` */ export declare function pickProperties(object: T, properties: K[]): { [P in K]: T[P]; }; /** * Polyfil for [Map#getOrInsert](https://github.com/tc39/proposal-upsert) * * ```js * let preferences = new Map() * let darkMode = getOrInsert(preferences, "use_dark_mode", true) * * let groups = new Map() * for (let value of array) { * getOrInsert(groups, value.theme, []).push(value) * } * ``` */ export declare function getOrInsert(map: Map, key: K, defaultValue: V): V; //# sourceMappingURL=utilities.d.ts.map