Type Checking, Formatting, Annotations, & more
const oh = require("overhaul");
let format = oh.object({
id: oh.required.toString.description("User Id"),
state: oh.default("WA").values(["CA", "OR", "WA"]),
age: oh.integer.within(10, 20).deprecated,
filter: oh.object({
start: oh.default(0).toNumber,
end: oh.default(() => 5000).number
})
});
let req = format.value({
id: 123,
age: 15,
filter: {start: "100"}
});
// req === { id: '123', age: 15, state: 'WA', filter: { start: 100, end: 5000 } }
//Shortcut
oh.object({
id: oh.string,
filter: oh.object({
start: oh.number,
end: oh.number
})
})
// Is equivalent to:
oh.object({
id: oh.string,
filter: {
start: oh.number,
end: oh.number
}
})
// oh.object is implied if inner key value is a plain object
npm install --save overhaul
overhaul is licensed under the MIT license.