Constructor
new Promptlet(info)
- Source:
Instantiates a new Promptlet
Parameters:
Name | Type | Description |
---|---|---|
info |
PromptletOptions | Object with all the prompt configurations passed to inquirer. See the 'inquirer' documentation on npm or Github for specific details. Name property required |
Throws:
-
Will be thrown if info.name is not a string
- Type
- TypeError
Members
editable :boolean
- Source:
Whether the question can be answered again and edited after the initial prompt
Type:
- boolean
filters :Array.<function()>
- Source:
Array of filter functions to pass prompt answers through to be altered
Function output must be a string. Outputs will be used as the input to the next function in the array
Type:
- Array.<function()>
info :PromptletOptions
- Source:
Default object template for the inquirer prompt function. Options passed to the Promptlet will overwrite these.
The name property will be ignored on the default if set.
No longer a static property due to arrays
Type:
info :PromptletOptions|Object
- Source:
Object containing all the data needed to start an inquirer prompt. Requires name property
Type:
- PromptletOptions | Object
name
- Source:
Getter for Promptlet.name property
optionName :string
- Source:
Text displayed for this Promptlet on the PromptSet option list
Type:
- string
postProcessors :Array.<function()>
- Source:
Array of post-processor functions for prompt answers
Each function will be called in order until the end of the array. Error handling must be handled by each individual function
Each function should return something to pass to the next function or throw an error to crash
Type:
- Array.<function()>
prerequisites :Array.<string>
- Source:
Array with a list of names from Promptlets in a PromptSet that must be answered before this instance can be asked
Type:
- Array.<string>
satisfied :boolean
- Source:
Whether this Promptlet has been answered satisfactorily yet
Type:
- boolean
validators :Array.<function()>
- Source:
Array of validator functions for prompt answers
Each function will be called in order until the end of the array or until an error or error message is returned instead of true
Return a string to display an error message, true to continue, or throw an error to crash
Type:
- Array.<function()>
value :string|number|boolean|*
- Source:
The answer given to the Promptlet
Typeof value depends on the type of prompt being used and the output of the filters in that order
Type:
- string | number | boolean | *
Methods
addFilter(filter) → {Promptlet}
- Source:
Add a filter to the prompt. Will not add identical duplicates (Wrap or recreate a function if multiple copies are desired)
Parameters:
Name | Type | Description |
---|---|---|
filter |
function | Array.<function()> | Filter function to add |
Throws:
-
Thrown if a function is not provided
- Type
- TypeError
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
addPostProcessor(postProcessor) → {Promptlet}
- Source:
Add a post processor to the prompt. Will not add identical duplicates
Parameters:
Name | Type | Description |
---|---|---|
postProcessor |
function | Array.<function()> | Post processor function to add |
Throws:
-
Thrown if a function is not provided
- Type
- TypeError
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
addPrerequisite(newPrerequisite) → {Promptlet}
- Source:
Adds a prerequisite that must be completed before this Promptlet can run
Parameters:
Name | Type | Description |
---|---|---|
newPrerequisite |
string | Promptlet | The name property of the prerequisite Promptlet |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
addValidator(validator) → {Promptlet}
- Source:
Add a validator to the prompt. Will not add identical duplicates (Wrap or recreate a function if multiple copies are desired)
Parameters:
Name | Type | Description |
---|---|---|
validator |
function | Array.<function()> | Validator function to add |
Throws:
-
Thrown if a function is not provided
- Type
- TypeError
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
allowBlank(allowopt) → {Promptlet}
- Source:
Whether to allow blank answers (responses). Defaults to true if called without arguments
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
allow |
boolean |
<optional> |
true
|
Determines whether to include the Validators.disableBlank function as a validator |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
autoTrim(allowopt) → {Promptlet}
- Source:
Whether to automatically use the built-in trim filter. Defaults to true if called without arguments
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
allow |
boolean |
<optional> |
true
|
Determines whether to include the Filters.autoTrim function as a filter |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
generateListing(preSatisfied) → {Object}
- Source:
Generates the listing for this Promptlet through an Object for inquirer lists
Parameters:
Name | Type | Description |
---|---|---|
preSatisfied |
boolean | Whether the prerequisites have been satisfied (Cannot be automatically done internally by a Promptlet without a PromptSet) |
Returns:
An entry for the PromptSet.selectPromptlet() function's prompt
- Type
- Object
(async) postProcess(answersopt) → {Promptlet}
- Source:
Runs all the post processor functions with the current value Modifies value property
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
answers |
Object |
<optional> |
{}
|
Object with all the previous Promptlet answers if run by a PromptSet |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
removeFilter(filter) → {Promptlet}
- Source:
Remove a filter from the prompt. (Requires exact same function instance to remove)
Parameters:
Name | Type | Description |
---|---|---|
filter |
function | Filter function to remove |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
removePostProcessor(postProcessor) → {Promptlet}
- Source:
Remove a post processor from the prompt. (Requires exact same function instance to remove)
Parameters:
Name | Type | Description |
---|---|---|
postProcessor |
function | Post processor function to remove |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
removePrerequisite(removePrerequisite) → {Promptlet}
- Source:
Removes a prerequisite that must be completed before this Promptlet can run
Parameters:
Name | Type | Description |
---|---|---|
removePrerequisite |
string | Promptlet | The name property of the prerequisite Promptlet |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
removeValidator(validator) → {Promptlet}
- Source:
Remove a validator from the prompt. (Requires exact same function instance to remove)
Parameters:
Name | Type | Description |
---|---|---|
validator |
function | Validator function to remove |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
required(toggleopt) → {Promptlet}
- Source:
Whether the current Promptlet instance must be run before the parent PromptSet can terminate. Defaults to true if called without arguments
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
toggle |
boolean |
<optional> |
true
|
Whether answering the Promptlet is required. Defaults to true if this function is called. |
Returns:
Returns 'this' Promptlet for chaining
- Type
- Promptlet
(async) start(answersopt) → {string}
- Source:
Runs the Promptlet and sets satisfied property to true. Updates value property
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
answers |
Object |
<optional> |
{}
|
Object with all the previous Promptlet answers if run by a PromptSet |
Returns:
Resolves to the answer value after inquirer finishes
- Type
- string
toString() → {string}
- Source:
Returns basic data about the Promptlet as a string
Returns:
String detailing the current state of the Promptlet
- Type
- string