1.1.0 • Published 2 years ago

@fvilers/is-nil v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

is-nil

A TypeScript type guard that validates if the given value is nil

Installation

npm install @fvilers/is-nil

or

yarn add @fvilers/is-nil

Usage

import { isNil, isNotNil } from "@fvilers/is-nil";

const variable: string | null = "This is a string";

if (isNil(variable)) {
  console.log("Variable is null");
} else {
  // From here, variable is strongly typed as a non null string
  console.log("Variable is a string with length of", variable.length);
}

if (isNotNil(variable)) {
  // From here, variable is strongly typed as a non null string
  console.log("Variable is a string with length of", variable.length);
} else {
  console.log("Variable is null");
}

It will output:

Variable is a string with length of 16
Variable is a string with length of 16
1.1.0

2 years ago

1.0.0

2 years ago