From 1db3491711beed4acc3c69e873add015404a7d2e Mon Sep 17 00:00:00 2001 From: John Lindquist Date: Thu, 13 Feb 2025 11:00:33 -0700 Subject: [PATCH] fix(test): update regex for global matcher --- src/api/global.test.js | 88 +++-- src/types/kit.d.ts | 846 ++++++++++++++++++++++++++++------------- src/types/kitapp.d.ts | 329 ---------------- 3 files changed, 632 insertions(+), 631 deletions(-) diff --git a/src/api/global.test.js b/src/api/global.test.js index d10d0330..b8286b75 100644 --- a/src/api/global.test.js +++ b/src/api/global.test.js @@ -1,58 +1,56 @@ -import ava from "ava" -import "../../test-sdk/config.js" -import { pathToFileURL } from "node:url" +import ava from 'ava' +import '../../test-sdk/config.js' +import { pathToFileURL } from 'node:url' -ava.serial("env should work with different params", async (t) => { - let name = "mock-env-message" - let content = ` +ava.serial('env should work with different params', async (t) => { + let name = 'mock-env-message' + let content = ` await env("MOCK_ENV_MESSAGE", "Enter a value:") ` - let type = "js" + let type = 'js' - await exec(`kit new ${name} main --no-edit`, { - env: { - ...process.env, - KIT_NODE_PATH: process.execPath, - KIT_MODE: type - } - }) + await exec(`kit new ${name} main --no-edit`, { + env: { + ...process.env, + KIT_NODE_PATH: process.execPath, + KIT_MODE: type + } + }) - await appendFile(kenvPath("scripts", `${name}.js`), content) + await appendFile(kenvPath('scripts', `${name}.js`), content) - if (process.platform === "win32") { - name += ".cmd" - } + if (process.platform === 'win32') { + name += '.cmd' + } - let p = exec(`${kenvPath("bin", name)}`) + let p = exec(`${kenvPath('bin', name)}`) - p.stdin.write("Some value\n") + p.stdin.write('Some value\n') - let { stdout } = await p + let { stdout } = await p - t.regex(stdout, /env/) + t.regex(stdout, /env/) }) -ava.serial("All globals exist", async (t) => { - // TODO: Make platform independent... - /** @type {import("../platform/darwin")} */ - await import(pathToFileURL(kitPath("core", "utils.js")).href) - await import(pathToFileURL(kitPath("platform", "darwin.js")).href) - await import(pathToFileURL(kitPath("target", "app.js")).href) - await import(pathToFileURL(kitPath("api", "pro.js")).href) - await import(pathToFileURL(kitPath("index.js")).href) - - let files = await readdir(kitPath("types")) - let content = `` - for await (let f of files) { - content += await readFile(kitPath("types", f), "utf-8") - } - - let matches = content - .match(/(?<=var ).*?(?=:)/gim) - .filter((m) => !m.includes("projectPath")) - - for (let m of matches) { - t.log(`Checking if ${m} exists on global...`) - t.true(typeof global[m] !== "undefined", `${m} is missing`) - } +ava.serial('All globals exist', async (t) => { + // TODO: Make platform independent... + /** @type {import("../platform/darwin")} */ + await import(pathToFileURL(kitPath('core', 'utils.js')).href) + await import(pathToFileURL(kitPath('platform', 'darwin.js')).href) + await import(pathToFileURL(kitPath('target', 'app.js')).href) + await import(pathToFileURL(kitPath('api', 'pro.js')).href) + await import(pathToFileURL(kitPath('index.js')).href) + + let files = await readdir(kitPath('types')) + let content = `` + for await (let f of files) { + content += await readFile(kitPath('types', f), 'utf-8') + } + + let matches = content.match(/(?<=^\s*var ).*?(?=:)/gim).filter((m) => !m.includes('projectPath')) + + for (let m of matches) { + t.log(`Checking if ${m} exists on global...`) + t.true(typeof global[m] !== 'undefined', `${m} is missing`) + } }) diff --git a/src/types/kit.d.ts b/src/types/kit.d.ts index d20c0aff..de582b79 100644 --- a/src/types/kit.d.ts +++ b/src/types/kit.d.ts @@ -147,8 +147,94 @@ export type CreateGist = ( export type SetShortcuts = (shortcuts: Shortcut[]) => Promise export interface KitApi { - path: PathSelector - db: DB +/** + * The `path` prompt allows you to select a file or folder from the file system. You navigate with tab/shift+tab (or right/left arrows) and enter to select. + * 1. Optional: The first argument is the initial directory to open with. Defaults to the home directory. + * #### path example + * ```ts + * let selectedFile = await path() + * ``` + * @see https://johnlindquist.github.io/kit-docs/#path + */ +path: PathSelector +/** + * An extremely simple database that persists to a file. + * #### db hello world + * ```ts + * // Name: db-hello-world + * import "@johnlindquist/kit"; + * // Pre-populate the database with some items + * const peopleDb = await db({ + * people: [ + * { + * name: "John", + * age: 30, + * city: "San Francisco", + * }, + * { + * name: "Jane", + * age: 25, + * city: "New York", + * }, + * ] as Person[], + * }); + * const person = await arg("Select a person", peopleDb.people); + * // Do something with the person... + * const [name, age, city] = await fields({ + * fields: ["name", "age", "city"], + * enter: "Add", + * description: "Add a new person to the database", + * }); + * peopleDb.people.push({ name, age: parseInt(age), city }); + * await peopleDb.write(); + * await editor(JSON.stringify(peopleDb.people, null, 2)); + * type Person = { + * name: string; + * age: number; + * city: string; + * }; + * ``` + * #### db populate + * ```ts + * // Name: Populate db example + * // Description: Shows how to pre-populate database + * // Group: Data + * // Pass in a function to generate data for the db + * // Because this script is named "db-basic.js" + * // The database is found at "~/.kenv/db/_db-basic.json" + * import "@johnlindquist/kit"; + * let reposDb = await db(async () => { + * let response = await get("https://api.github.com/users/johnlindquist/repos"); + * return response.data.map(({ name, description, html_url }) => { + * return { + * name, + * description, + * value: html_url, + * }; + * }); + * }); + * let repoUrl = await arg("Select repo to open:", reposDb.items); + * exec(`open "${repoUrl}"`); + * ``` + * #### db store + * ```ts + * // Name: Database Read/Write Example + * // Description: Add/remove items from a list of fruit + * // Group: Data + * import "@johnlindquist/kit" + * let fruitDb = await db(["apple", "banana", "orange"]) + * while (true) { + * let fruitToAdd = await arg("Add a fruit", md(fruitDb.items.map(fruit => `* ${fruit}`).join("\n"))) + * fruitDb.items.push(fruitToAdd) + * await fruitDb.write() + * let fruitToDelete = await arg("Delete a fruit", fruitDb.items) + * fruitDb.items = fruitDb.items.filter(fruit => fruit !== fruitToDelete) + * await fruitDb.write() + * } + * ``` + * @see https://johnlindquist.github.io/kit-docs/#db + */ +db: DB wait: Wait @@ -167,21 +253,202 @@ export interface KitApi { isBin: IsCheck createPathResolver: PathResolver /** - * @example + * - Accept text input from the user. + * - Optionally provide a list of choices filtered by the text input. + * - Optionally provide a list of actions to trigger when the user presses a shortcut. + * 1. The first argument is a string or a prompt configuration object. + * 2. The second argument is a list of choices, a string to render, or a function that returns choices or a string to render. + * #### arg example + * ```ts + * let value = await arg() + * ``` + * #### arg basic string input + * ```ts + * let name = await arg("Enter your name") + * ``` + * #### arg with async choices object + * ```ts + * let person = await arg("Select a person", async () => { + * let response = await get("https://swapi.dev/api/people/"); + * // return an array of objects with "name", "value", and "description" properties + * return response?.data?.results.map((person) => { + * return { + * name: person.name, + * description: person.url, + * value: person + * } + * }); + * }) * ``` - * let value = await arg() + * #### arg with async choices + * ```ts + * let name = await arg("Select a name", async () => { + * let response = await get("https://swapi.dev/api/people/"); + * return response?.data?.results.map((p) => p.name); + * }) + * ``` + * #### arg with choices array + * ```ts + * let name = await arg("Select a name", [ + * "John", + * "Mindy", + * "Joy", + * ]) + * ``` + * #### arg with generated choices + * ```ts + * let char = await arg("Type then pick a char", (input) => { + * // return an array of strings + * return input.split("") + * }) + * ``` + * #### arg with shortcuts + * ```ts + * let url = "https://swapi.dev/api/people" + * let name = await arg({ + * placeholder: "Select a name", + * shortcuts: [ + * { + * name: "Explore API", + * key: "cmd+e", + * onPress: async () => { + * open(url) + * }, + * bar: "right" + * } + * ] + * }, async () => { + * let response = await get(url); + * return response?.data?.results.map((p) => p.name); + * }) * ``` + * @see https://johnlindquist.github.io/kit-docs/#arg */ arg: Arg - select: Select - mini: Arg - micro: Arg +/** + * Prompts the user to select one or more options. + * #### select example + * ```ts + * let multipleChoice = await select( + * "Select one or more developer", + * ["John", "Nghia", "Mindy", "Joy"] + * ) + * ``` + * #### select a choice with a single keystroke + * ```ts + * // Name: Single Keystroke Demo + * // Group: Prompt + * import "@johnlindquist/kit" + * let choice = await arg({ + * placeholder: "Choose a color", + * choices: [ + * { name: "[R]ed", value: "red" }, + * { name: "[G]reen", value: "green" }, + * { name: "[B]lue", value: "blue" }, + * ], + * }) + * await div(md(`You chose ${choice}`)) + * ``` + * #### select array object + * ```ts + * const people = [ + * { + * name: "John", + * description: "Full-stack Dev", + * value: "John", + * }, + * { + * name: "Nghia", + * description: "Full-stackoverflow dev", + * value: "Nghia", + * }, + * { + * name: "Mindy", + * description: "Business Analyst", + * value: "Mindy", + * }, + * { + * name: "Joy", + * description: "Leader", + * value: "Joy", + * }, + * ] + * let multipleChoice = await select( + * "Select one or more developer", + * people + * ) + * ``` + * #### select async choices array object + * ```ts + * let name = await select( + * "GET: NAME (please wait)", + * async () => { + * let response = await get( + * "https://swapi.dev/api/people/" + * ) + * return response?.data?.results.map(person => { + * return { + * name: person.name, + * description: `height: ${person.height}, mass: ${person.mass}`, + * value: person, + * preview: () => JSON.stringify(person), + * } + * }) + * } + * ) + * ``` + * #### select basic array input + * ```ts + * let multipleChoice = await select( + * "Select one or more developer", + * ["John", "Nghia", "Mindy", "Joy"] + * ) + * ``` + * #### select generated input choices + * ```ts + * let word = await select("Type then pick a words", input => { + * return input.trim().split(new RegExp("[.,;/-_\n]", "g")) + * }) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#select + */ +select: Select +/** + * Prompts the user for input in a compact format. + * #### mini example + * ```ts + * let name = await mini("Enter your name") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#mini + */ +mini: Arg +/** + * Prompts the user for input in a tiny, adorable format. + * #### micro example + * ```ts + * let name = await micro("Enter your name") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#micro + */ +micro: Arg /** - * @example + * Load an env var if it exists, prompt to set the env var if not: + * You can also prompt the user to set the env var using a prompt by nesting it in an async function: + * #### env example + * ```ts + * // Write write "MY_ENV_VAR" to ~/.kenv/.env + * let MY_ENV_VAR = await env("MY_ENV_VAR") * ``` - * // Reads from .env or prompts if not set - * let SOME_ENV_VAR = await env("SOME_ENV_VAR") + * #### env example with prompt + * ```ts + * // Prompt the user to select from a path + * let OUTPUT_DIR = await env("OUTPUT_DIR", async () => { + * return await path({ + * hint: `Select the output directory`, + * }) + * }) * ``` + * @see https://johnlindquist.github.io/kit-docs/#env */ env: Env argOpts: string[] @@ -199,14 +466,53 @@ export interface KitApi { tmpPath: PathFn kenvTmpPath: PathFn + /** + * `inspect` takes an object and writes out a text file you can use to read/copy/paste the values from: + * > Note: It will automatically convert objects to JSON to display them in the file + * #### inspect example + * ```ts + * let response = await get("https://swapi.dev/api/people/1/") + * await inspect(response.data) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#inspect + */ inspect: Inspect onTab: OnTab onExit: OnExit + /** + * Attempts to import a module. + * #### attemptImport example + * ```ts + * let module = await attemptImport("lodash") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#attemptimport + */ attemptImport: KitModuleLoader - silentAttemptImport: KitModuleLoader - npm: KitModuleLoader +/** + * Attempts to import a module silently. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### silentAttemptImport example + * ```ts + * let module = await silentAttemptImport("lodash") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#silentattemptimport + */ +silentAttemptImport: KitModuleLoader +/** + * > Deprecated: Use standard `import` instead. + * Installs an npm package. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### npm example + * ```ts + * await npm("lodash") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#npm + */ +npm: KitModuleLoader setup: KitModuleLoader edit: Edit @@ -231,6 +537,15 @@ export interface KitApi { getScripts: GetScripts + /** + * Manages a memory map of objects. + * #### memoryMap example + * ```ts + * memoryMap.set("myKey", { myObject: true }) + * let value = memoryMap.get("myKey") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#memorymap + */ memoryMap: Map selectKitEditor: SelectKitEditor @@ -244,7 +559,25 @@ export interface KitApi { selectKenv: SelectKenv highlight: Highlight projectPath: PathFn - createGist: CreateGist +/** + * Creates a GitHub gist. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### createGist example + * ```ts + * let gistUrl = await createGist({ + * description: "My awesome gist", + * public: true, + * files: { + * "hello.txt": { + * content: "Hello, world!" + * } + * } + * }) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#creategist + */ +createGist: CreateGist setShortcuts: SetShortcuts isWin: boolean isMac: boolean @@ -263,16 +596,16 @@ export type Run = (command?: string, ...args: string[]) => Promise type Utils = typeof import('../core/utils') declare global { - /** - * The `path` prompt allows you to select a file or folder from the file system. You navigate with tab/shift+tab (or right/left arrows) and enter to select. - * 1. Optional: The first argument is the initial directory to open with. Defaults to the home directory. - * #### path example - * ```ts - * let selectedFile = await path() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#path - */ - var path: PathSelector +/** + * The `path` prompt allows you to select a file or folder from the file system. You navigate with tab/shift+tab (or right/left arrows) and enter to select. + * 1. Optional: The first argument is the initial directory to open with. Defaults to the home directory. + * #### path example + * ```ts + * let selectedFile = await path() + * ``` + * @see https://johnlindquist.github.io/kit-docs/#path + */ +var path: PathSelector var edit: Edit var browse: Browse @@ -290,18 +623,17 @@ declare global { * @see https://johnlindquist.github.io/kit-docs/#attemptimport */ var attemptImport: KitModuleLoader - /** - * Attempts to import a module silently. - * - Only tested on macOS - * - May require additional permissions or configurations - * #### silentAttemptImport example - * ```ts - * let module = await silentAttemptImport("lodash") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#silentattemptimport - */ - var silentAttemptImport: KitModuleLoader - /** @deprecated Use standard or dynamic imports instead. */ +/** + * Attempts to import a module silently. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### silentAttemptImport example + * ```ts + * let module = await silentAttemptImport("lodash") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#silentattemptimport + */ +var silentAttemptImport: KitModuleLoader /** * > Deprecated: Use standard `import` instead. * Installs an npm package. @@ -339,198 +671,198 @@ declare global { * @see https://johnlindquist.github.io/kit-docs/#env */ var env: Env - /** - * - Accept text input from the user. - * - Optionally provide a list of choices filtered by the text input. - * - Optionally provide a list of actions to trigger when the user presses a shortcut. - * 1. The first argument is a string or a prompt configuration object. - * 2. The second argument is a list of choices, a string to render, or a function that returns choices or a string to render. - * #### arg example - * ```ts - * let value = await arg() - * ``` - * #### arg basic string input - * ```ts - * let name = await arg("Enter your name") - * ``` - * #### arg with async choices object - * ```ts - * let person = await arg("Select a person", async () => { - * let response = await get("https://swapi.dev/api/people/"); - * // return an array of objects with "name", "value", and "description" properties - * return response?.data?.results.map((person) => { - * return { - * name: person.name, - * description: person.url, - * value: person - * } - * }); - * }) - * ``` - * #### arg with async choices - * ```ts - * let name = await arg("Select a name", async () => { - * let response = await get("https://swapi.dev/api/people/"); - * return response?.data?.results.map((p) => p.name); - * }) - * ``` - * #### arg with choices array - * ```ts - * let name = await arg("Select a name", [ - * "John", - * "Mindy", - * "Joy", - * ]) - * ``` - * #### arg with generated choices - * ```ts - * let char = await arg("Type then pick a char", (input) => { - * // return an array of strings - * return input.split("") - * }) - * ``` - * #### arg with shortcuts - * ```ts - * let url = "https://swapi.dev/api/people" - * let name = await arg({ - * placeholder: "Select a name", - * shortcuts: [ - * { - * name: "Explore API", - * key: "cmd+e", - * onPress: async () => { - * open(url) - * }, - * bar: "right" - * } - * ] - * }, async () => { - * let response = await get(url); - * return response?.data?.results.map((p) => p.name); - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#arg - */ - var arg: Arg - /** - * Prompts the user to select one or more options. - * #### select example - * ```ts - * let multipleChoice = await select( - * "Select one or more developer", - * ["John", "Nghia", "Mindy", "Joy"] - * ) - * ``` - * #### select a choice with a single keystroke - * ```ts - * // Name: Single Keystroke Demo - * // Group: Prompt - * import "@johnlindquist/kit" - * let choice = await arg({ - * placeholder: "Choose a color", - * choices: [ - * { name: "[R]ed", value: "red" }, - * { name: "[G]reen", value: "green" }, - * { name: "[B]lue", value: "blue" }, - * ], - * }) - * await div(md(`You chose ${choice}`)) - * ``` - * #### select array object - * ```ts - * const people = [ - * { - * name: "John", - * description: "Full-stack Dev", - * value: "John", - * }, - * { - * name: "Nghia", - * description: "Full-stackoverflow dev", - * value: "Nghia", - * }, - * { - * name: "Mindy", - * description: "Business Analyst", - * value: "Mindy", - * }, - * { - * name: "Joy", - * description: "Leader", - * value: "Joy", - * }, - * ] - * let multipleChoice = await select( - * "Select one or more developer", - * people - * ) - * ``` - * #### select async choices array object - * ```ts - * let name = await select( - * "GET: NAME (please wait)", - * async () => { - * let response = await get( - * "https://swapi.dev/api/people/" - * ) - * return response?.data?.results.map(person => { - * return { - * name: person.name, - * description: `height: ${person.height}, mass: ${person.mass}`, - * value: person, - * preview: () => JSON.stringify(person), - * } - * }) - * } - * ) - * ``` - * #### select basic array input - * ```ts - * let multipleChoice = await select( - * "Select one or more developer", - * ["John", "Nghia", "Mindy", "Joy"] - * ) - * ``` - * #### select generated input choices - * ```ts - * let word = await select("Type then pick a words", input => { - * return input.trim().split(new RegExp("[.,;/-_\n]", "g")) - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#select - */ - var select: Select - /** - * Prompts the user to select one or more options in a grid layout. - * #### grid example - * ```ts - * let multipleChoice = await grid( - * "Select one or more developer", - * ["John", "Nghia", "Mindy", "Joy"] - * ) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#grid - */ - var grid: Grid +/** + * - Accept text input from the user. + * - Optionally provide a list of choices filtered by the text input. + * - Optionally provide a list of actions to trigger when the user presses a shortcut. + * 1. The first argument is a string or a prompt configuration object. + * 2. The second argument is a list of choices, a string to render, or a function that returns choices or a string to render. + * #### arg example + * ```ts + * let value = await arg() + * ``` + * #### arg basic string input + * ```ts + * let name = await arg("Enter your name") + * ``` + * #### arg with async choices object + * ```ts + * let person = await arg("Select a person", async () => { + * let response = await get("https://swapi.dev/api/people/"); + * // return an array of objects with "name", "value", and "description" properties + * return response?.data?.results.map((person) => { + * return { + * name: person.name, + * description: person.url, + * value: person + * } + * }); + * }) + * ``` + * #### arg with async choices + * ```ts + * let name = await arg("Select a name", async () => { + * let response = await get("https://swapi.dev/api/people/"); + * return response?.data?.results.map((p) => p.name); + * }) + * ``` + * #### arg with choices array + * ```ts + * let name = await arg("Select a name", [ + * "John", + * "Mindy", + * "Joy", + * ]) + * ``` + * #### arg with generated choices + * ```ts + * let char = await arg("Type then pick a char", (input) => { + * // return an array of strings + * return input.split("") + * }) + * ``` + * #### arg with shortcuts + * ```ts + * let url = "https://swapi.dev/api/people" + * let name = await arg({ + * placeholder: "Select a name", + * shortcuts: [ + * { + * name: "Explore API", + * key: "cmd+e", + * onPress: async () => { + * open(url) + * }, + * bar: "right" + * } + * ] + * }, async () => { + * let response = await get(url); + * return response?.data?.results.map((p) => p.name); + * }) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#arg + */ +var arg: Arg +/** + * Prompts the user to select one or more options. + * #### select example + * ```ts + * let multipleChoice = await select( + * "Select one or more developer", + * ["John", "Nghia", "Mindy", "Joy"] + * ) + * ``` + * #### select a choice with a single keystroke + * ```ts + * // Name: Single Keystroke Demo + * // Group: Prompt + * import "@johnlindquist/kit" + * let choice = await arg({ + * placeholder: "Choose a color", + * choices: [ + * { name: "[R]ed", value: "red" }, + * { name: "[G]reen", value: "green" }, + * { name: "[B]lue", value: "blue" }, + * ], + * }) + * await div(md(`You chose ${choice}`)) + * ``` + * #### select array object + * ```ts + * const people = [ + * { + * name: "John", + * description: "Full-stack Dev", + * value: "John", + * }, + * { + * name: "Nghia", + * description: "Full-stackoverflow dev", + * value: "Nghia", + * }, + * { + * name: "Mindy", + * description: "Business Analyst", + * value: "Mindy", + * }, + * { + * name: "Joy", + * description: "Leader", + * value: "Joy", + * }, + * ] + * let multipleChoice = await select( + * "Select one or more developer", + * people + * ) + * ``` + * #### select async choices array object + * ```ts + * let name = await select( + * "GET: NAME (please wait)", + * async () => { + * let response = await get( + * "https://swapi.dev/api/people/" + * ) + * return response?.data?.results.map(person => { + * return { + * name: person.name, + * description: `height: ${person.height}, mass: ${person.mass}`, + * value: person, + * preview: () => JSON.stringify(person), + * } + * }) + * } + * ) + * ``` + * #### select basic array input + * ```ts + * let multipleChoice = await select( + * "Select one or more developer", + * ["John", "Nghia", "Mindy", "Joy"] + * ) + * ``` + * #### select generated input choices + * ```ts + * let word = await select("Type then pick a words", input => { + * return input.trim().split(new RegExp("[.,;/-_\n]", "g")) + * }) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#select + */ +var select: Select +/** + * Prompts the user to select one or more options in a grid layout. + * #### grid example + * ```ts + * let multipleChoice = await grid( + * "Select one or more developer", + * ["John", "Nghia", "Mindy", "Joy"] + * ) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#grid + */ +var grid: Grid var basePrompt: Arg - /** - * Prompts the user for input in a compact format. - * #### mini example - * ```ts - * let name = await mini("Enter your name") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#mini - */ - var mini: Arg - /** - * Prompts the user for input in a tiny, adorable format. - * #### micro example - * ```ts - * let name = await micro("Enter your name") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#micro - */ - var micro: Arg +/** + * Prompts the user for input in a compact format. + * #### mini example + * ```ts + * let name = await mini("Enter your name") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#mini + */ +var mini: Arg +/** + * Prompts the user for input in a tiny, adorable format. + * #### micro example + * ```ts + * let name = await micro("Enter your name") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#micro + */ +var micro: Arg var onTab: OnTab var onExit: OnExit var args: Args @@ -636,18 +968,18 @@ declare global { * @see https://johnlindquist.github.io/kit-docs/#db */ var db: DB - /** - * Stores data in a persistent key-value store. - * - Only tested on macOS - * - May require additional permissions or configurations - * #### store example - * ```ts - * await store.set("myKey", "myValue") - * let value = await store.get("myKey") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#store - */ - var store: Store +/** + * Stores data in a persistent key-value store. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### store example + * ```ts + * await store.set("myKey", "myValue") + * let value = await store.get("myKey") + * ``` + * @see https://johnlindquist.github.io/kit-docs/#store + */ +var store: Store /** * Manages a memory map of objects. @@ -685,25 +1017,25 @@ declare global { var projectPath: PathFn var clearAllTimeouts: () => void var clearAllIntervals: () => void - /** - * Creates a GitHub gist. - * - Only tested on macOS - * - May require additional permissions or configurations - * #### createGist example - * ```ts - * let gistUrl = await createGist({ - * description: "My awesome gist", - * public: true, - * files: { - * "hello.txt": { - * content: "Hello, world!" - * } - * } - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#creategist - */ - var createGist: CreateGist +/** + * Creates a GitHub gist. + * - Only tested on macOS + * - May require additional permissions or configurations + * #### createGist example + * ```ts + * let gistUrl = await createGist({ + * description: "My awesome gist", + * public: true, + * files: { + * "hello.txt": { + * content: "Hello, world!" + * } + * } + * }) + * ``` + * @see https://johnlindquist.github.io/kit-docs/#creategist + */ +var createGist: CreateGist var setShortcuts: SetShortcuts var isWin: boolean var isMac: boolean diff --git a/src/types/kitapp.d.ts b/src/types/kitapp.d.ts index 00627913..7fc67550 100644 --- a/src/types/kitapp.d.ts +++ b/src/types/kitapp.d.ts @@ -988,153 +988,14 @@ export interface HideOptions { } declare global { var textarea: TextArea - /** - * Use `await drop()` to prompt the user to drop a file or folder. - * #### drop example - * ```ts - * // Note: Dropping one or more files returns an array of file information - * // Dropping text or an image from the browser returns a string - * let fileInfos = await drop() - * let filePaths = fileInfos.map(f => f.path).join(",") - * await div(md(filePaths)) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#drop - */ var drop: Drop - /** - * `div` displays HTML. Pass a string of HTML to `div` to render it. `div` is commonly used in conjunction with `md` to render markdown. - * 1. Just like arg, the first argument is a string or a prompt configuration object. - * 2. Optional:The second argument is a string of tailwind class to apply to the container, e.g., `bg-white p-4`. - * #### div example - * ```ts - * await div(`Hello world!`) - * ``` - * #### div with markdown - * ```ts - * await div(md(` - * # example! - * @see https://johnlindquist.github.io/kit-docs/#div - */ var div: Div - /** - * Use an HTML form which returns an Object based on the names of the form fields. - * #### form example - * ```ts - * let result = await form(` - *
- * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
- * `) - * inspect(result) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#form - */ var form: Form - /** - * The `fields` prompt allows you to rapidly create a form with fields. - * 1. An array of labels or objects with label and field properties. - * #### fields example - * ```ts - * let [first, last] = await fields(["First name", "Last name"]) - * ``` - * #### fields with field properties - * ```ts - * let [name, age] = await fields([ - * { - * name: "name", - * label: "Name", - * type: "text", - * placeholder: "John" - * }, - * { - * name: "age", - * label: "Age", - * type: "number", - * placeholder: "40" - * } - * ]) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#fields - */ var fields: Fields var emoji: Emoji - /** - * The `editor` function opens a text editor with the given text. The editor is a full-featured "Monaco" editor with syntax highlighting, find/replace, and more. The editor is a great way to edit or update text to write a file. The default language is markdown. - * #### editor example - * ```ts - * let content = await editor() - * ``` - * #### editor load remote text content - * ```ts - * let response = await get(`https://raw.githubusercontent.com/johnlindquist/kit/main/API.md`) - * let content = await editor(response.data) - * ``` - * #### editor with initial content - * ```ts - * let content = await editor("Hello world!") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#editor - */ var editor: Editor - /** - * The `template` prompt will present the editor populated by your template. You can then tab through each variable in your template and edit it. - * 1. The first argument is a string template. Add variables using $1, $2, etc. You can also use - * [//]: # (\${1:default value} to set a default value.)) - * #### template example - * ```ts - * let text = await template(`Hello $1!`) - * ``` - * #### template standard usage - * ```ts - * let text = await template(` - * Dear \${1:name}, - * Please meet me at \${2:address} - * Sincerely, John`) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#template - */ var template: Template - /** - * The `hotkey` prompt allows you to press modifier keys, then submits once you've pressed a non-monodifier key. For example, press `command` then `e` to submit key info about the `command` and `e` keys: - * ```json - * { - * "key": "e", - * "command": true, - * "shift": false, - * "option": false, - * "control": false, - * "fn": false, - * "hyper": false, - * "os": false, - * "super": false, - * "win": false, - * "shortcut": "command e", - * "keyCode": "KeyE" - * } - * ``` - * This can be useful when you want to use a palette of commands and trigger each of them by switching on a hotkey. - * 1. Optional: The first argument is a string to display in the prompt. - * #### hotkey example - * ```ts - * let keyInfo = await hotkey() - * await editor(JSON.stringify(keyInfo, null, 2)) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#hotkey - */ var hotkey: Hotkey var send: Send var sendWait: (channel: Channel, value?: any, timeout?: number) => Promise @@ -1145,14 +1006,6 @@ declare global { var setFocused: SetFocused var setEnter: SetEnter var setPlaceholder: SetPlaceholder - /** - * Sets the panel content. - * #### setPanel example - * ```ts - * await setPanel("

Hello, world!

") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#setpanel - */ var setPanel: SetPanel var setFooter: SetFooter var addChoice: AddChoice @@ -1161,23 +1014,7 @@ declare global { var setFormData: SetFormData var clearTabs: () => void var setDiv: SetPanel - /** - * Sets the preview content. - * #### setPreview example - * ```ts - * await setPreview("

Preview

") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#setpreview - */ var setPreview: SetPreview - /** - * Sets the prompt content. - * #### setPrompt example - * ```ts - * await setPrompt("

Enter your name:

") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#setprompt - */ var setPrompt: SetPrompt var setBounds: SetBounds var getBounds: GetBounds @@ -1190,96 +1027,26 @@ declare global { var scrollTo: ScrollTo var setFilterInput: SetInput var setTextareaValue: SetTextareaValue - /** - * Sets whether to ignore blur events. - * #### setIgnoreBlur example - * ```ts - * await setIgnoreBlur(true) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#setignoreblur - */ var setIgnoreBlur: SetIgnoreBlur var setResize: SetResize var setPauseResize: SetResize var setLoading: SetLoading var setProgress: SetProgress var setRunning: SetLoading - /** - * Set the system menu bar icon and message. - * Each status message will be appended to a list. - * Clicking on the menu will display the list of messages. - * The status and messages will be dismissed once the tray closes, so use `log` if you want to persist messages. - * #### setStatus example - * ```ts - * await setStatus({ - * message: "Working on it...", - * status: "busy", - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#setstatus - */ var setStatus: SetStatus var setTheme: SetTheme var setScriptTheme: SetTheme var showImage: ShowAppWindow - /** - * Shows the main prompt. - * #### show example - * ```ts - * await show() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#show - */ var show: () => Promise - /** - * Hides the main prompt. - * #### hide example - * ```ts - * await hide() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#hide - */ var hide: (hideOptions?: HideOptions) => Promise var blur: () => Promise - /** - * `dev` Opens a standalone instance of Chrome Dev Tools so you can play with JavaScript in the console. Passing in an object will set the variable `x` to your object in the console making it easy to inspect. - * 1. Optional: the first argument is an object to set to the variable `x` to in the console. - * #### dev example - * ```ts - * dev() - * ``` - * #### dev with object - * ```ts - * dev({ - * name: "John", - * age: 40 - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#dev - */ var dev: (object?: any) => Promise var getClipboardHistory: () => Promise - /** - * Clears the clipboard history. - * #### clearClipboardHistory example - * ```ts - * await clearClipboardHistory() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#clearclipboardhistory - */ var clearClipboardHistory: () => Promise var getEditorHistory: GetEditorHistory - /** - * Removes an item from the clipboard. - * #### removeClipboardItem example - * ```ts - * await removeClipboardItem(item) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#removeclipboarditem - */ var removeClipboardItem: (id: string) => Promise var setTab: (tabName: string) => void var submit: Submit @@ -1309,65 +1076,8 @@ declare global { var eyeDropper: () => Promise<{ sRGBHex: string }> - /** - * A chat prompt. Use `chat.addMessage()` to insert messages into the chat. - * > Note: Manually invoke `submit` inside of a shortcut/action/etc to end the chat. - * Also see the included "chatgpt" example for a much more advanced scenario. - * #### chat example - * ```ts - * // Name: Testing Chat - * import "@johnlindquist/kit" - * await chat({ - * onInit: async () => { - * chat.addMessage({ - * // Note: text and position are implemented, there are other properties that are a WIP - * text: "You like Script Kit", - * position: "left", - * }) - * await wait(1000) - * chat.addMessage({ - * text: "Yeah! It's awesome!", - * position: "right", - * }) - * await wait(1000) - * chat.addMessage({ - * text: "I know, right?!?", - * position: "left", - * }) - * await wait(1000) - * chat.addMessage({ - * text: ``, - * position: "right", - * }) - * }, - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#chat - */ var chat: Chat - /** - * Displays a small pop-up notification inside the Script Kit window. - * #### toast example - * ```ts - * await toast("Hello from Script Kit!", { - * autoClose: 3000, // close after 3 seconds - * pauseOnFocusLoss: false - * }) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#toast - */ var toast: Toast - /** - * A file search prompt - * #### find example - * ```ts - * let filePath = await find("Search in the Downloads directory", { - * onlyin: home("Downloads"), - * }) - * await revealFile(filePath) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#find - */ var find: Find var mic: Mic /** @@ -1377,37 +1087,9 @@ declare global { * @returns A Promise that resolves to a Buffer containing the screenshot data. */ var screenshot: Screenshot - /** - * Prompt for webcam access. Press enter to capture an image buffer: - * ## Alerts - * #### webcam example - * ```ts - * let buffer = await webcam() - * let imagePath = tmpPath("image.jpg") - * await writeFile(imagePath, buffer) - * await revealFile(imagePath) - * ``` - * @see https://johnlindquist.github.io/kit-docs/#webcam - */ var webcam: WebCam var prompt: Prompt - /** - * Retrieves available media devices. - * #### getMediaDevices example - * ```ts - * let devices = await getMediaDevices() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#getmediadevices - */ var getMediaDevices: GetMediaDevices - /** - * Retrieves typed text from the user. - * #### getTypedText example - * ```ts - * let text = await getTypedText() - * ``` - * @see https://johnlindquist.github.io/kit-docs/#gettypedtext - */ var getTypedText: GetTypedText var PROMPT: typeof PROMPT_OBJECT var preventSubmit: symbol @@ -1456,16 +1138,5 @@ declare global { var getTheme: () => Promise - /** - * Send a system notification - * > Note: osx notifications require permissions for "Terminal Notifier" in the system preferences. Due to the complicated nature of configuring notifications, please use a search engine to find the latest instructions for your osx version. - * > In the Script Kit menu bar icon: "Permissions -> Request Notification Permissions" might help. - * ## Widget - * #### notify example - * ```ts - * await notify("Attention!") - * ``` - * @see https://johnlindquist.github.io/kit-docs/#notify - */ var notify: Notify }