An idiomatic way to enforce values not to be null nor undefined, with first-class support for TypeScript

Overview

nullthrows

An idiomatic way to enforce values not to be null or undefined, with first-class support for TypeScript. Very lightweight with no dependencies.

Installation and usage

npm install @expo/nullthrows
import process from 'node:process';
import nullthrows from '@expo/nullthrows';

// nodeEnv is guaranteed to be a string. If the environment variable is
// undefined, nullthrows throws a TypeError.
const nodeEnv = nullthrows(process.env.NODE_ENV);

// You can optionally provide a custom error message
const nodeEnv2 = nullthrows(process.env.NODE_ENV, `NODE_ENV must be defined`);

API

function nullthrows<T>(value: T | null | undefined, message?: string): NonNullable<T>

Parameters

  • value: the value to enforce not to be null or undefined
  • message: an optional error message to use in the thrown TypeError if the given value is null or undefined

Type parameters

  • T: the static type of value

Return value

Returns value if it is neither null nor undefined.

Throws

Throws a TypeError if value is null or undefined.

History

This package is a spiritual successor of nullthrows. The motivation for a new package was primarily to support using TypeScript with ES modules since the type declarations included with nullthrows produce type errors.

You might also like...

A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Jul 10, 2022

⚡ the first open-source redis client made with care and acessibility-first 🚀

⚡ Redis UI The first open-source project to create an awesome and accessible UI for Redis as a native desktop application. ✨ 🦄 🚀 How to develop loca

Dec 5, 2022

🦢 A public CS:GO Clicker cheat! (Not meant to be used in a bad way)

🦢 A public CS:GO Clicker cheat! (Not meant to be used in a bad way)

WetBird Strongly inspired by: https://greasyfork.org/en/scripts/446977-mopsek-csgo-mtsl-2-mod-menu/ Information Wetbird is a cheat for Case Clicker 2.

Nov 13, 2022

Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Parameter Store in bulk and output them in environment-file or json forma

Oct 18, 2022

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Oct 23, 2022

This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild).

💽 remix-esbuild-override ⚠️ While I believe you will most likely get a lot of benefit from using this library, it can sometimes destroy your product.

Dec 22, 2022

Compare 👥 and extract 🔬 differences between JSON values

json-changes Easily compare changes in JSON-like values. This can be especially useful when you want to compare an incoming payload with a counterpart

Aug 23, 2022
Releases(v1.0.0)
Owner
Expo
Expo is a free and open-source platform for making universal native apps with React that run on Android, iOS, and the web.
Expo
🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

?? TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

CodelyTV 82 Dec 7, 2022
Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.

@suchipi/is Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values. Usage import { is

Lily Skye 5 Sep 8, 2022
A webpack plugin to enforce case-sensitive paths when resolving module

@umijs/case-sensitive-paths-webpack-plugin A webpack plugin to enforce case-sensitive paths when resolving module, similar to the well-known case-sens

UmiJS 13 Jul 25, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
null

ScrollUp A jQuery plugin to create a customisable 'Scroll to top' feature that will work with any website Installing with Bower To install scrollUp wi

Mark Goodyear 995 Jan 2, 2023
A refined tool for exploring open-source projects on GitHub with a file tree, rich Markdown and image previews, multi-pane multi-tab layouts and first-class support for Ink syntax highlighting.

Ink codebase browser, "Kin" ?? The Ink codebase browser is a tool to explore open-source code on GitHub, especially my side projects written in the In

Linus Lee 20 Oct 30, 2022
Plugin to enable PDF files as first class citizens within an Obsidian vault.

Obsidian-PDF Plugin to enable PDF files as first class citizens within an Obsidian vault. What does this plugin do for me? All PDF files in your vault

Noah Cabral 16 Nov 26, 2022
Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Stephanie Eckles 65 Nov 2, 2022