hoorain-atm
Version:
ATM Simulator: A Node.js package for creating console-based ATM simulations. Offers interactive prompts and colorful output for an engaging user experience.
56 lines (55 loc) • 1.83 kB
JavaScript
import chalk from "chalk";
import inquirer from "inquirer";
import { validateName, validatePin } from "./validation.js";
import { createSpinner } from "nanospinner";
//* Function to take user data one time
export const userData = async (balance) => {
const user = await inquirer.prompt([
{
message: chalk.yellow("Enter your user id: "),
name: "userId",
type: "input",
validate: validateName,
},
{
message: chalk.yellow("Enter your pin: "),
name: "pin",
type: "input",
validate: validatePin,
},
{
message: chalk.yellow("Select your account type: "),
name: "account",
type: "list",
choices: ['Current', 'Saving'],
},
]);
const spinner = createSpinner('Logging...').start();
await new Promise((r) => setTimeout(r, 200));
spinner.success({ text: chalk.green('Successfully logged in') });
console.log(chalk.white.bold.italic(`Your balance is ${balance}`));
};
//* Function to ask user for transition
export const transitionType = async () => {
const { transaction } = await inquirer.prompt([
{
message: chalk.yellow("Select transaction you want to do: "),
name: "transaction",
type: "list",
choices: ['Withdraw', 'Deposit', 'Transfer', 'Inquiry'],
},
]);
return transaction;
};
//* Function to ask user if he/she want to do another transition
export const again = async () => {
const { useAgain } = await inquirer.prompt([
{
message: chalk.yellow("Do you want to do another transaction "),
name: "useAgain",
type: "confirm",
default: true,
},
]);
return useAgain;
};