UNPKG

@hazae41/cursor

Version:

Rust-like Cursor for TypeScript

43 lines (29 loc) 701 B
# Cursor ```bash npm i @hazae41/cursor ``` [**Node Package 📦**](https://www.npmjs.com/package/@hazae41/cursor) ## Features ### Current features - 100% TypeScript and ESM - No external dependencies - Zero-copy reading and writing - Rust-like patterns - Unit-tested ## Usage ### Cursor #### Writing ```typescript const cursor = Cursor.allocUnsafe(1024) cursor.tryWriteUint8(123).unwrap() cursor.tryWriteUint16(1234).unwrap() console.log(cursor.offset) // 3 ``` #### Reading ```typescript const bytes = new Uint8Array(/*...*/) const cursor = new Cursor(bytes) const uint8 = cursor.tryReadUint8().unwrap() const uint16 = cursor.tryReadUint16().unwrap() console.log(cursor.offset) // 3 ```