
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mithril-validator
Advanced tools
Easily validate Mithril.js models, and objects.
npm install mithril-validatorvar m = require('mithril')
require('mithril-validator')(m)
Validates mithril models and objects through validation functions mapped to specific model properties.
// Our mithril model
var Todo = function (data) {
this.name = m.prop(data.name || '')
this.done = m.prop(data.done)
}
// Initialize a new validator
var validator = new m.validator({
// Check model name property
name: function (name) {
if (!name) {
return "Name is required."
}
}
})
// Results in "Name is required."
validator.validate(new Todo()).hasError('name')
Returns length of error mapping
if (validator.hasErrors()) {
// do something
}
Returns the element associated with the specified key from the error mapping
m('input', {
// Set class to error when an error for this field has occurred
// Trigger validator on submission or when a field changes
class: ctrl.validator.hasError('name') ? 'error' : '',
onchange: m.withAttr('value', ctrl.model.name),
value: ctrl.model.name()
})
Removes all of the elements from the error list.
// Results in "Name is required."
validator.hasError('name')
validator.clearErrors()
// Results in undefined
validator.hasError('name')
Validates the specified model against the validations mapping in this instance.
Each (shallow) property is iterated over and cross-checked against the given model for value, then the validation function is invoked passing the model as context and value as the first argument.
On a truthy result from a validation function the result is placed on the error object with the property name as the identifier.
validator.validate(new Todo())
Note Missing properties are treated as undefined and do not throw errors, you should do this yourself
within the property validator.
Licensed under The MIT License.
FAQs
Easily validate Mithril.js forms, models, and objects.
We found that mithril-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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.