Socket
Book a DemoInstallSign in
Socket

is-not-null-or-undefined

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-not-null-or-undefined

A TypeScript utility function to check if a value is not null or undefined

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

is-not-null-or-undefined

A TypeScript utility function & type-guard to check if a value is not null or undefined.

Installation

npm

npm install is-not-null-or-undefined

yarn

yarn add is-not-null-or-undefined

pnpm

pnpm add is-not-null-or-undefined

Usage

import { isNotNullOrUndefined } from 'is-not-null-or-undefined';

// Returns true for non-`null` and non-`undefined` values
isNotNullOrUndefined('string'); // true
isNotNullOrUndefined(123); // true
isNotNullOrUndefined({}); // true
isNotNullOrUndefined([]); // true
isNotNullOrUndefined(false); // true
isNotNullOrUndefined(0); // true

// Returns false for `null` and `undefined` values
isNotNullOrUndefined(null); // false
isNotNullOrUndefined(undefined); // false

Type Guard

The function acts as a TypeScript type guard, narrowing the type from T | null | undefined to T:

const value: string | null | undefined = getValue();

if (isNotNullOrUndefined(value)) {
  // value is now typed as string
  console.log(value.toUpperCase());
}

Keywords

typescript

FAQs

Package last updated on 12 Sep 2025

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