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')
new TextEncoder().encode('hello world')
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...Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too