get-or-throw
v3.0.1
Published
A convenience function for safely getting values from dynamic objects and arrays
Maintainers
Readme
Get-Or-Throw
A convenience function for safely accessing values in dynamic objects and
arrays. It gets the value at a specified key or index, and throws an error if
the resulting value is undefined.
Features
- TypeScript assertions for type narrowing
- Works with both objects and arrays
- Supports negative indexing for arrays
- Allows for custom error messages
- Zero dependencies
- Provides
gotas alias forgetOrThrow
Quick Start
pnpm add get-or-throwimport { got } from "get-or-throw";
const arr = [1, 2, 3];
got(arr, 1); // 2
const obj = { a: 1, b: 2, c: 3 };
got(obj, "b"); // 2Documentation
For full documentation visit get-or-throw.codecompose.dev.
License
MIT
