1.0.2 • Published 2 years ago

simplifyprompt v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

SimplifyPromptJS

Introduction

With this package, you will be able to create prompts to interact with the command line in a simple way.

You can customize your indicator with numerous options and create commands too easy.

new Prompt(PromptConstructorOptions)

With this class, you can create your own prompt.

ParamDescriptionDefault
PromptConstructorOptionsThe constructor options for this promptPromptConstructorOptions (default value)

Check the types part to see more information

<prompt>.addCommands(...commands):this

Add commands to the prompt.

ParamDescriptionDefaultType
commandsThe list of commands to addundefined \| []...CommandsOptions | Array\<CommandsOptions>

Usage:

const prompt = new Prompt(/*Options*/);

prompt.addCommands(
    {
        name: 'install',
        aliases: ['i'],
        description: 'Install a package'
    }
);

<prompt>.reply(args?):ReplyResponse

Reply to a prompt interation.

ParamDescriptionDefaultType
argsThe args of the promptprocess.argvstring

Usage:

const prompt = new Prompt(/*Options*/);

let interaction = prompt.reply();

Types

PromptConstructorOptions

PropertyDescriptionTypeDefaultRequired
commandsThe commands of this promptArray<CommandsOptions>[]
prefixThe prefix options for this promptPrefixOptionsPrefixOptions (default value)
optionsThe options for this promptPromptOptions{}

CommandsOptions

PropertyDescriptionTypeDefaultRequired
nameThe name of the commandstringundefined
aliasesThe aliases of this commandArray\[]
descriptionThe description of this commandstringnull
optionsThe options of this commandArray<CommandOptions>[]
actionThe action of this command. Launched when the command is invokedCommandFunction()() => {}
typeThe type of the value"string" | "boolean" | "number" | "any""any"
requiredIf the value of the command is requiredbooleanfalse

CommandOptions

PropertyDescriptionTypeDefaultRequired
nameThe name of this optionstringundefined
aliasesThe aliases of this optionArray\[]
descriptionThe description of this optionstringnull
typeThe type of this option"string" | "number" | "boolean" | "any""any"
actionThe action of this option. Launched when the option is invokedOptionFunction()() => {}

CommandFunction

ParamDescriptionTypeRequired
optionsThe data of this functionCommandFunctionProperties

CommandFunctionProperties

PropertyDescriptionTypeDefault
argsThe arguments of this interactionArray\ | string, string | number | booleanArray\<undefined>
commandValueThe value of this interactionstring | number | booleanundefined

OptionFunction

ParamDescriptionTypeRequired
optionsThe data of this functionOptionFunctionProperties

OptionFunctionProperties

PropertyDescriptionTypeDefault
valueThe value of this optionstring | boolean | numberundefined
commandValueThe value of the interactionstring | number | booleanundefined

PrefixOptions

PropertyDescriptionTypeDefaultRequired
largeThe large prefix for complete option namestring--
sortThe sort prefix for alias optionstring-

PromptOptions

PropertyDescriptionTypeDefaultRequired
errorMessagesA object with all error messagesErrorMessages{}

ErrorMessages

PropertyDescriptionTypeDefaultRequired
COMMAND_DOESNT_EXISTInvoked when a command doesn't existstring"The command does not exist!"
MALFORMED_COMMANDInvoked when a command have bad sintaxisstring"The command sintaxis isn't correct!"
WRONG_DATA_TYPEInvoked when you provide a incorrect data type in a command or optionstring"The option "{name}" wants this type: {type}"
REQUIRED_VALUEInvoked when the value of the command or options is required and the value is undefinedstring"The command value is required!"

ReplyResponse

PropertyDescriptionType
commandNameThe name of the launched commandstring
valueThe value of the interactionstring | number | boolean
argumentsThe arguments of this interactionArray\ | [string, string | number | boolean][]