Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.133.141.143
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/task/3/root/proc/3/root/proc/3/root/usr/lib/node_modules/pm2/node_modules/promptly/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/task/3/root/proc/3/root/proc/3/root/usr/lib/node_modules/pm2/node_modules/promptly/index.js
'use strict';

var read = require('read');
var promptly = module.exports;

function prompt(message, opts, fn) {
    // Setup read's options
    var readOpts = {
        prompt: message,
        input: opts.input || process.stdin,
        output: opts.output || process.stdout,
        silent: opts.silent,
        replace: opts.replace || ''
    };

    // Use readline question
    read(readOpts, function (err, data) {
        // Ignore the error attribute
        // It is set on SIGINT or if timeout reached (we are not using timeout)
        if (err) {
            return;
        }

        // Trim?
        if (opts.trim) {
            data = data.trim();
        }

        // Mandatory?
        if (opts['default'] == null && !data) {
            return promptly.prompt(message, opts, fn);
        } else {
            data = data || opts['default'];
        }

        // Validator verification
        if (opts.validator) {
            if (!Array.isArray(opts.validator)) {
                opts.validator = [opts.validator];
            }

            var x;
            var length = opts.validator.length;

            for (x = 0; x < length; x += 1) {
                try {
                    data = opts.validator[x](data);
                } catch (e) {
                    // Retry automatically if the retry option is enabled
                    if (opts.retry) {
                        if (e.message) {
                            readOpts.output.write(e.message + '\n');
                        }

                        return promptly.prompt(message, opts, fn);
                    }

                    e.retry = promptly.prompt.bind(promptly, message, opts, fn);

                    return fn(e);
                }
            }
        }

        // Everything ok
        fn(null, data);
    });
}

promptly.prompt = function (message, opts, fn) {
    // Arguments parsing
    if (typeof opts === 'function') {
        fn = opts;
        opts = {};
    } else if (!opts) {
        opts = {};
    }

    if (opts.trim === undefined) {
        opts.trim = true;
    }
    if (opts.retry === undefined) {
        opts.retry = true;
    }

    if (fn) {
        return prompt(message, opts, fn);
    }

    return new Promise(function (resolve, reject) {
        prompt(message, opts, function (err, result) {
            if (err) {
                return reject(err);
            }

            resolve(result);
        });
    });
};

promptly.password = function (message, opts, fn) {
    // Arguments parsing
    if (typeof opts === 'function') {
        fn = opts;
        opts = {};
    } else {
        opts = opts || {};
    }

    // Set default options
    if (opts.silent === undefined) {
        opts.silent = true;
    }
    if (opts.trim === undefined) {
        opts.trim = false;
    }
    if (opts['default'] === undefined) {
        opts['default'] = '';
    }

    // Use prompt()
    return promptly.prompt(message, opts, fn);
};

promptly.confirm = function (message, opts, fn) {
    // Arguments parsing
    if (typeof opts === 'function') {
        fn = opts;
        opts = {};
    } else if (!opts) {
        opts = {};
    }

    opts.validator = opts.validator || [];
    if (!Array.isArray(opts.validator)) {
        opts.validator = [opts.validator];
    }

    // Push the validator that will coerse boolean values
    var validator = function (value) {
        if (typeof value === 'string') {
            value = value.toLowerCase();
        }

        switch (value) {
        case 'y':
        case 'yes':
        case '1':
        case true:
            return true;
        case 'n':
        case 'no':
        case '0':
        case false:
            return false;
        }

        throw new Error();
    };
    opts.validator.push(validator);

    // Use choose() with true, false
    return promptly.choose(message, [true, false], opts, fn);
};

promptly.choose = function (message, choices, opts, fn) {
    // Arguments parsing
    if (typeof opts === 'function') {
        fn = opts;
        opts = {};
    } else if (!opts) {
        opts = {};
    }

    opts.validator = opts.validator || [];
    if (!Array.isArray(opts.validator)) {
        opts.validator = [opts.validator];
    }

    // Push the choice validator
    var nrChoices = choices.length;
    var validator = function (value) {
        var x;

        for (x = 0; x < nrChoices; x++) {
            if (choices[x] == value) {
                return choices[x];
            }
        }

        throw new Error('Invalid choice: ' + value);
    };
    opts.validator.push(validator);

    // Use prompt()
    return promptly.prompt(message, opts, fn);
};

Anon7 - 2022
AnonSec Team