updeep-remeda/lib/is.js

22 lines
445 B
JavaScript
Raw Normal View History

2017-04-19 00:55:46 +00:00
import splitPath from './util/splitPath'
import curry from './util/curry'
2015-08-07 03:48:04 +00:00
function is(path, predicate, object) {
2017-04-19 00:55:46 +00:00
const parts = splitPath(path)
2015-08-07 03:48:04 +00:00
2017-04-19 00:55:46 +00:00
let rest = object
2017-04-19 00:47:53 +00:00
for (let i = 0; i < parts.length; i += 1) {
2017-04-19 00:55:46 +00:00
if (typeof rest === 'undefined') return false
const part = parts[i]
rest = rest[part]
2015-08-07 03:48:04 +00:00
}
if (typeof predicate === 'function') {
2017-04-19 00:55:46 +00:00
return predicate(rest)
2015-08-07 03:48:04 +00:00
}
2017-04-19 00:55:46 +00:00
return predicate === rest
2015-08-07 03:48:04 +00:00
}
2017-04-19 00:55:46 +00:00
export default curry(is)