This rule is more targeted for cross platform compatibility reasons. node:buffer
is a node specific module and i mostly just see it as something that bloats browser bundles and runs slower (in none NodeJS contexts - or using npm:buffer
instead of node:buffer
).
TextEncoder
/ TextDecoder
can be used instead to turn your buffer to / from string / Uint8Array and is also actually much faster then Buffer.from(str)
(which originally use string_decoder) in the browser,buffer.slice
is also overriding uint8array.slice
with subarray, which is also unexpected and now also deprecated Buffer.isBuffer
can be replaced with instaceof Uint8Array
to be acceptable of both Uint8Array
and node:buffer
. something even better would be to accept any TypedArray using ArrayBuffer.isView
buf.toString()
I bet if you read this issue then you will maybe also be convinced that node:buffer
is just unnecessary.
Buffer.from('hello world')Pass
new TextEncoder().encode('hello world')Additional Info
Replacing node:buffer
with Uint8Array
can be a lot. and maybe not that easy to autofix
Maybe dividing it up to smaller task could be easier.
like
TextDecoder
over buf.toString()
and node:string_encoder
instanceof Uint8Array
over Buffer.isBuffer
or something like that...sindresorhus, jimmywarting, yudai-nkt, esdmr, juliomrqz and 2 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4