-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(string): add case-sensitive-matching if exist (stringLikeIfExists)
- Loading branch information
1 parent
d5dfa3c
commit 695961d
Showing
8 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { stringLikeIfExists } from './stringLikeIfExists'; | ||
|
||
describe('stringLikeIfExists', () => { | ||
it('returns true', () => { | ||
expect(stringLikeIfExists('newHouse', 'new*')).toBeTruthy; | ||
expect(stringLikeIfExists('topSecret', '*Secret')).toBeTruthy; | ||
expect(stringLikeIfExists(undefined, 'hi')).toBeTruthy; | ||
}); | ||
|
||
it('returns false', () => { | ||
expect(stringLikeIfExists('NewHouse', 'new*')).toBeFalsy; | ||
expect(stringLikeIfExists('TopSecret', '*Secret')).toBeFalsy; | ||
expect(stringLikeIfExists('hi', 'no')).toBeFalsy; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {stringLike} from './stringLike'; | ||
|
||
/** | ||
* Case-sensitive matching if exist. The values can include a multi-character match wildcard (*) anywhere in the string. | ||
* | ||
* @since 4.12.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` or if it does not exist. | ||
* @example | ||
* ```javascript | ||
* stringLikeIfExists(undefined, 'new*') | ||
* // => true | ||
* | ||
* stringLikeIfExists('House', 'new*') | ||
* // => false | ||
* ``` | ||
*/ | ||
export function stringLikeIfExists(data: string | undefined, expected: string): boolean { | ||
return data?( | ||
stringLike(data,expected) | ||
):true; | ||
} |