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