Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@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('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);
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);
isTypesValid(params, types)
Checks that the parameters have the correct datatype. Returns true if all params are of valid types.
var has_valid_params = input_validator.isTypesValid({foo: 'baz', bar: 'foz'}, {foo: String, bar: Boolean});
assert(has_valid_params === false);
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);
getType(obj)
Returns a string with the name of the datatype of obj
.
assert(input_validator.getType('this is a string') === 'String');
assert(input_validator.getType(1337) === 'Number');
assert(input_validator.getType(true) === 'Boolean');
assert(input_validator.getType([]) === 'Array');
assert(input_validator.getType({}) === 'Object');
getType(obj)
Returns a string with the name of the datatype of obj
.
assert(input_validator.getType('this is a string') === 'String');
assert(input_validator.getType(1337) === 'Number');
assert(input_validator.getType(true) === 'Boolean');
assert(input_validator.getType([]) === 'Array');
assert(input_validator.getType({}) === 'Object');
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'
}
*/
Run npm test
to run complete unit tests with Istanbul code coverage.
FAQs
Simple module to validate input parameters.
The npm package @springworks/input-validator receives a total of 955 weekly downloads. As such, @springworks/input-validator popularity was classified as not popular.
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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.