updeep-remeda/lib/is.js

22 lines
452 B
JavaScript
Raw Normal View History

2015-08-07 03:48:04 +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) {
const parts = splitPath(path);
let rest = object;
2016-01-13 15:58:55 +00:00
for (let i = 0; i < parts.length; ++i) {
2015-08-07 03:48:04 +00:00
if (typeof rest === 'undefined') return false;
2016-01-13 15:58:55 +00:00
const part = parts[i];
2015-08-07 03:48:04 +00:00
rest = rest[part];
}
if (typeof predicate === 'function') {
return predicate(rest);
}
return predicate === rest;
}
export default curry(is);