
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
bedrock-validation
Advanced tools
A bedrock module that provides a express middleware and an API for validating data structures and their contents. bedrock-validation uses schemas based on JSON schema.
npm install bedrock-validation
var bedrock = require('bedrock');
var {validate} = require('bedrock-validation');
// load schemas from '/foo'
bedrock.config.validation.schema.paths.push('/foo');
// add an express route with validation middleware
bedrock.events.on('bedrock-express.configure.routes', function(app) {
app.post('/bar',
// validate the query using the 'postBarQueryValidator'
// validate the response body using the 'postBarValidator'
validate({query: 'postBarQueryValidator', body: 'postBarValidator'}),
function(req, res) {
// do something
});
});
bedrock.start();
bedrock-validation will, on initialization (via the bedrock.init
event),
read any schemas found in the list of paths specified in
bedrock.config.validation.schema.paths
. Individual schemas can be skipped
via the bedrock.config.validation.schema.skip
configuration option. If any
schema name matches a previously loaded schema, it will override that
schema.
For more documentation on configuration, see config.js.
This method may be called with either one, two, or three parameters.
If only one parameter is given:
body
and query
schema names as properties of the object.If two parameters are given:
If three parameters are given:
Retrieves a validation schema given a name
for the schema. If no such
schema exists, null
is returned.
Validates an instance
(data) against a schema
. This method may be used
to validate data using a schema that wasn't necessarily registered via
the configuration system. The schema
must be a JSON schema instance. The
return value will contain the result of the validation. If a callback
is
given, it will be called once the validation operation completes. If an
error occurred it will be passed in the second parameter of the callback
.
The synchronous and callback return value are the same:
{
valid: <boolean>,
error: <error> // only present when valid === false
}
4.5.0 - 2020-11-19
FAQs
Bedrock validation
The npm package bedrock-validation receives a total of 33 weekly downloads. As such, bedrock-validation popularity was classified as not popular.
We found that bedrock-validation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.