ge
The ge utility checks if the first value is greater than or equal to 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 greater than or equal to the second argument.
*
* @example
* ```ts
* gte(5, 3); // true
* gte(3, 5); // false
* gte(5, 5); // true
* gte(5, '3'); // false
* gte('5', 3); // false
* gte('5', '3'); // false
* ```
* @param a - The first argument to compare.
* @param b - The second argument to compare.
*
* @returns `true` if `a` is greater than or equal to `b`, otherwise `false`.
*/
export function ge(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 ge(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 { ge } from '@vielzeug/toolkit';
ge(10, 5); // true
ge(5, 5); // true
ge(3, 10); // false
ge('b', 'a'); // trueImplementation Notes
- Returns
trueifa >= b. - Uses standard JavaScript comparison rules.
- Throws nothing; safe for any comparable types.