const obj = {
a: 1,
b: 'hello',
c: { d: 2 }
}
assertObject(obj, {
a: (val) => [val === 1, 'a should be 1'],
b: (val) => [val === 'hello', 'b should be hello'],
c: [
(val) => [!!val, 'c should not be empty'],
(val) => [isObject(val), 'c should be an object']
],
'c.d': (val) => [isOptional(val, v === 2), 'c.d should be 2']
});
Asserts the values in an object based on the provided assertions. The assertions are a map of paths to functions that return a tuple of a boolean and a message. This is intended to be used for testing and validation when there is no schema validator available.