Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
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.
The npm package legitimize receives a total of 2 weekly downloads. As such, legitimize popularity was classified as not popular.
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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.