@bearing-dev/compass
v0.0.1
Published
Headless navigation state for lists and trees
Downloads
10
Maintainers
Readme
@bearing-dev/compass
Headless navigation cursor for ordered and nested content.
Designed for documentation sites, learning paths, keyboard-driven navigation, terminal UIs, and anywhere you need to traverse structured content without coupling to a framework or DOM.
const nav = createNavigator({ items: ['a', 'b', 'c'] });
nav.next(); // move forward
nav.prev(); // move back
nav.current; // where you are nowWorks with nested items too:
const nav = createNavigator({
items: [
{ slug: 'ch-1', children: ['1.1', '1.2'] },
{ slug: 'ch-2' }
]
});
nav.next(); // ch-1 → 1.1
nav.parent(); // 1.1 → ch-1
nav.firstChild(); // ch-1 → 1.1Options
wrap- loop around at the ends (default: true)leavesOnly- skip parents, only visit leaves
Details
No framework needed. Handles edge cases like wrapping, siblings, and depth-first traversal. See src/types.ts for full API.
