New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

get-or-throw

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-or-throw

A convenience function for safely getting values from dynamic objects and arrays

latest
Source
npmnpm
Version
2.2.0
Version published
Weekly downloads
13K
-24.26%
Maintainers
1
Weekly downloads
 
Created
Source

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 got as alias for getOrThrow

Quick Start

pnpm add get-or-throw
import { 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"); // 2

Documentation

For full documentation visit get-or-throw.codecompose.dev.

License

MIT

Keywords

indexed

FAQs

Package last updated on 19 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts