Skip to main content
Deno 2 is finally here 🎉️
Learn more

Input Logo

Input-Deno

Tests

Used to get command line input from the user

Choose

Returns an array indicating which index was selected

const input = new InputLoop();
const accepting = await input.choose(["Accepting node", "Non-accepting node"]);

// output:

// ------------------------------
// 0: Accepting node
// 1: Non-accepting node
// ------------------------------

// Return value:
// [false, true]

Question

Ask a single question

const input = new InputLoop();
const nodeName = await input.question('Enter the label for the node:');

// output:

// Enter the label for the node:

// Return Value:
// 'a'

Looping

Control an input loop which continues reprompting until terminated

Automatic Looping:

Passing true as the second argument will automatically end the iteration of the last option is selected.

const input = new InputLoop();
const mainQuestions = ["Add a node", "Add an edge", "Set starting node", "Evaluate a string", "Quit"];

while (!input.done) {
    const result = await input.choose(mainQuestions, true);

    // Business logic...
}

Manual Looping:

const input = new InputLoop();
const mainQuestions = ["Add a node", "Add an edge", "Set starting node", "Evaluate a string", "Quit"];

while (!input.done) {
    const result = await input.choose(mainQuestions);

    // Business logic...

    if (result[mainQuestions.length - 1]) {
        input.close();
    }
}

Repeat

Repeat the previous question

const input = new InputLoop();
const mainQuestions = ["Add a node", "Add an edge", "Set starting node", "Evaluate a string", "Quit"];

let result = await input.choose(mainQuestions);

while (!(result[0] || result[1])) {
    result = input.repeat();
}

Testing

Deno tests can be run using:

make test