object
object([config])
Effect
Get a schema object of type object.
Arguments
[config]
(Object) - The config that respects the structure ofobject
.[config.prop]
(schema) - An enumerable key and the corresponding value should be a schema object declared byracoon-js
. If the value is not a schema object, it will be ignored.
Example
const schema1 = racoon.object();
schema1.validate(1); // fail
schema1.validate([1, 2]); // fail
schema1.validate({}); // pass
schema1.validate({ prop: 1 }); // pass
const schema2 = racoon.object({
name: racoon.string(),
age: racoon.number()
});
schema2.validate({ name: 123, age: 20 }); // fail
schema2.validate({ name: 'abc', age: 20 }); // pass
Last updated
Was this helpful?