-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1018 Bytes
/
index.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*!
* any <https://github.com/jonschlinkert/any>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var iterator = require('make-iterator');
var forOwn = require('for-own');
module.exports = function any(value, fn, thisArg) {
if (value == null) {
return false;
}
// strings
if(typeof value === 'string' && typeof fn === 'string') {
return value.indexOf(fn) !== -1;
}
// object key
if (typeof fn === 'string') {
if (value.hasOwnProperty(fn)) {
return true;
}
}
fn = iterator(fn, thisArg);
var res = false;
// arrays or arguments
if(typeof value.length === 'number') {
var len = value.length;
var i = -1;
while (++i < len) {
if (fn(value[i], i, value)) {
res = true;
break;
}
}
// object properties/values
} else {
forOwn(value, function (val, key) {
if (fn(val, key, value)) {
res = true;
return false;
}
});
}
return res;
};