3ce001a4f6
lodash's curry is great and does a lot, but we don't need it all. This is quite a bit faster. Currently, it does away with placeholder support. updeep curry partial call x 9,951,410 ops/sec ±1.61% (62 runs sampled) lodash curry partial call x 988,949 ops/sec ±1.36% (62 runs sampled)
22 lines
418 B
JavaScript
22 lines
418 B
JavaScript
import splitPath from './util/splitPath';
|
|
import curry from './util/curry';
|
|
|
|
function is(path, predicate, object) {
|
|
const parts = splitPath(path);
|
|
|
|
let rest = object;
|
|
let part;
|
|
for (part of parts) {
|
|
if (typeof rest === 'undefined') return false;
|
|
rest = rest[part];
|
|
}
|
|
|
|
if (typeof predicate === 'function') {
|
|
return predicate(rest);
|
|
}
|
|
|
|
return predicate === rest;
|
|
}
|
|
|
|
export default curry(is);
|