Skip to content

Commit

Permalink
feat(stringoperators): adding new string operators
Browse files Browse the repository at this point in the history
stringEqualsIgnoreCase, stringNotEquals, stringNotEqualsIgnoreCase
  • Loading branch information
roggervalf committed Feb 18, 2021
1 parent 0ab50bd commit 83665fa
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/conditionOperators/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {stringEquals} from './string/stringEquals';
import {stringEqualsIgnoreCase} from './string/stringEqualsIgnoreCase';
import {stringNotEquals} from './string/stringNotEquals';
import {stringNotEqualsIgnoreCase} from './string/stringNotEqualsIgnoreCase';

export const operators: Record<string, unknown>={
stringEquals
stringEquals,
stringEqualsIgnoreCase,
stringNotEquals,
stringNotEqualsIgnoreCase
};

15 changes: 15 additions & 0 deletions src/conditionOperators/string/stringEqualsIgnoreCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stringEqualsIgnoreCase } from './stringEqualsIgnoreCase';

describe('stringEqualsIgnoreCase', () => {
it('returns true', () => {
expect(stringEqualsIgnoreCase('secrets', 'Secrets')).toBeTruthy;
expect(stringEqualsIgnoreCase('newHouse', 'NewHouse')).toBeTruthy;
expect(stringEqualsIgnoreCase('', '')).toBeTruthy;
});

it('returns false', () => {
expect(stringEqualsIgnoreCase('secrets', 'house')).toBeFalsy;
expect(stringEqualsIgnoreCase('house', 'secrets')).toBeFalsy;
expect(stringEqualsIgnoreCase('', '1')).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/string/stringEqualsIgnoreCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Exact matching, ignoring case.
*
* @since 4.4.0
* @category String
* @param {string} data The value to be compared.
* @param {string} expected The expected value.
* @returns {boolean} Returns `true` if `value` is equal to `expected value`.
* @example
* ```javascript
* stringEqualsIgnoreCase('hi', 'Hi')
* // => true
*
* stringEqualsIgnoreCase('hi', 'no')
* // => false
* ```
*/
export function stringEqualsIgnoreCase(data: string, expected: string): boolean {
return (
data.toLowerCase() === expected.toLowerCase()
);
}
15 changes: 15 additions & 0 deletions src/conditionOperators/string/stringNotEquals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stringNotEquals } from './stringNotEquals';

describe('stringNotEquals', () => {
it('returns true', () => {
expect(stringNotEquals('secrets', 'Secrets')).toBeTruthy;
expect(stringNotEquals('house', 'secrets')).toBeTruthy;
expect(stringNotEquals('', '1')).toBeTruthy;
});

it('returns false', () => {
expect(stringNotEquals('secrets', 'secrets')).toBeFalsy;
expect(stringNotEquals('house', 'house')).toBeFalsy;
expect(stringNotEquals('', '')).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/string/stringNotEquals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Negated string matching.
*
* @since 4.4.0
* @category String
* @param {string} data The value to be compared.
* @param {string} expected The expected value.
* @returns {boolean} Returns `true` if `value` is not equal to `expected value`.
* @example
* ```javascript
* stringNotEquals('hi', 'no')
* // => true
*
* stringNotEquals('hi', 'hi')
* // => false
* ```
*/
export function stringNotEquals(data: string, expected: string): boolean {
return (
data !== expected
);
}
15 changes: 15 additions & 0 deletions src/conditionOperators/string/stringNotEqualsIgnoreCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stringNotEqualsIgnoreCase } from './stringNotEqualsIgnoreCase';

describe('stringNotEqualsIgnoreCase', () => {
it('returns true', () => {
expect(stringNotEqualsIgnoreCase('secrets', 'house')).toBeTruthy;
expect(stringNotEqualsIgnoreCase('house', 'secrets')).toBeTruthy;
expect(stringNotEqualsIgnoreCase('', '1')).toBeTruthy;
});

it('returns false', () => {
expect(stringNotEqualsIgnoreCase('secrets', 'Secrets')).toBeFalsy;
expect(stringNotEqualsIgnoreCase('newHouse', 'NewHouse')).toBeFalsy;
expect(stringNotEqualsIgnoreCase('', '')).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/string/stringNotEqualsIgnoreCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Negated string matching, ignoring case.
*
* @since 4.4.0
* @category String
* @param {string} data The value to be compared.
* @param {string} expected The expected value.
* @returns {boolean} Returns `true` if `value` is not equal to `expected value`.
* @example
* ```javascript
* stringNotEqualsIgnoreCase('hi', 'no')
* // => true
*
* stringNotEqualsIgnoreCase('hi', 'Hi')
* // => false
* ```
*/
export function stringNotEqualsIgnoreCase(data: string, expected: string): boolean {
return (
data.toLowerCase() !== expected.toLowerCase()
);
}

0 comments on commit 83665fa

Please sign in to comment.