Joistick
Default values for joi
schemas.
Install
$ npm install joistick
Usage
Purpose
Joi's default value
API
(any.default([value, [description]])
) supports being passed a function that,
when called, returns the default value.
If you want the default value to be an Object
, Array
or other complex data
type, you need a function that returns a new instance. If you just pass a value
literal it would be shared between calls, usually we don't want that.
Joistick helps reduce boilerplate in your shemas.
Importing
Access features as properties of the whole module:
const Joi = ;const Joistick = ; const arrayFactory = Joistick;const dateFactory = Joistick;const objectFactory = Joistick;
Or import a feature directly:
const Joi = ;const NewArray = ;const NewDate = ;const NewObject = ; const arrayFactory = ;const dateFactory = ;const objectFactory = ;
API
NewArray([default])
Returns a function
that returns a new Array
where:
value
- An optional array of cloneable values to seed a new array with.
const Joi = ;const NewArray = ; // An empty Arrayconst schema = job: Joi actions: Joi; // An Array with default itemsconst schema2 = job: Joi actions: Joi;
NewDate([default])
Returns a function
that returns a new Date
where:
default
- An optional value that is passed to theDate
constructor.
const Joi = ;const NewDate = ; // A fresh Date (now)const schema = name: Joi created: Joi; // A specificed Dateconst schema2 = name: Joi created: Joi;
NewObject([default])
Returns a function
that returns a new Object
where:
value
- An optionalObject
of cloneable values to seed a new object with. UsesObject.assign
to create a new object whenseed
is defined.
const Joi = ;const NewObject = ; // An empty objectconst schema = uri: Joi headers: Joiobject; // An object with default fieldsconst schema = uri: Joi headers: Joiobject;
Have a question?
Any issues or questions (no matter how basic), open an issue. Please take the initiative to read relevant documentation and be pro-active with debugging.
Want to contribute?
Contributions are welcome. If you're changing something non-trivial, you may want to submit an issue before creating a large pull request.
License
MIT