As a convenience, @joystick.js/node
offers the schema validation function used behind the scenes for validating getter/setter input as a named export validate_input
to be used in non-Joystick code within your app.
Example Usage
import { validate_input } from '@joystick.js/node';
const errors = validate_input({
name: {
first: 'Ryan',
last: 'Glover',
},
}, {
name: {
type: 'object',
required: true,
fields: {
first: {
type: 'string',
required: true,
},
last: {
type: 'string',
required: true,
}
},
},
});
Above, the first argument to validate_input
is the input value to validate, and the second argument is the schema to validate it against.
In response, if there are any errors with the input value, each error will be returned as a string describing the path and the error that occurred.
API
Definition
validate_input(input: object, schema: object) => array[string];
Parameters
- input object required
- The input object to validate.
- schema object required
- The schema object to validate the input against.