This commit is contained in:
毛财君
2023-07-06 17:37:33 +08:00
parent 06f26608af
commit 197b38ca6f
816 changed files with 236883 additions and 989 deletions

View File

@@ -0,0 +1,31 @@
var hasOwnProp = require('./hasOwnProp')
var isArray = require('./isArray')
function helperCreateIterateHandle (prop, useArray, restIndex, matchValue, defaultValue) {
return function (obj, iterate, context) {
if (obj && iterate) {
if (prop && obj[prop]) {
return obj[prop](iterate, context)
} else {
if (useArray && isArray(obj)) {
for (var index = 0, len = obj.length; index < len; index++) {
if (!!iterate.call(context, obj[index], index, obj) === matchValue) {
return [true, false, index, obj[index]][restIndex]
}
}
} else {
for (var key in obj) {
if (hasOwnProp(obj, key)) {
if (!!iterate.call(context, obj[key], key, obj) === matchValue) {
return [true, false, key, obj[key]][restIndex]
}
}
}
}
}
}
return defaultValue
}
}
module.exports = helperCreateIterateHandle