code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
autofill = (answers = {}) => {
return enquirer => {
let prompt = enquirer.prompt.bind(enquirer);
let context = { ...enquirer.answers, ...answers };
enquirer.prompt = async questions => {
let list = [].concat(questions || []);
let choices = [];
for (let item of list) {
let value... | Example "autofill" plugin - to achieve similar goal to autofill for web forms.
_This isn't really needed in Enquirer, since the `autofill` option does
effectively the same thing natively_. This is just an example. | autofill | javascript | enquirer/enquirer | examples/autofill-plugin.js | https://github.com/enquirer/enquirer/blob/master/examples/autofill-plugin.js | MIT |
format() {
return prompt.input + ' ' + prompt.styles.muted(prompt.state.hint);
} | Example that shows all of the prompt elements displayed at once. | format | javascript | enquirer/enquirer | examples/everything.js | https://github.com/enquirer/enquirer/blob/master/examples/everything.js | MIT |
pointer(state, choice, i) {
return (state.index === i ? state.symbols.pointer : ' ') + ' ';
} | Example that shows all of the prompt elements displayed at once. | pointer | javascript | enquirer/enquirer | examples/everything.js | https://github.com/enquirer/enquirer/blob/master/examples/everything.js | MIT |
footer(state) {
if (state.limit < state.choices.length) {
return colors.dim('(Scroll up and down to reveal more choices)');
}
} | Example that shows all of the prompt elements displayed at once. | footer | javascript | enquirer/enquirer | examples/everything.js | https://github.com/enquirer/enquirer/blob/master/examples/everything.js | MIT |
result(names) {
return this.map(names);
} | Example that shows all of the prompt elements displayed at once. | result | javascript | enquirer/enquirer | examples/everything.js | https://github.com/enquirer/enquirer/blob/master/examples/everything.js | MIT |
constructor(options = {}) {
this.options = options;
} | Imagine this class does a search against an external api that returns a stream
of results. The results are used in the autocomplete suggest function below. | constructor | javascript | enquirer/enquirer | examples/autocomplete/option-suggest-streaming.js | https://github.com/enquirer/enquirer/blob/master/examples/autocomplete/option-suggest-streaming.js | MIT |
search(filter) {
let events = new Events();
let i = 0;
if (this.interval) this.stop();
this.interval = setInterval(() => {
let choice = this.options.choices[i++];
if (choice && choice.includes(filter)) {
events.emit('data', choice);
}
}, this.options.inter... | Imagine this class does a search against an external api that returns a stream
of results. The results are used in the autocomplete suggest function below. | search | javascript | enquirer/enquirer | examples/autocomplete/option-suggest-streaming.js | https://github.com/enquirer/enquirer/blob/master/examples/autocomplete/option-suggest-streaming.js | MIT |
stop() {
clearInterval(this.interval);
this.interval = null;
clearTimeout(this.timeout);
this.timeout = null;
} | Imagine this class does a search against an external api that returns a stream
of results. The results are used in the autocomplete suggest function below. | stop | javascript | enquirer/enquirer | examples/autocomplete/option-suggest-streaming.js | https://github.com/enquirer/enquirer/blob/master/examples/autocomplete/option-suggest-streaming.js | MIT |
dispatch(ch) {
if (!ch) return this.alert();
this.input += ch;
this.cursor += 1;
this.render();
} | > Using a custom Prompt class as an Enquirer plugin
Custom prompt class - in this example, we use a custom prompt class
to show how to use a custom prompt as an Enquirer plugin.
This is necessary if you want Enquirer to be able to automatically run
your custom prompt when specified on the question "type". | dispatch | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-class.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-class.js | MIT |
delete() {
this.input = this.input.slice(0, -1);
this.cursor = this.input.length;
this.render();
} | > Using a custom Prompt class as an Enquirer plugin
Custom prompt class - in this example, we use a custom prompt class
to show how to use a custom prompt as an Enquirer plugin.
This is necessary if you want Enquirer to be able to automatically run
your custom prompt when specified on the question "type". | delete | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-class.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-class.js | MIT |
render() {
this.clear();
let prefix = this.style(this.symbols.prefix[this.state.status]);
let msg = this.styles.strong(this.state.message);
let sep = this.styles.muted(this.symbols.separator[this.state.status]);
let prompt = [prefix, msg, sep].filter(Boolean).join(' ');
this.write(prompt + ' ' +... | > Using a custom Prompt class as an Enquirer plugin
Custom prompt class - in this example, we use a custom prompt class
to show how to use a custom prompt as an Enquirer plugin.
This is necessary if you want Enquirer to be able to automatically run
your custom prompt when specified on the question "type". | render | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-class.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-class.js | MIT |
customPrompt = (Prompt, enquirer) => {
class CustomInput extends Prompt {
dispatch(ch) {
if (!ch) return this.alert();
this.value = (this.value || '') + ch;
this.cursor += 1;
this.render();
}
delete() {
let value = this.value || '';
this.value = value ? value.slice(0, ... | This example builds off of the "custom-prompt-plugin-class.js" example.
When you register a custom Prompt class as a plugin, you can optionally
wrap your class in a function with `Prompt` and `enquirer` params, where
`Prompt` is a the base Prompt class, and `enquirer` is an instance
of Enquirer. | customPrompt | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-function.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-function.js | MIT |
customPrompt = (Prompt, enquirer) => {
class CustomInput extends Prompt {
dispatch(ch) {
if (!ch) return this.alert();
this.value = (this.value || '') + ch;
this.cursor += 1;
this.render();
}
delete() {
let value = this.value || '';
this.value = value ? value.slice(0, ... | This example builds off of the "custom-prompt-plugin-class.js" example.
When you register a custom Prompt class as a plugin, you can optionally
wrap your class in a function with `Prompt` and `enquirer` params, where
`Prompt` is a the base Prompt class, and `enquirer` is an instance
of Enquirer. | customPrompt | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-function.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-function.js | MIT |
dispatch(ch) {
if (!ch) return this.alert();
this.value = (this.value || '') + ch;
this.cursor += 1;
this.render();
} | This example builds off of the "custom-prompt-plugin-class.js" example.
When you register a custom Prompt class as a plugin, you can optionally
wrap your class in a function with `Prompt` and `enquirer` params, where
`Prompt` is a the base Prompt class, and `enquirer` is an instance
of Enquirer. | dispatch | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-function.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-function.js | MIT |
delete() {
let value = this.value || '';
this.value = value ? value.slice(0, -1) : '';
this.cursor = value.length;
this.render();
} | This example builds off of the "custom-prompt-plugin-class.js" example.
When you register a custom Prompt class as a plugin, you can optionally
wrap your class in a function with `Prompt` and `enquirer` params, where
`Prompt` is a the base Prompt class, and `enquirer` is an instance
of Enquirer. | delete | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-function.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-function.js | MIT |
async render() {
this.clear();
let value = this.value || '';
let message = await this.message();
this.write(`${message} ${value}`);
} | This example builds off of the "custom-prompt-plugin-class.js" example.
When you register a custom Prompt class as a plugin, you can optionally
wrap your class in a function with `Prompt` and `enquirer` params, where
`Prompt` is a the base Prompt class, and `enquirer` is an instance
of Enquirer. | render | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-plugin-function.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-plugin-function.js | MIT |
dispatch(ch) {
if (!ch) return this.alert();
this.value = (this.value || '') + ch;
this.cursor += 1;
this.render();
} | _Using a custom Prompt class_
Custom prompt class - in this example, we create custom prompt by
extending the built-in Prompt class (the base class used by all
Enquirer prompts).
Here we use this custom prompt as a standalone prompt, but you can
also register prompts as plugins on enquirer
(see "custom-prompt-plugin... | dispatch | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-standalone.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-standalone.js | MIT |
delete() {
let value = this.value || '';
this.value = value ? value.slice(0, -1) : '';
this.cursor = value.length;
this.render();
} | _Using a custom Prompt class_
Custom prompt class - in this example, we create custom prompt by
extending the built-in Prompt class (the base class used by all
Enquirer prompts).
Here we use this custom prompt as a standalone prompt, but you can
also register prompts as plugins on enquirer
(see "custom-prompt-plugin... | delete | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-standalone.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-standalone.js | MIT |
async render() {
this.clear();
let value = this.value || '';
let message = await this.message();
this.write(`${message} ${value}`);
} | _Using a custom Prompt class_
Custom prompt class - in this example, we create custom prompt by
extending the built-in Prompt class (the base class used by all
Enquirer prompts).
Here we use this custom prompt as a standalone prompt, but you can
also register prompts as plugins on enquirer
(see "custom-prompt-plugin... | render | javascript | enquirer/enquirer | examples/enquirer/custom-prompt-standalone.js | https://github.com/enquirer/enquirer/blob/master/examples/enquirer/custom-prompt-standalone.js | MIT |
input = (name, message, initial) => prompt => {
const p = new Input({ name, message, initial });
return p.run().then(value => ({ name, message, initial: value, value }));
} | First, let's wrap the Input prompt to cut down on boilerplate,
since we know in advance that we only need to define a few options. | input | javascript | enquirer/enquirer | examples/form/async-choices.js | https://github.com/enquirer/enquirer/blob/master/examples/form/async-choices.js | MIT |
input = (name, message, initial) => prompt => {
const p = new Input({ name, message, initial });
return p.run().then(value => ({ name, message, initial: value, value }));
} | First, let's wrap the Input prompt to cut down on boilerplate,
since we know in advance that we only need to define a few options. | input | javascript | enquirer/enquirer | examples/form/async-choices.js | https://github.com/enquirer/enquirer/blob/master/examples/form/async-choices.js | MIT |
header() {
return `${dim('You have')} ${color(time)} ${dim('seconds left to answer!')}`;
} | This example shows how to create a "countdown" effect. You can
put the countdown timer in the prefix, footer, header, separator,
or whatever prompt position makes sense for your goal. | header | javascript | enquirer/enquirer | examples/fun/countdown.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/countdown.js | MIT |
separator() {
return ''; // hide separator
} | This example shows how to create a "countdown" effect. You can
put the countdown timer in the prefix, footer, header, separator,
or whatever prompt position makes sense for your goal. | separator | javascript | enquirer/enquirer | examples/fun/countdown.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/countdown.js | MIT |
message(state) {
if (state.submitted && !state.input) return 'Really? Your own name?';
return state.submitted ? 'Well done,' : 'What is your full name!!!';
} | This example shows how to create a "countdown" effect. You can
put the countdown timer in the prefix, footer, header, separator,
or whatever prompt position makes sense for your goal. | message | javascript | enquirer/enquirer | examples/fun/countdown.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/countdown.js | MIT |
pointer(state, choice, i) {
return state.index === i ? frame(colors, state.timer.tick) + ' ' : ' ';
} | This examples shows how to use the `timers` option to
create multiple heartbeat effects in different positions. | pointer | javascript | enquirer/enquirer | examples/fun/heartbeats.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/heartbeats.js | MIT |
timeout = (fn, ms = 0) => {
return new Promise((resolve, reject) => {
setTimeout(() => fn().then(resolve).catch(reject), ms);
});
} | This examples shows how to "play" an array of keypresses. | timeout | javascript | enquirer/enquirer | examples/fun/play-steps.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/play-steps.js | MIT |
timeout = (fn, ms = 0) => {
return new Promise((resolve, reject) => {
setTimeout(() => fn().then(resolve).catch(reject), ms);
});
} | This examples shows how to "play" an array of keypresses. | timeout | javascript | enquirer/enquirer | examples/fun/play-steps.js | https://github.com/enquirer/enquirer/blob/master/examples/fun/play-steps.js | MIT |
footer() {
let fn = colors[keys[++idx % keys.length]];
return '\n' + fn('(Scroll up and down to reveal more choices)');
} | This prompt shows how you can easily customize the footer
to render a different value based on conditions. | footer | javascript | enquirer/enquirer | examples/select/select-long.js | https://github.com/enquirer/enquirer/blob/master/examples/select/select-long.js | MIT |
constructor(token) {
this.name = token.key;
this.field = token.field || {};
this.value = clean(token.initial || this.field.initial || '');
this.message = token.message || this.name;
this.cursor = 0;
this.input = '';
this.lines = [];
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | constructor | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
tokenize = async(options = {}, defaults = {}, fn = token => token) => {
let unique = new Set();
let fields = options.fields || [];
let input = options.template;
let tabstops = [];
let items = [];
let keys = [];
let line = 1;
if (typeof input === 'function') {
input = await input();
}
let i = -... | This file contains the interpolation and rendering logic for
the Snippet prompt. | tokenize | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
tokenize = async(options = {}, defaults = {}, fn = token => token) => {
let unique = new Set();
let fields = options.fields || [];
let input = options.template;
let tabstops = [];
let items = [];
let keys = [];
let line = 1;
if (typeof input === 'function') {
input = await input();
}
let i = -... | This file contains the interpolation and rendering logic for
the Snippet prompt. | tokenize | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
push = token => {
token.line = line;
tabstops.push(token);
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | push | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
push = token => {
token.line = line;
tabstops.push(token);
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | push | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
validate = async(value, state, item, index) => {
let error = await isValid(value, state, item, index);
if (error === false) {
return 'Invalid field ' + item.name;
}
return error;
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | validate | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
validate = async(value, state, item, index) => {
let error = await isValid(value, state, item, index);
if (error === false) {
return 'Invalid field ' + item.name;
}
return error;
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | validate | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
function createFn(prop, prompt, options, fallback) {
return (value, state, item, index) => {
if (typeof item.field[prop] === 'function') {
return item.field[prop].call(prompt, value, state, item, index);
}
return [fallback, value].find(v => prompt.isValue(v));
};
} | This file contains the interpolation and rendering logic for
the Snippet prompt. | createFn | javascript | enquirer/enquirer | lib/interpolate.js | https://github.com/enquirer/enquirer/blob/master/lib/interpolate.js | MIT |
constructor(options = {}) {
super();
this.name = options.name;
this.type = options.type;
this.options = options;
theme(this);
timer(this);
this.state = new State(this);
this.initial = [options.initial, options.default].find(v => v != null);
this.stdout = options.stdout || process.std... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | constructor | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async keypress(input, event = {}) {
this.keypressed = true;
let key = keypress.action(input, keypress(input, event), this.options.actions);
this.state.keypress = key;
this.emit('keypress', input, key);
this.emit('state', this.state.clone());
const fn = this.options[key.action] || this[key.actio... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | keypress | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
alert() {
delete this.state.alert;
if (this.options.show === false) {
this.emit('alert');
} else {
this.stdout.write(ansi.code.beep);
}
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | alert | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
cursorHide() {
this.stdout.write(ansi.cursor.hide());
const releaseOnExit = utils.onExit(() => this.cursorShow());
this.on('close', () => {
this.cursorShow();
releaseOnExit();
});
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | cursorHide | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
write(str) {
if (!str) return;
if (this.stdout && this.state.show !== false) {
this.stdout.write(str);
}
this.state.buffer += str;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | write | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
clear(lines = 0) {
let buffer = this.state.buffer;
this.state.buffer = '';
if ((!buffer && !lines) || this.options.show === false) return;
this.stdout.write(ansi.cursor.down(lines) + ansi.clear(buffer, this.width));
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | clear | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
restore() {
if (this.state.closed || this.options.show === false) return;
let { prompt, after, rest } = this.sections();
let { cursor, initial = '', input = '', value = '' } = this;
let size = this.state.size = rest.length;
let state = { after, cursor, initial, input, prompt, size, value };
le... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | restore | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
sections() {
let { buffer, input, prompt } = this.state;
prompt = stripAnsi(prompt);
let buf = stripAnsi(buffer);
let idx = buf.indexOf(prompt);
let header = buf.slice(0, idx);
let rest = buf.slice(idx);
let lines = rest.split('\n');
let first = lines[0];
let last = lines[lines.lengt... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | sections | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async submit() {
this.state.submitted = true;
this.state.validating = true;
// this will only be called when the prompt is directly submitted
// without initializing, i.e. when the prompt is skipped, etc. Otherwize,
// "options.onSubmit" is will be handled by the "initialize()" method.
if (this... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | submit | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async cancel(err) {
this.state.cancelled = this.state.submitted = true;
await this.render();
await this.close();
if (typeof this.options.onCancel === 'function') {
await this.options.onCancel.call(this, this.name, this.value, this);
}
this.emit('cancel', await this.error(err));
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | cancel | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async close() {
this.state.closed = true;
try {
let sections = this.sections();
let lines = Math.ceil(sections.prompt.length / this.width);
if (sections.rest) {
this.write(ansi.cursor.down(sections.rest.length));
}
this.write('\n'.repeat(lines));
} catch (err) { /* do ... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | close | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
start() {
if (!this.stop && this.options.show !== false) {
this.stop = keypress.listen(this, this.keypress.bind(this));
this.once('close', this.stop);
this.emit('start', this);
}
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | start | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async skip() {
this.skipped = this.options.skip === true;
if (typeof this.options.skip === 'function') {
this.skipped = await this.options.skip.call(this, this.name, this.value);
}
return this.skipped;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | skip | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async initialize() {
let { format, options, result } = this;
this.format = () => format.call(this, this.value);
this.result = () => result.call(this, this.value);
if (typeof options.initial === 'function') {
this.initial = await options.initial.call(this, this);
}
if (typeof options.onR... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | initialize | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
render() {
throw new Error('expected prompt to have a custom render method');
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | render | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
run() {
return new Promise(async(resolve, reject) => {
this.once('submit', resolve);
this.once('cancel', reject);
if (await this.skip()) {
this.render = () => {};
return this.submit();
}
await this.initialize();
this.emit('run');
});
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | run | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async element(name, choice, i) {
let { options, state, symbols, timers } = this;
let timer = timers && timers[name];
state.timer = timer;
let value = options[name] || state[name] || symbols[name];
let val = choice && choice[name] != null ? choice[name] : await value;
if (val === '') return val;
... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | element | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async prefix() {
let element = await this.element('prefix') || this.symbols;
let timer = this.timers && this.timers.prefix;
let state = this.state;
state.timer = timer;
if (utils.isObject(element)) element = element[state.status] || element.pending;
if (!utils.hasColor(element)) {
let styl... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | prefix | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async message() {
let message = await this.element('message');
if (!utils.hasColor(message)) {
return this.styles.strong(message);
}
return message;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | message | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async separator() {
let element = await this.element('separator') || this.symbols;
let timer = this.timers && this.timers.separator;
let state = this.state;
state.timer = timer;
let value = element[state.status] || element.pending || state.separator;
let ele = await this.resolve(value, state);
... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | separator | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async pointer(choice, i) {
let val = await this.element('pointer', choice, i);
if (typeof val === 'string' && utils.hasColor(val)) {
return val;
}
if (val) {
let styles = this.styles;
let focused = this.index === i;
let style = focused ? styles.primary : val => val;
let e... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | pointer | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async indicator(choice, i) {
let val = await this.element('indicator', choice, i);
if (typeof val === 'string' && utils.hasColor(val)) {
return val;
}
if (val) {
let styles = this.styles;
let enabled = choice.enabled === true;
let style = enabled ? styles.success : styles.dark;
... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | indicator | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
body() {
return null;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | body | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
footer() {
if (this.state.status === 'pending') {
return this.element('footer');
}
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | footer | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
header() {
if (this.state.status === 'pending') {
return this.element('header');
}
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | header | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
async hint() {
if (this.state.status === 'pending' && !this.isValue(this.state.input)) {
let hint = await this.element('hint');
if (!utils.hasColor(hint)) {
return this.styles.muted(hint);
}
return hint;
}
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | hint | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
error(err) {
return !this.state.submitted ? (err || this.state.error) : '';
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | error | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
format(value) {
return value;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | format | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
result(value) {
return value;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | result | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
validate(value) {
if (this.options.required === true) {
return this.isValue(value);
}
return true;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | validate | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
isValue(value) {
return value != null && value !== '';
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | isValue | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
resolve(value, ...args) {
return utils.resolve(this, value, ...args);
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | resolve | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get base() {
return Prompt.prototype;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | base | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get style() {
return this.styles[this.state.status];
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | style | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get height() {
return this.options.rows || utils.height(this.stdout, 25);
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | height | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get width() {
return this.options.columns || utils.width(this.stdout, 80);
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | width | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get size() {
return { width: this.width, height: this.height };
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | size | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
set cursor(value) {
this.state.cursor = value;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | cursor | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get cursor() {
return this.state.cursor;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | cursor | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
set input(value) {
this.state.input = value;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | input | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get input() {
return this.state.input;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | input | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
set value(value) {
this.state.value = value;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | value | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
get value() {
let { input, value } = this.state;
let result = [value, input].find(this.isValue.bind(this));
return this.isValue(result) ? result : this.initial;
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | value | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
static get prompt() {
return options => new this(options).run();
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | prompt | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
function setOptions(prompt) {
let isValidKey = key => {
return prompt[key] === void 0 || typeof prompt[key] === 'function';
};
let ignore = [
'actions',
'choices',
'initial',
'margin',
'roles',
'styles',
'symbols',
'theme',
'timers',
'value'
];
let ignoreFn = [
... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | setOptions | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
isValidKey = key => {
return prompt[key] === void 0 || typeof prompt[key] === 'function';
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | isValidKey | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
isValidKey = key => {
return prompt[key] === void 0 || typeof prompt[key] === 'function';
} | Base class for creating a new Prompt.
@param {Object} `options` Question object. | isValidKey | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
function margin(value) {
if (typeof value === 'number') {
value = [value, value, value, value];
}
let arr = [].concat(value || []);
let pad = i => i % 2 === 0 ? '\n' : ' ';
let res = [];
for (let i = 0; i < 4; i++) {
let char = pad(i);
if (arr[i]) {
res.push(char.repeat(arr[i]));
} els... | Base class for creating a new Prompt.
@param {Object} `options` Question object. | margin | javascript | enquirer/enquirer | lib/prompt.js | https://github.com/enquirer/enquirer/blob/master/lib/prompt.js | MIT |
onExit = (quit, code) => {
if (onExitCalled) return;
onExitCalled = true;
onExitCallbacks.forEach(fn => fn());
if (quit === true) {
process.exit(128 + code);
}
} | Get a value from the given object.
@param {Object} obj
@param {String} prop | onExit | javascript | enquirer/enquirer | lib/utils.js | https://github.com/enquirer/enquirer/blob/master/lib/utils.js | MIT |
onExit = (quit, code) => {
if (onExitCalled) return;
onExitCalled = true;
onExitCallbacks.forEach(fn => fn());
if (quit === true) {
process.exit(128 + code);
}
} | Get a value from the given object.
@param {Object} obj
@param {String} prop | onExit | javascript | enquirer/enquirer | lib/utils.js | https://github.com/enquirer/enquirer/blob/master/lib/utils.js | MIT |
set(val) {
custom = val;
} | Get a value from the given object.
@param {Object} obj
@param {String} prop | set | javascript | enquirer/enquirer | lib/utils.js | https://github.com/enquirer/enquirer/blob/master/lib/utils.js | MIT |
get() {
return custom ? custom() : fn();
} | Get a value from the given object.
@param {Object} obj
@param {String} prop | get | javascript | enquirer/enquirer | lib/utils.js | https://github.com/enquirer/enquirer/blob/master/lib/utils.js | MIT |
renderScaleKey() {
if (this.scaleKey === false) return '';
if (this.state.submitted) return '';
let scale = this.scale.map(item => ` ${item.name} - ${item.message}`);
let key = ['', ...scale].map(item => this.styles.muted(item));
return key.join('\n');
} | Render the scale "Key". Something like:
@return {String} | renderScaleKey | javascript | enquirer/enquirer | lib/prompts/scale.js | https://github.com/enquirer/enquirer/blob/master/lib/prompts/scale.js | MIT |
renderScaleHeading(max) {
let keys = this.scale.map(ele => ele.name);
if (typeof this.options.renderScaleHeading === 'function') {
keys = this.options.renderScaleHeading.call(this, max);
}
let diff = this.scaleLength - keys.join('').length;
let spacing = Math.round(diff / (keys.length - 1));
... | Render the heading row for the scale.
@return {String} | renderScaleHeading | javascript | enquirer/enquirer | lib/prompts/scale.js | https://github.com/enquirer/enquirer/blob/master/lib/prompts/scale.js | MIT |
highlight(code, lang) {
let hljs = require('highlight.js');
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, code).value;
} catch (err) {}
}
try {
return hljs.highlightAuto(code).value;
} catch (err) {}
return code;
} | Default options for highlight.js markdown plugin | highlight | javascript | enquirer/enquirer | support/build/defaults.js | https://github.com/enquirer/enquirer/blob/master/support/build/defaults.js | MIT |
function getDerivative(derivative, t, vs) {
// the derivative of any 't'-less function is zero.
var n = vs.length - 1,
_vs,
value,
k;
if (n === 0) {
return 0;
}
// direct values? compute!
if (derivative === 0) {
value = 0;
for (k = 0; k <= n; k++) {
value += binomials(n,... | Compute the curve derivative (hodograph) at t. | getDerivative | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function B(xs, ys, t) {
var xbase = getDerivative(1, t, xs);
var ybase = getDerivative(1, t, ys);
var combined = xbase * xbase + ybase * ybase;
return Math.sqrt(combined);
} | Compute the curve derivative (hodograph) at t. | B | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function getCubicArcLength(xs, ys, t) {
var z, sum, i, correctedT;
/*if (xs.length >= tValues.length) {
throw new Error('too high n bezier');
}*/
if (t === undefined) {
t = 1;
}
var n = 20;
z = t / 2;
sum = 0;
for (i = 0; i < n; i++) {
correctedT = z * tValues[n][i] + z;
sum += cVal... | Compute the curve derivative (hodograph) at t. | getCubicArcLength | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function unit_vector_angle$1(ux, uy, vx, vy) {
var sign = (ux * vy - uy * vx < 0) ? -1 : 1;
var dot = ux * vx + uy * vy;
// Add this to work with arbitrary vectors:
// dot /= Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
// rounding errors, e.g. -1.0000000000000002 can screw up this
if (do... | Compute the curve derivative (hodograph) at t. | unit_vector_angle$1 | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function get_arc_center$1(x1, y1, x2, y2, fa, fs, rx, ry, sin_phi, cos_phi) {
// Step 1.
//
// Moving an ellipse so origin will be the middlepoint between our two
// points. After that, rotate it to line up ellipse axes with coordinate
// axes.
//
var x1p = cos_phi*(x1-x2)/2 + sin_phi*(y1-y2)/2;
var y1... | Compute the curve derivative (hodograph) at t. | get_arc_center$1 | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function approximate_unit_arc$1(theta1, delta_theta) {
var alpha = 4/3 * Math.tan(delta_theta/4);
var x1 = Math.cos(theta1);
var y1 = Math.sin(theta1);
var x2 = Math.cos(theta1 + delta_theta);
var y2 = Math.sin(theta1 + delta_theta);
return [ x1, y1, x1 - y1*alpha, y1 + x1*alpha, x2 + y2*alpha, y2 - x2*al... | Compute the curve derivative (hodograph) at t. | approximate_unit_arc$1 | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
Arc = function(x0, y0, rx,ry, xAxisRotate, LargeArcFlag,SweepFlag, x,y) {
return new Arc$1(x0, y0, rx,ry, xAxisRotate, LargeArcFlag,SweepFlag, x,y);
} | Compute the curve derivative (hodograph) at t. | Arc | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
function Arc$1(x0, y0,rx,ry, xAxisRotate, LargeArcFlag,SweepFlag,x,y) {
var length = 0;
var partialLengths = [];
var curves = [];
var res = a2c$3(x0, y0,rx,ry, xAxisRotate, LargeArcFlag,SweepFlag,x,y);
res.forEach(function(d){
var curve = new Bezier(d[0], d[1], d[2], d[3], d[4], d[5], d[6], ... | Compute the curve derivative (hodograph) at t. | Arc$1 | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
LinearPosition = function(x0, x1, y0, y1) {
return new LinearPosition$1(x0, x1, y0, y1);
} | Compute the curve derivative (hodograph) at t. | LinearPosition | javascript | veltman/flubber | build/flubber.js | https://github.com/veltman/flubber/blob/master/build/flubber.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.