
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
simple-validate
Advanced tools
Simple argument validator.
$ npm install simple-validate
Run the specs
$ jasmine-node spec/
var validate = require('simple-validate');
var pattern = {
title : validate.required(isString)
description : validate.isAll(isString, hasLengthGreaterThan(5)),
isActive : isBoolean,
tags : isArray
};
validate(pattern, {
title : 'Hi There',
description : 'This is a great post.',
isActive : true
// tags are undefined - but that is ok, validator treats them as optional
});
// => true
The validator runs each argument against the defined validation pattern, asserting a true outcome for each. Properties defined in the validation pattern are assumed to be optional unless declared otherwise.
Note, this module is best used with a functional library to provide predicates (isString
, isNull
, etc.), such as lodash
or ramda
.
A more advanced example can also be found in the examples directory.
Object -> Object -> Boolean
Validates arguments against the provided pattern.
validate(<pattern>, <args>) -> Boolean
Note: all logical utilities must be called incrementally (fn(v1)(v2)
) as shown in the examples below.
Predicate -> Predicate
Returns a predicate that is satisfied if the supplied predicate is satisfied and the provided value is not undefined. This should be used to denote that a property is required, since otherwise properties as assumed to be optional.
validate.required(p) -> Function
validate.required(p)(<value>) -> Boolean
Predicate -> Predicate
Returns a predicate that is satisfied if the supplied predicate is satisfied or the provided value is undefined. Note: using this utility is probably not necessary to use often, since validate
assumes all properties are optional by default. This is the shorthand equivalent to isAny(isUndefined, p)
.
validate.optional(p) -> Function
validate.optional(p)(<value>) -> Boolean
Predicates -> Predicate
Returns a predicate that is satisfied if all supplied predicates are satisfied for the provided value.
validate.isAll(p1, p2, ...) -> Function
validate.isAll(p1, p2, ...)(<value>) -> Boolean
Predicates -> Predicate
Returns a predicate that is satisfied if any of the supplied predicates are satisfied for the provided value.
validate.isAny(p1, p2, ...) -> Function
validate.isAny(p1, p2, ...)(<value>) -> Boolean
Predicate -> Predicate
Returns a predicate that inverts the supplied predicate.
validate.isNot(p) -> Function
validate.isNot(p)(<value>) -> Boolean
validate.withErrors(<pattern>, <values>)
. Consider adding getErrors
, etc. Will probably include helper method to map pattern values for general usage.git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Simple object validator.
We found that simple-validate 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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.