-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add
buf-compare
replacement (#181)
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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: [ <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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters