throw-if-arg-empty
v3.1.0
Published
Throws if the specified argument is empty/nullable
Downloads
23
Readme
throw-if-arg-empty
Throws if the specified argument is empty/nullable.
Installation
yarn add 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;