/throw-if-arg-empty

Throw if an argument is empty

Primary LanguageTypeScriptMIT LicenseMIT

throw-if-arg-empty

Build Status npm version Node.js Version

Throws if the specified argument is empty/nullable.

Installation

npm i throw-if-arg-empty

Example

import { throwIfEmpty } from 'throw-if-arg-empty';

function foo(name) {
  throwIfEmpty(name, 'name');
}

foo();
// throws: Error: The argument "name" cannot be empty

APIs

// Throws if argument is `undefined` or `null`.
function throwIfEmptyStrict(argument: unknown, name: string): void;

// Throws if argument is `undefined`, `null` or an empty array.
function throwIfEmpty(argument: unknown, name: string): void;

// Throws if argument is falsy.
function throwIfFalsyStrict(argument: unknown, name: string): void;

// Throws if argument is falsy or an empty array.
function throwIfFalsy(argument: unknown, name: string): void;