How to use the enquirer.NumberPrompt function in enquirer

To help you get started, we’ve selected a few enquirer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enquirer / enquirer / examples / number / option-format.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');
const placeholder = require('../../lib/placeholder');

const prompt = new NumberPrompt({
  name: 'amount',
  message: 'How much do you want to donate?',
  float: true,
  cursor: 1,
  format(input = this.input) {
    const str = Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' }).format(input);

    let pos = this.cursor + 1;

    // Total number of commas (,) in the formatted string
    const totalcommas = str.split(',').length - 1;

    // Number of commas (,) to the right of the current cursor position
    const extracommas =
      Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' })
        .format(
github enquirer / enquirer / examples / numeral / option-format.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');
const placeholder = require('../../lib/placeholder');

const prompt = new NumberPrompt({
  name: 'amount',
  message: 'How much do you want to donate?',
  float: true,
  format(input = this.input) {
    const str = Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' }).format(input);

    let pos = this.cursor + 1;

    // Total number of commas (,) in the formatted string
    const totalcommas = str.split(',').length - 1;

    // Number of commas (,) to the right of the current cursor position
    const extracommas =
      Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' })
        .format(
          input
github enquirer / enquirer / examples / number / prompt.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');

const prompt = new NumberPrompt({
  name: 'number',
  message: 'Please enter a number'
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);
github enquirer / enquirer / examples / number / option-initial.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');

const prompt = new NumberPrompt({
  name: 'number',
  message: 'Please enter a number',
  initial: 2
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);
github enquirer / enquirer / examples / numeral / prompt.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');

const prompt = new NumberPrompt({
  name: 'number',
  message: 'Please enter a number'
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);
github bunqCommunity / bunq-cli / src / Prompts / custom_input_id.ts View on Github external
export default async customIdText => {
    const prompt = new NumberPrompt({
        message: `Please enter the ${customIdText}`
    });

    return prompt.run();
};
github enquirer / enquirer / examples / number / option-validate.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');

const prompt = new NumberPrompt({
  name: 'value',
  price: 7.75,
  message: 'How many tickets do you need?',
  float: false,
  validate(state) {
    return +state.value < 2 ? 'You must purchase 2 or more tickets' : true;
  },
  hint() {
    if (!this.state.submitted) {
      return this.styles.muted(`(${dollars(this.input, this.options.price)})`);
    }
  },
  format() {
    return this.state.submitted ? dollars(this.value, this.options.price) : this.value;
  }
});