Skip to content

Commit 0a22a53

Browse files
committed
Add docs for orderUint8Array
1 parent 5d68a77 commit 0a22a53

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

packages/common/src/Order.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,23 @@ export const orderNumber = createOrder<number>((a, b) => a < b);
9494
*/
9595
export const orderBigInt = createOrder<bigint>((a, b) => a < b);
9696

97-
export const orderUint8Array: Order<globalThis.Uint8Array> = (a, b) => {
97+
/**
98+
* An {@link Order} for {@link Uint8Array} values.
99+
*
100+
* Comparison is performed in two phases:
101+
*
102+
* 1. Compare `byteLength` (shorter arrays are considered smaller).
103+
* 2. If lengths are equal, compare bytes lexicographically (ascending).
104+
*
105+
* ### Example
106+
*
107+
* ```ts
108+
* orderUint8Array(new Uint8Array([1, 2]), new Uint8Array([1, 2, 3])); // -1
109+
* orderUint8Array(new Uint8Array([1, 2, 3]), new Uint8Array([1, 2])); // 1
110+
* orderUint8Array(new Uint8Array([1, 2]), new Uint8Array([1, 3])); // -1
111+
* ```
112+
*/
113+
export const orderUint8Array: Order<Uint8Array> = (a, b) => {
98114
if (a.byteLength > b.byteLength) return 1;
99115
if (a.byteLength < b.byteLength) return -1;
100116

0 commit comments

Comments
 (0)