-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
import {firstLine, includesIgnoreCase} from './string'; | ||
|
||
describe('includesIgnoreCase', () => { | ||
it('finds exact match', () => { | ||
expect(includesIgnoreCase('find me', 'search and find me')).toBeTruthy(); | ||
expect(includesIgnoreCase('find it', 'search and find me again')).toBeFalsy(); | ||
expect(includesIgnoreCase('fist part', 'first part')).toBeFalsy(); | ||
}); | ||
|
||
it('finds no match', () => { | ||
expect(includesIgnoreCase('find it', 'search and find me again')).toBeFalsy(); | ||
}); | ||
|
||
it('finds match', () => { | ||
expect(includesIgnoreCase('find MÖ', 'search and find mö')).toBeTruthy(); | ||
expect(includesIgnoreCase('find mö', 'search and find MÖ')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('firstLine', () => { | ||
it('gets the first line of a multiline string', () => { | ||
expect(firstLine('foo\nbar')).toEqual('foo'); | ||
}); | ||
|
||
it('gets the first line of a one line string', () => { | ||
expect(firstLine('foo')).toEqual('foo'); | ||
}); | ||
|
||
it('returns an empty string for empty strings', () => { | ||
expect(firstLine('')).toEqual(''); | ||
}); | ||
}); |
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,14 @@ | ||
export function includesIgnoreCase( | ||
needle: string, | ||
haystack: string | Array<string>, | ||
): boolean { | ||
if (haystack instanceof Array) { | ||
return haystack.some((hay) => includesIgnoreCase(needle, hay)); | ||
} | ||
|
||
return haystack.toLowerCase().includes(needle.toLowerCase()); | ||
} | ||
|
||
export function firstLine(multilineText: string): string { | ||
return multilineText.split('\n', 1)[0]; | ||
} |