Skip to content

docs: fix hex example to match the Buffer it formats - #1054

Open
JiuYue0820 wants to merge 1 commit into
debug-js:masterfrom
JiuYue0820:docs/fix-hex-example
Open

JiuYue0820 wants to merge 1 commit into
debug-js:masterfrom
JiuYue0820:docs/fix-hex-example

Conversation

@JiuYue0820

Copy link
Copy Markdown

Problem

The custom formatters example reads:

debug('this is hex: %h', new Buffer('hello world'))
//   foo this is hex: 68656c6c6f20776f726c6421 +0ms

Two things are wrong:

  1. new Buffer(...) is deprecated since Node.js 6; the modern equivalent is Buffer.from(...).
  2. The shown output ends with 21 (the hex of !), which is not part of the input string 'hello world'. Buffer.from('hello world').toString('hex') is 68656c6c6f20776f726c64.

Solution

Use Buffer.from and drop the stray 21 so the comment matches the actual formatter output.

Verification

Buffer.from('hello world').toString('hex')
// '68656c6c6f20776f726c64'

Documentation-only change.

Co-authored-by: FirmamentalSpring <287222957+FirmaSpring@users.noreply.github.com>

@lbesecker195 lbesecker195 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked: Buffer.from('hello world').toString('hex') gives 68656c6c6f20776f726c64, so the old comment had a stray 21 (!) that isn't in the input. The README on master (line 210) still uses the deprecated new Buffer(...), and Buffer.from is the drop-in replacement. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants