Skip to content

Commit

Permalink
feat(numeric): adding numericLessThan condition operator
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Feb 25, 2021
1 parent 1de1638 commit fb75c5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/conditionOperators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {numericEquals} from './numeric/numericEquals';
import {numericLessThan} from './numeric/numericLessThan';
import {numericNotEquals} from './numeric/numericNotEquals';
import {stringEquals} from './string/stringEquals';
import {stringEqualsIgnoreCase} from './string/stringEqualsIgnoreCase';
Expand All @@ -8,6 +9,7 @@ import {stringNotEqualsIgnoreCase} from './string/stringNotEqualsIgnoreCase';

export const operators: Record<string, unknown>={
numericEquals,
numericLessThan,
numericNotEquals,
stringEquals,
stringEqualsIgnoreCase,
Expand Down
15 changes: 15 additions & 0 deletions src/conditionOperators/numeric/numericLessThan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { numericLessThan } from './numericLessThan';

describe('numericLessThan', () => {
it('returns true', () => {
expect(numericLessThan(5, 7)).toBeTruthy;
expect(numericLessThan(2.2, 8.2)).toBeTruthy;
expect(numericLessThan(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)).toBeTruthy;
});

it('returns false', () => {
expect(numericLessThan(7, 5)).toBeFalsy;
expect(numericLessThan(-1, -1)).toBeFalsy;
expect(numericLessThan(Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER)).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/numeric/numericLessThan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Numeric less than matching.
*
* @since 4.6.0
* @category Numeric
* @param {number} data The value to be compared.
* @param {number} expected The expected value.
* @returns {boolean} Returns `true` if `value` is less than `expected value`.
* @example
* ```javascript
* numericLessThan(5, 6)
* // => true
*
* numericLessThan(8, 4)
* // => false
* ```
*/
export function numericLessThan(data: number, expected: number): boolean {
return (
data < expected
);
}

0 comments on commit fb75c5f

Please sign in to comment.