Skip to content

Commit

Permalink
feat(stringlike): adding case sensitive matching with multi character…
Browse files Browse the repository at this point in the history
… match *
  • Loading branch information
roggervalf committed Feb 21, 2021
1 parent 43646f0 commit e5f2fc8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 6 deletions.
26 changes: 24 additions & 2 deletions dist/main.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.es.js.map

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/conditionOperators/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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>={
stringEquals,
stringEqualsIgnoreCase,
stringLike,
stringNotEquals,
stringNotEqualsIgnoreCase
};
15 changes: 15 additions & 0 deletions src/conditionOperators/string/stringLike.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stringLike } from './stringLike';

describe('stringLike', () => {
it('returns true', () => {
expect(stringLike('newHouse', 'new*')).toBeTruthy;
expect(stringLike('topSecret', '*Secret')).toBeTruthy;
expect(stringLike('hi', 'hi')).toBeTruthy;
});

it('returns false', () => {
expect(stringLike('NewHouse', 'new*')).toBeFalsy;
expect(stringLike('TopSecret', '*Secret')).toBeFalsy;
expect(stringLike('hi', 'no')).toBeFalsy;
});
});
24 changes: 24 additions & 0 deletions src/conditionOperators/string/stringLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Matcher} from '../../Matcher';

/**
* Case-sensitive matching. The values can include a multi-character match wildcard (*) anywhere in the string.
*
* @since 4.5.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 like `expected value`.
* @example
* ```javascript
* stringLike('newHouse', 'new*')
* // => true
*
* stringLike('House', 'new*')
* // => false
* ```
*/
export function stringLike(data: string, expected: string): boolean {
return (
new Matcher(data).match(expected)
);
}

0 comments on commit e5f2fc8

Please sign in to comment.