Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (valid) {
stdout.write(label)
} else {
const _label = label.replace('-', '✖')
stdout.write(chalk.red(_label))
}
value = initialValue
stdout.write(initialValue)
if (mask) {
if (!value) {
value = chalk.gray(placeholder)
caretOffset = 0 - stripAnsi(value).length
stdout.write(value)
stdout.write(ansiEscapes.cursorBackward(Math.abs(caretOffset)))
}
regex = placeholder
.split('')
.reduce((prev, curr) => {
if (curr !== ' ' && !prev.includes(curr)) {
if (curr === '/') {
prev.push(' / ')
} else {
prev.push(curr)
}
}
return prev
}, [])
.join('|')
regex = new RegExp(`(${regex})`, 'g')
caretOffset += formattedData.length
}
} else if (/\s/.test(data) && caretOffset < 0) {
caretOffset++
tmp = value
} else {
return stdout.write(ansiEscapes.beep)
}
value = tmp
} else if (validateKeypress(data, value)) {
value = tmp
if (caretOffset === 0) {
const completion = await autoComplete(value)
if (completion) {
suggestion = chalk.gray(completion)
suggestion += ansiEscapes.cursorBackward(completion.length)
} else {
suggestion = ''
}
}
} else {
return stdout.write(ansiEscapes.beep)
}
}
if (mask === 'cc' || mask === 'ccv') {
value = formatCC(value)
value = value.replace(regex, chalk.gray('$1'))
} else if (mask === 'expDate') {
value = value.replace(regex, chalk.gray('$1'))
}
caretOffset += formattedData.length
}
} else if (/\s/.test(data) && caretOffset < 0) {
caretOffset++
tmp = value
} else {
return stdout.write(ansiEscapes.beep)
}
value = tmp
} else if (validateKeypress(data, value)) {
value = tmp
if (caretOffset === 0) {
const completion = await autoComplete(value)
if (completion) {
suggestion = chalk.gray(completion)
suggestion += ansiEscapes.cursorBackward(completion.length)
} else {
suggestion = ''
}
}
} else {
return stdout.write(ansiEscapes.beep)
}
}
if (mask === 'cc' || mask === 'ccv') {
value = formatCC(value)
value = value.replace(regex, chalk.gray('$1'))
} else if (mask === 'expDate') {
value = value.replace(regex, chalk.gray('$1'))
}
val.substr(val.length + caretOffset)
}
const parts = val.split('@')
if (parts.length === 2 && parts[1].length > 0) {
const [, _host] = parts
const host = _host.toLowerCase()
for (const domain of _domains) {
if (host === domain) {
break
}
if (host === domain.substr(0, host.length)) {
suggestion = domain.substr(host.length)
completion = chalk[suggestionColor](suggestion)
completion += ansi.cursorBackward(domain.length - host.length)
break
}
}
}
if (completion.length === 0) {
suggestion = ''
}
}
process.stdout.write(ansi.eraseLines(1) + start + val + completion)
if (caretOffset) {
process.stdout.write(ansi.cursorBackward(Math.abs(caretOffset)))
}
}
caretOffset += formattedData.length;
}
} else if (/\s/.test(data) && caretOffset < 0) {
caretOffset++;
tmp = value;
} else {
return stdout.write(ansiEscapes.beep);
}
value = tmp;
} else if (validateKeypress(data, value)) {
value = tmp;
if (caretOffset === 0) {
const completion = await autoComplete(value);
if (completion) {
suggestion = chalk.gray(completion);
suggestion += ansiEscapes.cursorBackward(completion.length);
} else {
suggestion = '';
}
}
} else {
return stdout.write(ansiEscapes.beep);
}
}
if (mask === 'cc' || mask === 'ccv') {
value = formatCC(value);
value = value.replace(regex, chalk.gray('$1'));
} else if (mask === 'expDate') {
value = value.replace(regex, chalk.gray('$1'));
}
function update() {
var output = task.render();
var change = currentLine - task.line;
out.write(position.cursorUp(change));
out.write(output);
out.write(position.cursorDown(change - (out.height(output) - 1)));
out.write(position.cursorBackward(out.ln(output)));
return task;
}
exports.left = function(rl, x) {
rl.output.write(ansiEscapes.cursorBackward(x));
};
exports.left = function(rl, x) {
rl.output.write(ansiEscapes.cursorBackward(x));
};
} else {
if (resolveChars.has(s)) {
restore()
return resolve(val)
}
const add = forceLowerCase ? s.toLowerCase() : s
val =
val.substr(0, val.length + caretOffset) +
add +
val.substr(val.length + caretOffset)
}
process.stdout.write(ansi.eraseLines(1) + chalk.dim(question) + val)
if (caretOffset) {
process.stdout.write(ansi.cursorBackward(Math.abs(caretOffset)))
}
}
function backspace () {
if (input.length === 0) return
input = input.substr(0, input.length - 1)
stderr.write(ansi.cursorBackward(1))
stderr.write(ansi.eraseEndLine)
}