throw-if-arg-empty
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

throw-if-arg-empty

Build Status npm version Node.js Version

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;

Readme

Keywords

none

Package Sidebar

Install

npm i throw-if-arg-empty

Weekly Downloads

3

Version

3.1.0

License

MIT

Unpacked Size

5.38 kB

Total Files

8

Last publish

Collaborators

  • mgenware