Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
apply suggestions from @bnb code review
  • Loading branch information
mfdebian committed Oct 17, 2024
commit f8e78b159ffdeeb95513583efb57326fe8dba964
21 changes: 11 additions & 10 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,33 +303,34 @@ When a new [`repl.REPLServer`][] is created, a custom evaluation function may be
provided. This can be used, for instance, to implement fully customized REPL
applications.

The following illustrates a hypothetical example of a REPL that performs
translation of text from one language to another:
The following illustrates an example of a REPL that squares a given number:

```mjs
import repl from 'node:repl';
import { Translator } from 'translator';

const myTranslator = new Translator('en', 'fr');
function byThePowerOfTwo(number) {
return number * number;
}

function myEval(cmd, context, filename, callback) {
callback(null, myTranslator.translate(cmd));
callback(null, byThePowerOfTwo(cmd));
}

repl.start({ prompt: '> ', eval: myEval });
repl.start({ prompt: 'Enter a number: ', eval: myEval });
```
Comment on lines +309 to +320

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code block adds a mock dependency to a module that actually exists and is very dormant (translator). IMO we should try to avoid that and the alternative of using a module that doesn't exist.

While this is also true of the previously existing example, since it's being updated now with a totally new example I think it's a good time to adjust it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I also thought about that example since it throws an error when you try to execute it as is and new users can be frustrated by that, I'll come up with a good alternative and update as soon as I can! Thanks for the feedback! 🙌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the example, tell me what you think! 😊 And again, thank you for taking the time to provide feedback! 🙏


```cjs
const repl = require('node:repl');
const { Translator } = require('translator');

const myTranslator = new Translator('en', 'fr');
function byThePowerOfTwo(number) {
return number * number;
}

function myEval(cmd, context, filename, callback) {
callback(null, myTranslator.translate(cmd));
callback(null, byThePowerOfTwo(cmd));
}

repl.start({ prompt: '> ', eval: myEval });
repl.start({ prompt: 'Enter a number: ', eval: myEval });
```

#### Recoverable errors
Expand Down