-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (25 loc) · 818 Bytes
/
index.js
File metadata and controls
25 lines (25 loc) · 818 Bytes
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
module.exports = function includes(where, strings) {
switch (typeof where) {
case 'boolean':
return where;
case 'function':
return strings.find(value => where(value));
case 'object':
if (Array.isArray(where)) {
return where.find(value => includes(value, strings));
} else if (where instanceof RegExp) {
return strings.find(value => where.test(value));
} else {
return strings.find(value => where[value]);
}
case 'string':
switch (where) {
case 'true':
return true;
case 'false':
return false;
}
return strings.includes(where);
}
return false;
};