Skip to content

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

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

docs: fix hex example to match the Buffer it formats#1054
FirmaSpring wants to merge 1 commit into
debug-js:masterfrom
FirmaSpring:docs/fix-hex-example

Conversation

@FirmaSpring

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>
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.

1 participant