Skip to content

Commit

Permalink
feat(numeric): adding numericEquals condition operator
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Feb 25, 2021
1 parent 93752c9 commit 46b89c8
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,10 +1,12 @@
import {numericEquals} from './numeric/numericEquals';
import {stringEquals} from './string/stringEquals';
import {stringEqualsIgnoreCase} from './string/stringEqualsIgnoreCase';
import {stringLike} from './string/stringLike';
import {stringNotEquals} from './string/stringNotEquals';
import {stringNotEqualsIgnoreCase} from './string/stringNotEqualsIgnoreCase';

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

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

it('returns false', () => {
expect(numericEquals(5, 6)).toBeFalsy;
expect(numericEquals(-1, 1)).toBeFalsy;
expect(numericEquals(Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER)).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/numeric/numericEquals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Exact numeric 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 equal to `expected value`.
* @example
* ```javascript
* numericEquals(5, 5)
* // => true
*
* numericEquals(2, 4)
* // => false
* ```
*/
export function numericEquals(data: number, expected: number): boolean {
return (
data === expected
);
}

0 comments on commit 46b89c8

Please sign in to comment.