-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: add esm examples to node:util
#56793
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need destructed object ?
Hello @AugustinMauroy sorry I took so long to answer, I was on vacation. That's a feedback I received from other maintainers as I've been updating the docs to ensure all examples from the API docs have both their Most Thanks for your review! 🙌 tell me if you have any more questions or wish to ask for a change! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSLGTM
Landed in c05f4ba |
PR-URL: #56793 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This PR adds the missing
ESM
counterparts of theCJS
examples for the Util documentation.I also destructured the (
require
) imports for the currentCJS
examples following a feedback I had received in previous PRs.For the
numericSeparator
example ofutil.inspect(object[, showHidden[, depth[, colors]]])
I took the liberty to leave the numbers like this:Instead of:
Because that's actually what we want to showcase, how
numericSeparator
would add the missing underscores to print:For the
Box
andutil.inspect.custom
examples at Custom inspection functions on objects I added a finalconsole.log
so users don't have to add it themselves when copy/pasting the example to see an output.For the
util.inspect.defaultOptions
example I incremented the number of 0's to be added just so the output is more dramatic and it would showcase the function better imo, it would also print a square on the terminal which looks pretty awesome:For the
promisify()
class methods that use this example atutil.promisify(original)
, the one with:I updated the error message, since now it's:
TypeError: Cannot read properties of undefined (reading 'a')
instead ofTypeError: Cannot read property 'a' of undefined
.Lastly, for the
util.styleText(format, text[, options])
there was a typo on the example that recently got fixed but only for theESM
part, this adds theCJS
fix for that typo.I think that's all, tell me what you think and I can update/change things around!
I've tested every single example and they all work/behave as expected.
As always, best regards 💚
Edit:
For the
util.deprecate(fn, msg[, code])
example (the second one) I also added the functions and messages so users can just copy/paste that portion of code and run it without encountering errors.