compare-shield
Version:
A coercion-free numeric comparison utility for <, <=, >, >= within JavaScript's safe integer range.
24 lines (23 loc) • 955 B
TypeScript
export type ComparisonOperator = "<" | "<=" | ">" | ">=";
export type ComparisonValue = number | null | undefined;
/**
* Executes a strict numeric comparison without implicit type conversion.
* Ensures that both operands are valid finite numbers.
* Returns false for invalid inputs, unsupported operators, or special numeric values.
*
* @param a - First operand to compare
* @param operator - Comparison operator: '<', '<=', '>', '>='
* @param b - Second operand to compare
* @returns True if both operands are valid and the comparison succeeds; false otherwise
*
* @example
* import { compare } from 'compare-shield';
*
* compare(5, '<', 10); // true
* compare(3.14, '<=', 3.14); // true
* compare(null, '<', 5); // false
* compare(NaN, '>=', 0); // false
* compare(Infinity, '<', 1000); // false
*/
export declare function compare(a: ComparisonValue, operator: ComparisonOperator, b: ComparisonValue): boolean;
export default compare;