Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Legitimize is a simple and flexible object validator. It can be useful for validating JSON objects or to simply ensure an options parameter contains valid values.
npm install legitimize
It is relatively simple to use legitimize. Simply require the module, create a scheme and it's returned value will be the validation function. You may also pass a second parameter that is an object of default property rules.
var Legitimize = require("legitimize");
var defaults = {
type: "string"
};
var validate = new Legitimize({
name: {
required: true,
pattern: /[a-z]+/i
},
town: {
required: true
},
age: {
type: "integer",
error: "'age' must be an integer that is between 0 and 120",
use: function(value) { return (value >= 0 && value <= 120); }
},
color: {
within: ["red", "green", "blue"]
}
}, defaults);
This example object will return an error on many accounts but will return the first error it has encounted. 'town' should be a string, 'age' should be an integer that's between 0 and 120, and lastly color is a string (from the default rules object) but is not either 'red', 'green', or 'blue'.
var invalid = validate({
name: "Lewis Barnes",
town: 5,
age: "four hundred",
color: "myColour"
});
// returns 'town' must have a data type of string
console.log(invalid);
This object is a revised copy of the previous example with changes made to the town, age, and color properties. Since there are no errors, it returns null.
var invalid = validate({
name: "Lewis Barnes",
town: "Manchester",
age: 20,
color: "blue"
});
// returns null
console.log(invalid);
Copyright (c) 2014 Lewis Barnes. See LICENSE for details.
FAQs
A simple and flexible object validator.
We found that legitimize 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.