Skip to content

Commit 35d2137

Browse files
committed
doc: modernize and fix code examples in repl.md
* Improve UX in 2 code examples (add spaces between output and input for better readability). * Replace indexOf() by startsWith(). PR-URL: #12634 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 4241577 commit 35d2137

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/api/readline.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ For example:
158158

159159
```js
160160
rl.on('SIGINT', () => {
161-
rl.question('Are you sure you want to exit?', (answer) => {
161+
rl.question('Are you sure you want to exit? ', (answer) => {
162162
if (answer.match(/^y(es)?$/i)) rl.pause();
163163
});
164164
});
@@ -255,7 +255,7 @@ If the `readline.Interface` was created with `output` set to `null` or
255255
Example usage:
256256

257257
```js
258-
rl.question('What is your favorite food?', (answer) => {
258+
rl.question('What is your favorite food? ', (answer) => {
259259
console.log(`Oh, so your favorite food is ${answer}`);
260260
});
261261
```
@@ -414,7 +414,7 @@ For instance: `[[substr1, substr2, ...], originalsubstring]`.
414414
```js
415415
function completer(line) {
416416
const completions = '.help .error .exit .quit .q'.split(' ');
417-
const hits = completions.filter((c) => c.indexOf(line) === 0);
417+
const hits = completions.filter((c) => c.startsWith(line));
418418
// show all completions if none found
419419
return [hits.length ? hits : completions, line];
420420
}

0 commit comments

Comments
 (0)