From 7dea6e8bc9629bb6a78dcd8d156c73754f063dbd Mon Sep 17 00:00:00 2001 From: Michael Stramel Date: Tue, 12 Nov 2024 22:21:02 -0800 Subject: [PATCH] docs: add `buf-compare` replacement (#181) --- docs/modules/README.md | 1 + docs/modules/buf-compare.md | 21 +++++++++++++++++++++ manifests/preferred.json | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 docs/modules/buf-compare.md diff --git a/docs/modules/README.md b/docs/modules/README.md index 9a537a9..a016afd 100644 --- a/docs/modules/README.md +++ b/docs/modules/README.md @@ -14,6 +14,7 @@ ESLint plugin. - [`@jsdevtools/ez-spawn`](./process-exec.md) - [`bluebird` / `q`](./bluebird-q.md) +- [`buf-compare`](./buf-compare.md) - [`buffer-equal` / `buffer-equals`](./buffer-equal.md) - [`cpx`](./cpx.md) - [`deep-equal`](./deep-equal.md) diff --git a/docs/modules/buf-compare.md b/docs/modules/buf-compare.md new file mode 100644 index 0000000..f8bf45f --- /dev/null +++ b/docs/modules/buf-compare.md @@ -0,0 +1,21 @@ +# buf-compare + +[`buf-compare`](https://github.com/sindresorhus/buf-compare) recommends that you switch to native `Buffer.compare()` which has been available since Node.js v0.12.0 + +# Alternatives + +## NodeJS + +```js +import {Buffer} from 'node:buffer'; + +const buf1 = Buffer.from('1234'); +const buf2 = Buffer.from('0123'); +const arr = [buf1, buf2]; + +console.log(arr.sort(Buffer.compare)); +// Prints: [ , ] +// (This result is equal to: [buf2, buf1].) +``` + +[Node.js Docs](https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2) diff --git a/manifests/preferred.json b/manifests/preferred.json index 7f7da2b..a761909 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -12,6 +12,12 @@ "docPath": "bluebird-q", "category": "preferred" }, + { + "type": "documented", + "moduleName": "buf-compare", + "docPath": "buf-compare", + "category": "preferred" + }, { "type": "documented", "moduleName": "buffer-equal",