function userMeansYes
userMeansYes(answer: string): boolean

How an answer to [Y/n] is read: Enter, or anything starting with y. Everything else is no.

Deliberately strict in that direction. Most [Y/n] prompts take anything-but-n as yes, but this one RUNS CODE, and the complaint it exists to answer is code running when nobody asked for it. A prompt that reads a mistyped .exit as consent is the same bug with an extra step.

Its own function because it is the whole of the decision, and a decision made inside a callback inside a promise is one nothing can test without a terminal.

import { userMeansYes } from './editor.ts';

userMeansYes(''); // true — Enter takes the default, which is to run it
userMeansYes('y'); // true
userMeansYes('  YES  '); // true — trimmed, and case does not matter
userMeansYes('n'); // false
userMeansYes('.exit'); // false — a stray command is not consent

Parameters

answer: string

Return Type

boolean

Usage

import { userMeansYes } from "lib/commands/repl/editor.ts";