Skip to content

Commit

Permalink
add buf-compare replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel committed Nov 11, 2024
1 parent d501018 commit 17b2d5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/modules/buf-compare.md
Original file line number Diff line number Diff line change
@@ -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
const {Buffer} = require('node:buffer');

const buf1 = Buffer.from('1234');
const buf2 = Buffer.from('0123');
const arr = [buf1, buf2];

console.log(arr.sort(Buffer.compare));
// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
// (This result is equal to: [buf2, buf1].)
```

[Node.js Docs](https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2)
6 changes: 6 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"docPath": "bluebird-q",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "buf-compare",
"docPath": "buf-compare",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "builtin-modules",
Expand Down

0 comments on commit 17b2d5d

Please # to comment.