Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed May 3, 2024
1 parent 6c21785 commit 4f3610f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ export class Buffer extends Uint8Array {

/**
* Compares `this` with `target` and returns a number indicating whether `this` comes before, after, or is the same as `target` in sort order. Comparison is based on the actual sequence of bytes in each `Buffer`.
*
* The optional targetStart, targetEnd, sourceStart, and sourceEnd arguments can be used to limit the comparison to specific ranges within target and buf respectively.
* @param target - A `Buffer` or `Uint8Array` with which to compare `this`.
* @param targetStart - The offset within `target` at which to begin comparison. Default: `0`.
* @param targetEnd - The offset within `target` at which to end comparison (not inclusive). Default: `target.length`.
Expand Down Expand Up @@ -795,6 +797,19 @@ export class Buffer extends Uint8Array {
* // Prints: ['ABC', 'ABCD', 'BCD']
* })()
* ```
* @example
* ```js
* ;(async function () {
* const { Buffer } = await import('https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/dist/buffer.mjs/+esm')
*
* const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9])
* const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4])
*
* console.log(buf1.compare(buf2, 5, 9, 0, 4)) // Prints: 0
* console.log(buf1.compare(buf2, 0, 6, 4)) // Prints: -1
* console.log(buf1.compare(buf2, 5, 6, 5)) // Prints: 1
* })()
* ```
*/
compare (
target: any,
Expand Down

0 comments on commit 4f3610f

Please sign in to comment.