|
|
|
|
|
by vorticalbox
18 days ago
|
|
> There's a much cleaner way to do this - a shared helper disagree, then you end up with something this this function checkAll(target, conditions) {
return Object.entries(conditions).every(([path, expected]) => {
const value = path.split('.').reduce((o, k) => o?.[k], target);
return typeof expected === 'function' ? expected(value, target) : value === expected;
});
} and const ok = checkAll({ user, account }, {
'user.isActive': true,
'user.isSuspended': false,
'account.status': 'open',
'user': u => u.hasPermission('read'), // predicate for the trickier bit
}); how is that better? |
|