Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poppinss/prompts

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poppinss/prompts - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

3

build/src/Base.d.ts

@@ -1,4 +0,1 @@

/**
* @module @poppinss/prompts
*/
/// <reference types="node" />

@@ -5,0 +2,0 @@ import { EventEmitter } from 'events';

10

build/src/Base.js
"use strict";
/**
* @module @poppinss/prompts
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Prompt = exports.icons = void 0;
/*

@@ -15,5 +10,10 @@ * @poppinss/prompts

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Prompt = exports.icons = void 0;
const events_1 = require("events");
const colors_1 = require("@poppinss/colors");
const ObjectBuilder_1 = require("./ObjectBuilder");
/**
* Colors and icons to use.
*/
const colors = new colors_1.Colors();

@@ -20,0 +20,0 @@ exports.icons = process.platform === 'win32' ? { pointer: '>' } : { pointer: '❯' };

/**
* @module @poppinss/prompts
*/
/**
* The state of prompt shared with the validate function

@@ -6,0 +3,0 @@ */

"use strict";
/**
* @module @poppinss/prompts
/*
* @poppinss/prompts
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,4 +0,1 @@

/**
* @module @poppinss/prompts
*/
import { Prompt } from './Base';

@@ -5,0 +2,0 @@ /**

"use strict";
/**
* @module @poppinss/prompts
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmitterPrompt = void 0;
/*

@@ -15,2 +10,4 @@ * @poppinss/prompts

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmitterPrompt = void 0;
const Base_1 = require("./Base");

@@ -17,0 +14,0 @@ /**

@@ -1,4 +0,1 @@

/**
* @module @poppinss/prompts
*/
import { Prompt } from './Base';

