/
strContainsAll.ts
31 lines (29 loc) · 976 Bytes
/
strContainsAll.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import strContains from './strContains.js';
/**
* Determine if a given string contains all array values.
*
* Performs a case-sensitive check indicating if all of the
* needles are contained in haystack.
*
* @param {string} haystack - The string to search in
* @param {string[]} needles - The substrings to search for in the haystack
* @returns {boolean}
*
* @example
* ```js
* strContainsAll('Victor', ['Vic']); // true
* strContainsAll('Victor', ['Vix']); // false
* strContainsAll('Victor', ['']); // false
* strContainsAll('Victor', ['Vic', 'tor']); // true
* strContainsAll('Victor', ['Vix', 'tor']); // false
* strContainsAll('Victor', ['Vix', 'torx']); // false
* ```
*/
export default function strContainsAll(haystack: string, needles: string[]): boolean {
for (let index = 0, length = needles.length; index < length; index++) {
if (!strContains(haystack, needles[index])) {
return false;
}
}
return true;
}