@clack/prompts
Advanced tools
Comparing version 0.0.4 to 0.0.5
# @clack/prompts | ||
## 0.0.5 | ||
### Patch Changes | ||
- Update README | ||
## 0.0.4 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@clack/prompts", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -16,2 +16,89 @@ # `@clack/prompts` | ||
## Basics | ||
### Setup | ||
The `intro` and `outro` functions will print a message to begin or end a prompt session, respectively. | ||
```js | ||
import { intro, outro } from "@clack/prompts"; | ||
intro(`create-my-app`); | ||
// Do stuff | ||
outro(`You're all set!`); | ||
``` | ||
### Cancellation | ||
The `isCancel` function is a guard that detects when a user cancels a question with `CTRL + C`. You should handle this situation for each prompt, optionally providing a nice cancellation message with the `cancel` utility. | ||
```js | ||
import { isCancel, cancel, text } from "@clack/prompts"; | ||
const value = await text(/* TODO */); | ||
if (isCancel(value)) { | ||
cancel("Operation cancelled."); | ||
process.exit(0); | ||
} | ||
``` | ||
## Components | ||
### Text | ||
The text component accepts a single line of text. | ||
```js | ||
import { text } from "@clack/prompts"; | ||
const meaning = await text({ | ||
message: "What is the meaning of life?", | ||
placeholder: "Not sure", | ||
validate(value) { | ||
if (value.length === 0) return `Value is required!`; | ||
}, | ||
}); | ||
``` | ||
### Confirm | ||
The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`. | ||
```js | ||
import { confirm } from "@clack/prompts"; | ||
const shouldContinue = await confirm({ | ||
message: "Do you want to continue?", | ||
}); | ||
``` | ||
### Select | ||
The select component allows a user to choose one value from a list of options. The result is the `value` prop of a given option. | ||
```js | ||
import { select } from "@clack/prompts"; | ||
const projectType = await select({ | ||
message: "Pick a project type.", | ||
options: [ | ||
{ value: "ts", label: "TypeScript" }, | ||
{ value: "js", label: "JavaScript" }, | ||
{ value: "coffee", label: "CoffeeScript", hint: "oh no" }, | ||
], | ||
}); | ||
``` | ||
### Spinner | ||
The spinner component surfaces a pending action, such as a long-running download or dependency installation. | ||
```js | ||
import { spinner } from "@clack/prompts"; | ||
const s = spinner(); | ||
s.start("Installing via npm"); | ||
// Do installation | ||
s.stop("Installed via npm"); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26751
104