1 | var hasOwnProp = require('./hasOwnProp')
|
2 | var isArray = require('./isArray')
|
3 |
|
4 | function helperCreateIterateHandle (prop, useArray, restIndex, matchValue, defaultValue) {
|
5 | return function (obj, iterate, context) {
|
6 | if (obj && iterate) {
|
7 | if (prop && obj[prop]) {
|
8 | return obj[prop](iterate, context)
|
9 | } else {
|
10 | if (useArray && isArray(obj)) {
|
11 | for (var index = 0, len = obj.length; index < len; index++) {
|
12 | if (!!iterate.call(context, obj[index], index, obj) === matchValue) {
|
13 | return [true, false, index, obj[index]][restIndex]
|
14 | }
|
15 | }
|
16 | } else {
|
17 | for (var key in obj) {
|
18 | if (hasOwnProp(obj, key)) {
|
19 | if (!!iterate.call(context, obj[key], key, obj) === matchValue) {
|
20 | return [true, false, key, obj[key]][restIndex]
|
21 | }
|
22 | }
|
23 | }
|
24 | }
|
25 | }
|
26 | }
|
27 | return defaultValue
|
28 | }
|
29 | }
|
30 |
|
31 | module.exports = helperCreateIterateHandle
|