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
trueifa < 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'); // trueImplementation Notes
- Returns
trueifa < b. - Uses standard JavaScript comparison rules.
- Throws nothing; safe for any comparable types.