![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
object-template-validator
Advanced tools
Allows validation of an object against a template.
Example:
function validate(notification, callback){
var ov = require('object-template-validator');
var _ = require('lodash');
var obj = ov.obj, arr = ov.arr, opt = ov.opt, choice = ov.choice, and = ov.and, nullable = ov.nullable;
var notificationTemplate = {
id: opt(_.isString),
operator: _.isString,
country: _.isString,
environment: _.isString,
active: _.isBoolean,
type: and(_.isString, choice(['call2action', 'notification'])),
start: ov.isISODate,
end: nullable(ov.isISODate),
app: nullable(obj({
identifier: _.isString,
params: _.isObject
})),
matches: arr(obj({
"and": arr(obj({
type: _.isString,
values: opt(arr(function(value) {return /^\/.+\/[a-z]*$/.test(value)})),
rawValues: arr(_.isString)
}))
})
),
notification: obj(
{
message: _.isString,
retry: nullable(_.isNumber),
repeat: nullable(_.isNumber),
image: nullable(_.isString)
}
),
referenceId: opt(nullable(_.isString))
};
if (!ov.validateObject(notificationTemplate, notification)) {
return callback(new ResponseError('error.stbNotification.invalid', 'objectStructureMismatch: ' + ov.getInvalidDescription()));
}
callback();
};
In a template, you can use functions or wrappers. Wrappers, such as obj({..}) can be used to define a sub-object. The validateObject function should be used to validate the object against the template. objectValidator provides uses the congruence API internally, which emits errors when the object does not match the template. These emitted errors can be fetched after validation by the getMessages method. The getInvalidDescription provides a textual description of what was wrong.
Other interesting wrapper functions are:
opt(f)
: key is optional, or f(value) is truenullable(f)
: value may be null, or f(value) is trueobj({...})
: value must be an object according to the specified templaterecObj({...})
: same as obj, but if some keys of the template have a value that is an object or an array, the obj function is applied recursively to those keys. This allows the user to match a literal object in a template.exists
: key must exist but the value does not matterarr(f)
: value is an array in which each entry matches the specified validation function.and(f1, f2)
: f1(value) && f2(value)
or(f1, f2)
: f1(value) || f2(value)
choice(['...', '...'])
: value must be in arrayisISODate(v)
: validates an ISO Date-formatted string (2015-04-28T10:00.000Z)Other library functions/properties:
FAQs
Allows object validation against a template
The npm package object-template-validator receives a total of 0 weekly downloads. As such, object-template-validator popularity was classified as not popular.
We found that object-template-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.