
Security News
Inside Lodash’s Security Reset and Maintenance Reboot
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.
@times/schema-validator
Advanced tools
Basic schema validator for JS objects and arrays
Objects:
const { objectValidator } = require('@times/schema-validator');
const objectSchema = {
name: {
type: 'string',
required: true,
predicates: [
{
test: s => s.length <= 20,
onError: s => `${s} was longer than 20`
}
]
},
age: {
type: 'number',
required: false
}
};
const isValid = objectValidator(objectSchema);
const alice = {
name: 'Alice Smith',
age: 23
};
const bob = {
age: 'thirty'
};
isValid(alice); // { valid: true, errors: [] }
isValid(bob); // { valid: false, errors: [ ... ] }
Arrays:
const { arrayValidator } = require('@times/schema-validator');
const arraySchema = {
type: 'number',
predicates: [
{
test: n => n >= 10,
onError: n => `${n} was less than 10`
}
]
};
const isValid = arrayValidator(arraySchema);
const numbers1 = [ 1, 2, 3 ];
const numbers2 = [ 9, 10, 11 ];
const numbers3 = [ 'one', 'two' ];
isValid(numbers1); // { valid: true, errors: [] }
isValid(numbers2); // { valid: false, errors: [ ... ] }
isValid(numbers3); // { valid: false, errors: [ ... ] }
An object schema consists of field names that map to sets of properties. Each set of properties can include:
type (required): the type of the field. Can be string, number, date, array, objectrequired (optional): whether the field is required. Can be true or false, or omittedpredicates (optional): an array of predicates that should be applied to the contents of the fieldschemaValidator (optional): if the field is an array or object, you can provide a validator that should be applied to the contents of the fieldAn array schema can have the following properties:
type (required): the type of the items in the arraypredicates (optional): an array of predicates that should be applied to every item in the arrayschemaValidator (optional): if the array items are arrays or objects, you can provide a validator that should be applied to each array itemPredicates are boolean functions that can be applied to array items. They receive the array item as an argument.
You must also specify an error message, which will be used when the predicate returns false. The error message is specified through an onError function that also receives the array item as an argument.
For example:
{
test: s => s.includes('xyz'),
onError: s => `The string "${s}" did not include "xyz"`
}
Pull requests are very welcome. Please include a clear description of any changes, and full test coverage.
During development you can run tests with
npm test
Elliot Davies (elliot.davies@the-times.co.uk)
FAQs
Basic schema validator for JS objects and arrays
The npm package @times/schema-validator receives a total of 10 weekly downloads. As such, @times/schema-validator popularity was classified as not popular.
We found that @times/schema-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.

Security News
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.

Security News
The U.S. government is rolling back software supply chain mandates, shifting from mandatory SBOMs and attestations to a risk-based approach.