Skip to content
VersionSize

isZero

The isZero utility is a type guard that checks if a given number is exactly equal to zero.

Implementation

View Source Code
ts
/**
 * Checks if the value is a positive number.
 *
 * @example
 * ```ts
 * isPositive(0); // true
 * isPositive(123); // false
 * isPositive(-123); // false
 * isPositive(0.0000001); // false
 * isPositive('hello world'); // false
 * isPositive({}); // false
 * isPositive([]); // false
 * isPositive(new Date()); // false
 * isPositive(null); // false
 * isPositive(undefined); // false
 * isPositive(NaN); // false
 * ```
 *
 * @param arg - The argument to be checked.
 *
 * @returns `true` if the value is a positive number, else `false`.
 *
 */
export function isZero(arg: unknown): arg is number {
  return typeof arg === 'number' && arg === 0;
}

Features

  • Isomorphic: Works in both Browser and Node.js.
  • Strict Equality: Only returns true for the numeric value 0.
  • Type-safe: Properly typed for numeric inputs.

API

ts
function isZero(value: number): boolean;

Parameters

  • value: The number to check.

Returns

  • true if the number is zero; otherwise, false.

Examples

Basic Usage

ts
import { isZero } from '@vielzeug/toolkit';

isZero(0); // true
isZero(-0); // true (JavaScript considers 0 and -0 equal)
isZero(1); // false
isZero(0.1); // false

Implementation Notes

  • Returns true if value === 0.
  • Throws nothing; returns false for non-numeric inputs if TypeScript checks are bypassed.

See Also