Members
autoclear :boolean
- Source:
Whether to automatically clear the console after each prompt
Inquirer will usually do it automatically regardless but this is just in case
Type:
- boolean
defaultPosition :string|number
- Source:
Where to place the cursor in the PromptSet's list of Promptlets when started
Used to save the current position and return to it after the prompt is answered
Can be set to the name property of a Promptlet (preferred by internal code) or its index in the set
Type:
- string | number
finishMode :string
- Source:
A string from PromptSet.finishModes. Determines when and how to ask the user if they are finished yet.
See PromptSet.finishModes for more details
Type:
- string
(readonly) finishModes :Array.<string>
- Source:
Valid finishing modes for the PromptSet
Aggressive: Combination of 'confirm' and 'choice'
Confirm: Confirm after all prerequisites are met and every edit after that as well. Identical to auto if nothing is editable
Choice: Add an option to close the list at the end after all prerequisites are met
Auto: Automatically stops execution and closes the list after prerequisites are met
Type:
- Array.<string>
finishPrompt :Promptlet
- Source:
Confirmation Promptlet that determines whether to end execution or continue for edits or optional prompts
Type:
(readonly) names :Array.<string>
- Source:
Getter that returns an array of Promptlet names from the current set in order
Type:
- Array.<string>
passthroughProperties :Array.<string>
- Source:
All the method property names of the Promptlet prototype
Type:
- Array.<string>
previous :Promptlet|undefined
- Source:
Most recently added or edited Promptlet. May be undefined if nothing has been added or if the added item was deleted
Type:
- Promptlet | undefined
PromptletSet :Array.<Promptlet>
- Source:
The complete set of Promptlets in the PromptSet. Stored in the order they are added in
Type:
- Array.<Promptlet>
satisfied :boolean
- Source:
Is true when all necessary Promptlets have been answered
Type:
- boolean
Methods
(static) attachPassthrough(instance)
- Source:
Modifies the PromptSet prototype with passthrough functions for the this.previous Promptlet instance of each PromptSet.
All passthrough functions return this PromptSet for chaining rather than the return value of the Promptlet
Parameters:
Name | Type | Description |
---|---|---|
instance |
PromptSet | The PromptSet being modified with the passthrough functions |
(static) isIdentifier(identifier) → {string|Promptlet}
- Source:
Throws an error if the identifier is not a string or Promptlet instance
Parameters:
Name | Type | Description |
---|---|---|
identifier |
string | Promptlet | Identifier to check |
Throws:
-
Thrown if identifier is not the right type
- Type
- TypeError
Returns:
Returns the identifier untouched if no error is encountered
- Type
- string | Promptlet
add(set) → {PromptSet}
- Source:
Adds already instantiated Promptlets to the PromptSet
Parameters:
Name | Type | Description |
---|---|---|
set |
Promptlet | Promptlet to add to this PromptSet |
Throws:
-
Thrown if set is not a Promptlet instance
- Type
- TypeError
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
addNew(constructorArgs) → {PromptSet}
- Source:
Creates a new Promptlet and immediately adds it to the PromptSet
Parameters:
Name | Type | Description |
---|---|---|
constructorArgs |
PromptletOptions | Array.<PromptletOptions> | Argument passed to the Promptlet constructor. If this is an array, it will be looped through recursively from first to last |
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
addPrerequisite(prerequisiteIdentifier, addToIdentifieropt) → {PromptSet}
- Source:
Adds a prerequisite Promptlet that must be completed before this one
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
prerequisiteIdentifier |
string | Promptlet | Identifier for a prerequisite Promptlet (Promptlet must be in set) |
|
addToIdentifier |
string | Promptlet |
<optional> |
Identifier for a Promptlet to add prerequisite to (Promptlet must be in set). Will use PromptSet.previous if not provided |
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
clear()
- Source:
Empties and resets the PromptSet for reuse
clearConsole()
- Source:
Clears console if PromptSet.autoclear is set to a truthy value
generateList() → {Array.<{name: string, value: string}>}
- Source:
Generates the list of prompts that are displayed for selection
Returns:
- Type
- Array.<{name: string, value: string}>
(async) isFinished() → {boolean}
- Source:
Returns whether to close the list (True after everything needed to be answered has been answered)
Returns:
Whether to end execution
- Type
- boolean
isSatisfied() → {boolean}
- Source:
Returns true when all required Promptlets have been answered
Returns:
Whether all necessary Promptlets have been answered
- Type
- boolean
prereqSatisfied(chosenPromptlet, silentopt) → {boolean}
- Source:
Used for determining whether all the prerequisites for a Promptlet have been met
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
chosenPromptlet |
Promptlet | A Promptlet to check prerequisites from |
||
silent |
boolean |
<optional> |
false
|
When not set to true, the first unsatisfied prerequisite will be logged through the console |
Returns:
Whether the chosenPromptlet has had all of its prerequisites met
- Type
- boolean
reduce() → {Object}
- Source:
Collects the values of every Promptlet into an Object.
Note: Skips unanswered Promptlets
Returns:
All results in "name: value" pairs
- Type
- Object
refreshPrevious(newPreviousopt) → {Promptlet|undefined}
- Source:
Update or fetch the value of this.previous
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
newPrevious |
Promptlet | string |
<optional> |
New value to set as previous. Return value may vary depending on the type of this parameter |
Throws:
-
newPrevious is not a string or Promptlet
- Type
- TypeError
Returns:
Returns a Promptlet. If newPrevious is a Promptlet, it will be returned untouched. If it is as string, the Promptlet will be automatically looked up. If newPrevious is not provided, this.previous will be returned (See PromptSet.previous for details).
- Type
- Promptlet | undefined
remove(identifier) → {PromptSet}
- Source:
Remove a Promptlet from the PromptSet
Warning: Will make Promptlets that have the removed Promptlet as a prerequisite no longer selectable
Parameters:
Name | Type | Description |
---|---|---|
identifier |
Identifier for the Promptlet to remove from the PromptSet (Promptlet must be in set) |
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
removePrerequisite(removeIdentifier, removeFromIdentifieropt) → {PromptSet}
- Source:
Remove a prerequisite from a specific Promptlet
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
removeIdentifier |
string | Promptlet | Identifier for a prerequisite Promptlet (Promptlet must be in set) |
|
removeFromIdentifier |
string | Promptlet |
<optional> |
Identifier for a Promptlet to remove prerequisite from (Promptlet must be in set). Will use PromptSet.previous if not provided |
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
resetPrevious(targetPrevious) → {Promptlet}
- Source:
Clear this.previous if it matches the targetPrevious. Use when a Promptlet is being removed from the set
Parameters:
Name | Type | Description |
---|---|---|
targetPrevious |
Promptlet | string | Promptlet to assure is not equal to this.previous |
Throws:
-
targetPrevious is not a string or Promptlet
- Type
- TypeError
Returns:
Returns targetPrevious as a Promptlet. If targetPrevious was a string, it will be looked up
- Type
- Promptlet
searchSet(identifier) → {Promptlet}
- Source:
Search the PromptSet for a specific Promptlet
Parameters:
Name | Type | Description |
---|---|---|
identifier |
string | Promptlet | The name of the Promptlet to search for. If a Promptlet is provided, the Promptlet.name property will be used |
Throws:
-
-
Identifier is not a string or Promptlet
- Type
- TypeError
-
-
-
Identifier is not found in the set
- Type
- RangeError
-
Returns:
The searched Promptlet if found
- Type
- Promptlet
(async) selectPromptlet() → {Promptlet}
- Source:
Creates a list prompt for the user to select what to answer from the PromptSet
Returns:
Returns the selected Promptlet from the set. Does not take into account prerequisites or editable state PromptSet.start
- Type
- Promptlet
setFinishMode(modeopt) → {PromptSet}
- Source:
Toggle or set whether or not to confirm that the user is done before terminating the PromptSet
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mode |
string | number |
<optional> |
PromptSet.finishModes[3]
|
The finish mode to use. See PromptSet#finishModes for details |
Throws:
-
-
Index out of bounds for finish mode array
- Type
- RangeError
-
-
-
Throws if mode is not a string, a number, or a number string
- Type
- TypeError
-
Returns:
Returns 'this' PromptSet for chaining
- Type
- PromptSet
start() → {Promise.<Object>}
- Source:
Starts up the PromptSet and finishes once all the necessary questions are answered
Returns:
Returns a Promise that resolves to the result of PromptSet.reduce
- Type
- Promise.<Object>
toString() → {string}
- Source:
Returns the JSON.stringify() version of PromptSet.reduce
Returns:
JSON with all the values as a string. Parse with JSON.parse() if needed or use for debugging
- Type
- string