Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@springworks/input-validator
Advanced tools
Simple Node.js module to validate and filter input parameters.
npm install --save @springworks/input-validator
Include module and use validation functions:
var input_validator = require('@springworks/input-validator');
// Filter object to only include `foo` and `bar`
var filtered = input_validator.filterParams({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
filterParams(params, allowed)
Ensures a params
object only has the allowed
parameters:
// Remove all params but for `foo` or `bar`
var filtered = input_validator.filterParams({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
assert(filtered.length === 2);
validateSchema(obj, schema, resource_name, options)
Validates obj
against a Joi.schema
. It will filter unknown
keys. It will throw an error if validation fails.
var schema = Joi.object().keys({
'username': Joi.string().required(),
'password': Joi.string().required()
}),
validated;
validated = Joi.validate({
'username': 'foo',
'password': 'bar'
}, schema);
/*
Validated is now equal to:
{
'username': 'foo',
'password': 'bar'
}
*/
isMissingParams(params, required)
Checks if any of the required params are missing.
// Ensure both `foo` and `bar` are included in params object
var is_missing_params = input_validator.isMissingParams({ foo: 1 }, ['foo', 'bar']);
assert(is_missing_params === true);
missingParams(params, required)
Checks if any of the required params are missing. Returns any missing params in an array.
// Ensure both `foo` and `bar` are included in params object, and return missing params in an array
var missing_params = input_validator.missingParams({ foo: 1 }, ['foo', 'bar']);
assert(missing_params.length === 1);
invalidTypeParams(params, types)
Checks that the parameters have the correct datatype. Returns parameters that don't have the correct datatype in an array. Returns an empty array if all parameters are of the correct datatype.
// Ensure that `foo` is a String and `bar` is a Boolean.
var invalid_params = input_validator.invalidTypeParams({foo: 'baz', bar: 'foz'}, {foo: String, bar: Boolean});
assert(invalid_params.length === 1);
Run npm test
to run complete unit tests with Istanbul code coverage.
FAQs
Simple module to validate input parameters.
We found that @springworks/input-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.