Skip to content
VersionSize

lt

The lt utility checks if the first value is strictly less than the second value. It works with any comparable types, including numbers, strings, and Dates.

Implementation

View Source Code
ts
/**
 * Checks if the first argument is less than the second argument.
 *
 * @example
 * ```ts
 * lt(3, 5); // true
 * lt(5, 3); // false
 * lt(5, 5); // false
 * ```
 *
 * @param a - The first argument to compare.
 * @param b - The second argument to compare.
 *
 * @returns `true` if `a` is less than `b`, otherwise `false`.
 */
export function lt(a: unknown, b: unknown): boolean {
  return typeof a === 'number' && typeof b === 'number' && a < b;
}

Features

  • Isomorphic: Works in both Browser and Node.js.
  • Versatile: Supports multiple data types.
  • Type-safe: Properly typed for comparable inputs.

API

ts
function lt(a: number, b: number): boolean;

Parameters

  • a: The value to compare.
  • b: The value to compare against.

Returns

  • true if a < b; otherwise, false.

Examples

Basic Usage

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

lt(5, 10); // true
lt(10, 5); // false
lt(5, 5); // false
lt('a', 'b'); // true

Implementation Notes

  • Returns true if a < b.
  • Uses standard JavaScript comparison rules.
  • Throws nothing; safe for any comparable types.

See Also

  • le: Less than or equal to.
  • gt: Greater than.
  • ge: Greater than or equal to.