@@ -5,0 +2,0 @@ /**

"use strict";
/**
* @module @poppinss/prompts
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnquirerPrompt = void 0;
/*

@@ -18,2 +10,7 @@ * @poppinss/prompts

*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnquirerPrompt = void 0;
const enquirer_1 = __importDefault(require("enquirer"));

@@ -20,0 +17,0 @@ const Base_1 = require("./Base");

# The MIT License
Copyright 2019 Harminder virk, contributors
Copyright 2020 Harminder virk, contributors

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "@poppinss/prompts",
"version": "1.1.2",
"version": "1.1.3",
"description": "Module on top of enquirer with API to fake prompts during testing",

@@ -15,3 +15,2 @@ "main": "build/index.js",

"test": "node japaFile.js",
"lint": "eslint . --ext=.ts",
"clean": "del build",

@@ -23,3 +22,6 @@ "compile": "npm run lint && npm run clean && tsc",

"version": "npm run build",
"format": "prettier --write ."
"format": "prettier --write .",
"prepublishOnly": "npm run build",
"lint": "eslint . --ext=.ts",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json poppinss/prompts"
},

@@ -41,4 +43,4 @@ "repository": {

"devDependencies": {
"@adonisjs/mrm-preset": "^2.3.4",
"@types/node": "^14.0.14",
"@adonisjs/mrm-preset": "^2.4.0",
"@types/node": "^14.0.23",
"commitizen": "^4.1.2",

@@ -48,13 +50,15 @@ "cz-conventional-changelog": "^3.2.0",

"doctoc": "^1.4.0",
"eslint": "^7.3.1",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-adonis": "^1.0.14",
"eslint-plugin-prettier": "^3.1.4",
"github-label-sync": "^2.0.0",
"husky": "^4.2.5",
"japa": "^3.1.1",
"mrm": "^2.3.3",
"np": "^6.2.5",
"np": "^6.3.2",
"npm-audit-html": "^1.4.1",
"prettier": "^2.0.5",
"ts-node": "^8.10.2",
"typescript": "^3.9.6"
"typescript": "^3.9.7"
},

@@ -71,3 +75,3 @@ "nyc": {

"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md",
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md && npm audit --production --json | ./node_modules/.bin/npm-audit-html && git add npm-audit.html",
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"

@@ -86,5 +90,5 @@ }

"dependencies": {
"@poppinss/colors": "^2.0.0",
"@poppinss/colors": "^2.0.1",
"enquirer": "^2.3.6"
}
}

@@ -0,7 +1,9 @@

<div align="center"><img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px"></div>
# Prompts
> Module on top of [enquirer](https://github.com/enquirer/enquirer) with API for testing as well.
[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![audit-report-image]][audit-report-url]
[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
This module wraps [enquirer](https://github.com/enquirer/enquirer) and exposes the API to easily test prompts without pulling your hair.

@@ -21,10 +23,10 @@

- [Implemented Prompt types](#implemented-prompt-types)
- [ask(title: string, options?: TextPromptOptions)](#asktitle-string-options-textpromptoptions)
- [secure(title: string, options?: TextPromptOptions)](#securetitle-string-options-textpromptoptions)
- [confirm(title: string, options?: BooleanPromptOptions)](#confirmtitle-string-options-booleanpromptoptions)
- [toggle(title: string, choices: [string, string], options?: TogglePromptOptions)](#toggletitle-string-choices-string-string-options-togglepromptoptions)
- [choice(title: string, choices: (string | {})[], options?: ChoicePromptOptions)](#choicetitle-string-choices-string---options-choicepromptoptions)
- [multiple(title: string, choices: (string | {})[], options?: MultiplePromptOptions)](#multipletitle-string-choices-string---options-multiplepromptoptions)
- [autocomplete(title: string, choices: string[], options?: AutoCompletePromptOptions)](#autocompletetitle-string-choices-string-options-autocompletepromptoptions)
- [enum(title: string, options?: EnumPromptOptions)](#enumtitle-string-options-enumpromptoptions)
- [`ask(title: string, options?: TextPromptOptions)`](#asktitle-string-options-textpromptoptions)
- [`secure(title: string, options?: TextPromptOptions)`](#securetitle-string-options-textpromptoptions)
- [`confirm(title: string, options?: BooleanPromptOptions)`](#confirmtitle-string-options-booleanpromptoptions)
- [`toggle(title: string, choices: [string, string], options?: TogglePromptOptions)`](#toggletitle-string-choices-string-string-options-togglepromptoptions)
- [`choice(title: string, choices: (string | {})[], options?: ChoicePromptOptions)`](#choicetitle-string-choices-string---options-choicepromptoptions)
- [`multiple(title: string, choices: (string | {})[], options?: MultiplePromptOptions)`](#multipletitle-string-choices-string---options-multiplepromptoptions)
- [`autocomplete(title: string, choices: string[], options?: AutoCompletePromptOptions)`](#autocompletetitle-string-choices-string-options-autocompletepromptoptions)
- [`enum(title: string, options?: EnumPromptOptions)`](#enumtitle-string-options-enumpromptoptions)

@@ -34,4 +36,5 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Why use this module?
When using [enquirer](https://github.com/enquirer/enquirer), there is no simple way to test your code that makes use of prompts, since prompts needs manual intervention. This module ships with a parallel implementation that uses the Event emitter to write tests for prompts. For example:
When using [enquirer](https://github.com/enquirer/enquirer), there is no simple way to test your code that makes use of prompts as prompts needs manual intervention. This module ships with a parallel implementation that uses the Event emitter to interact with prompts programmatically. For example:
You want to test a command that asks for the **username** and **password** and this is how you may go about writing it.

@@ -41,7 +44,7 @@

class MyCommand {
constructor (prompt) {
constructor(prompt) {
this.prompt = prompt
}
async run () {
async run() {
const username = await this.prompt.ask('Enter account username', { name: 'username' })

@@ -61,7 +64,7 @@ const password = await this.prompt.ask('Enter account password', { name: 'password' })

prompt.on('prompt', (prompt) => {
if (prompt.name === 'username') {
prompt.answer('virk')
prompt.on('prompt', (question) => {
if (question.name === 'username') {
question.answer('virk')
} else {
prompt.answer('secret-password')
question.answer('secret-password')
}

@@ -77,2 +80,3 @@ })

## Installation
Install the package from the npm registry as follows:

@@ -101,5 +105,9 @@

## Implemented Prompt types
The following prompt types from enquirer are implemented. The method names exposed by this module are different (my personal preference).
#### ask(title: string, options?: TextPromptOptions)
---
### `ask(title: string, options?: TextPromptOptions)`
Uses the `input` prompt type. Optionally you can define the following options.

@@ -114,12 +122,27 @@

await prompt.ask('Choose account username', {
validate (answer) {
if (!answer || answer.length < 6) {
return 'Username is required and must be over 6 characters'
validate(answer) {
if (!answer || answer.length < 4) {
return 'Username is required and must be over 4 characters'
}
return true
}
},
})
```
#### secure(title: string, options?: TextPromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Choose account username')
question.answer('virk')
})
const username = await prompt.ask('Choose account username')
assert.equal(username, 'virk')
```
---
### `secure(title: string, options?: TextPromptOptions)`
Uses the `password` prompt type. You can define the same options as the `ask` method.

@@ -129,3 +152,3 @@

await prompt.secure('Enter account password', {
validate (answer) {
validate(answer) {
if (!answer) {

@@ -135,7 +158,22 @@ return 'Password is required to login'

return true
}
},
})
```
#### confirm(title: string, options?: BooleanPromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Enter account password')
question.answer('secret')
})
const password = await prompt.secure('Enter account password')
assert.equal(password, 'secret')
```
---
### `confirm(title: string, options?: BooleanPromptOptions)`
Uses the [confirm](https://github.com/enquirer/enquirer#confirm-prompt) prompt. The prompt options are same as the `ask` method.

@@ -145,5 +183,25 @@

await prompt.confirm('Want to delete files?')
```
```
#### toggle(title: string, choices: [string, string], options?: TogglePromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Want to delete files?')
// Say yes
question.accept()
// Say no
question.decline()
})
const deleteFiles = await prompt.confirm('Want to delete files?')
assert.isTrue(deleteFiles)
```
---
### `toggle(title: string, choices: [string, string], options?: TogglePromptOptions)`
Use the [toggle](https://github.com/enquirer/enquirer#toggle-prompt) prompt. The prompt options are same as the `ask` method.

@@ -155,3 +213,23 @@

#### choice(title: string, choices: (string | {})[], options?: ChoicePromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Want to delete files?')
// Say yes
question.accept()
// Say no
question.decline()
})
const deleteFiles = await prompt.toggle('Want to delete files?', ['Yep', 'Nope'])
assert.isTrue(deleteFiles)
```
---
### `choice(title: string, choices: (string | {})[], options?: ChoicePromptOptions)`
Uses the [select](https://github.com/enquirer/enquirer#select-prompt) prompt. The prompt options are same as the `ask` method.

@@ -173,16 +251,29 @@

name: 'Lettuce',
hint: 'Fresh and leafy',
}
hint: 'Fresh and leafy',
},
])
```
#### multiple(title: string, choices: (string | {})[], options?: MultiplePromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Select installation client')
// pass index
question.select(0)
})
const client = await prompt.choice('Select installation client', ['npm', 'yarn'])
assert.equal(client, 'npm')
```
---
### `multiple(title: string, choices: (string | {})[], options?: MultiplePromptOptions)`
Uses the [multiselect](https://github.com/enquirer/enquirer#multiselect-prompt) prompt. The prompt options are same as the `ask` method.
```ts
await prompt.multiple('Select base dependencies', [
'@adonisjs/core',
'@adonisjs/bodyparser'
])
await prompt.multiple('Select base dependencies', ['@adonisjs/core', '@adonisjs/bodyparser'])
```

@@ -196,23 +287,37 @@

name: '@adonisjs/core',
message: 'Framework core'
message: 'Framework core',
},
{
name: '@adonisjs/bodyparser',
message: 'Bodyparser'
}
message: 'Bodyparser',
},
])
```
#### autocomplete(title: string, choices: string[], options?: AutoCompletePromptOptions)
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Select base dependencies')
// pass indexes
question.multiSelect([0, 1])
})
const dependencies = await prompt.multiple('Select base dependencies', [
'@adonisjs/core',
'@adonisjs/bodyparser',
])
assert.deepEqual(dependencies, ['@adonisjs/core', '@adonisjs/bodyparser'])
```
---
### `autocomplete(title: string, choices: string[], options?: AutoCompletePromptOptions)`
Uses the [autocomplete](https://github.com/enquirer/enquirer#autocomplete-prompt) prompt.
```ts
await prompt.autocomplete('Select country', [
'India',
'USA',
'UK',
'Ireland',
'Australia',
])
await prompt.autocomplete('Select country', ['India', 'USA', 'UK', 'Ireland', 'Australia'])
```

@@ -223,3 +328,18 @@

```ts
await prompt.autocomplete('Select country', [
await prompt.autocomplete('Select country', ['India', 'USA', 'UK', 'Ireland', 'Australia'], {
multiple: true,
})
```
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Select country')
// pass indexes
question.select(1)
})
const country = await prompt.autocomplete('Select country', [
'India',

@@ -230,8 +350,11 @@ 'USA',

'Australia',
], {
multiple: true,
})
])
assert.equal(country, 'USA')
```
#### enum(title: string, options?: EnumPromptOptions)
---
### `enum(title: string, options?: EnumPromptOptions)`
Similar to the `ask` prompt, but allows comma (,) separated values. Uses the [list](https://github.com/enquirer/enquirer#list-prompt) prompt.

@@ -241,17 +364,27 @@

await prompt.enum('Define tags', {
hint: 'Accepts comma separated values'
hint: 'Accepts comma separated values',
})
```
Use the following code to answer prompt during tests
```ts
prompt.on('prompt', (question) => {
assert.equal(question.message, 'Define tags')
question.answer('nodejs,javascript')
})
const tags = await await prompt.enum('Define tags')
assert.deepEqual(tags, ['nodejs', 'javascript'])
```
[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/prompts/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/prompts "circleci"
[circleci-url]: https://circleci.com/gh/poppinss/prompts 'circleci'
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/@poppinss/prompts.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@poppinss/prompts "npm"
[npm-url]: https://npmjs.org/package/@poppinss/prompts 'npm'
[license-image]: https://img.shields.io/npm/l/@poppinss/prompts?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[license-url]: LICENSE.md 'license'
[audit-report-image]: https://img.shields.io/badge/-Audit%20Report-blueviolet?style=for-the-badge
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/poppinss/prompts/blob/develop/npm-audit.html 'audit-report'
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc