Skip to content
VersionSize

le

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

Implementation

View Source Code
ts
/**
 * Check if the first argument is less than or equal to the second argument.
 *
 * @example
 * ```ts
 * le(3, 5); // true
 * le(5, 3); // false
 * le(5, 5); // true
 * ```
 *
 * @param a - The first argument to compare.
 * @param b - The second argument to compare.
 *
 * @returns `true` if `a` is less than or equal to `b`, otherwise `false`.
 */
export function le(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 le(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 { le } from '@vielzeug/toolkit';

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

Implementation Notes

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

See Also

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