validated-changeset
Version:
Changesets for your local state
33 lines • 898 B
JavaScript
import { getChangeValue, isChange } from '../-private/change';
export function hasKey(record, path, safeGet) {
const keys = path.split('.');
let obj = record;
for (const key of keys) {
if (!obj || !Object.prototype.hasOwnProperty.call(obj, key)) {
return false;
}
obj = safeGet(obj, key);
if (isChange(obj)) {
obj = getChangeValue(obj);
}
}
return true;
}
export function pathInChanges(record, path, safeGet) {
if (isChange(record)) {
return false;
}
const keys = path.split('.');
let obj = record;
for (const key of keys) {
if (!obj) {
return false;
}
if (keys[keys.length - 1] !== key && isChange(safeGet(obj, key))) {
return true;
}
obj = safeGet(obj, key);
}
return false;
}
//# sourceMappingURL=has-key.js.map