Sha256: 36f3b66f61f4e348d374b2f401f9a7e909061e6a383b5004f9ada2fb35698f6d

Contents?: true

Size: 1.3 KB

Versions: 26

Compression:

Stored size: 1.3 KB

Contents

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@inquirer/core");
exports.default = (0, core_1.createPrompt)((config, done) => {
    const { transformer = (answer) => (answer ? 'yes' : 'no') } = config;
    const [status, setStatus] = (0, core_1.useState)('pending');
    const [value, setValue] = (0, core_1.useState)('');
    const theme = (0, core_1.makeTheme)(config.theme);
    const prefix = (0, core_1.usePrefix)({ theme });
    (0, core_1.useKeypress)((key, rl) => {
        if ((0, core_1.isEnterKey)(key)) {
            let answer = config.default !== false;
            if (/^(y|yes)/i.test(value))
                answer = true;
            else if (/^(n|no)/i.test(value))
                answer = false;
            setValue(transformer(answer));
            setStatus('done');
            done(answer);
        }
        else {
            setValue(rl.line);
        }
    });
    let formattedValue = value;
    let defaultValue = '';
    if (status === 'done') {
        formattedValue = theme.style.answer(value);
    }
    else {
        defaultValue = ` ${theme.style.defaultAnswer(config.default === false ? 'y/N' : 'Y/n')}`;
    }
    const message = theme.style.message(config.message);
    return `${prefix} ${message}${defaultValue} ${formattedValue}`;
});

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/@inquirer/confirm/dist/cjs/index.js