Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@springworks/input-validator

Package Overview
Dependencies
Maintainers
1
Versions
449
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@springworks/input-validator - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

2

package.json
{
"name": "@springworks/input-validator",
"version": "4.0.0",
"version": "4.0.1",
"description": "Module to help validate input parameters.",

@@ -5,0 +5,0 @@ "main": "index.js",

# Node.js Input Validator module
Simple Node.js module to validate and filter input parameters.
Simple Node.js module to validate input parameters.

@@ -8,4 +8,2 @@ [![Build Status](https://travis-ci.org/Springworks/node-input-validator.png?branch=master)](https://travis-ci.org/Springworks/node-validator)

## Usage
```

@@ -15,76 +13,20 @@ npm install --save @springworks/input-validator

Include module and use validation functions:
```js
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']);
```
## API
### `filterParams(params, allowed)`
Ensures a `params` object only has the `allowed` parameters:
```js
// 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.
```js
var schema = Joi.object().keys({
'username': Joi.string().required(),
'password': Joi.string().required()
}),
validated;
validated = Joi.validate({
'username': 'foo',
'password': 'bar'
}, schema);
Validates `obj` against a `joi` schema. It will throw an error if validation fails.
/*
Validated is now equal to:
{
'username': 'foo',
'password': 'bar'
}
*/
```
### ~~`isMissingParams(params, required)`~~(deprecated)
Checks if any of the required params are missing.
```js
// 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);
```
import { joi, validateSchema } from '@springworks/input-validator';
### ~~`missingParams(params, required)`~~(deprecated)
Checks if any of the required params are missing. Returns any missing params in an array.
```js
// 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);
```
const schema = joi.object().keys({
username: joi.string().required(),
password: joi.string().required()
});
### ~~`invalidTypeParams(params, types)`~~(deprecated)
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.
```js
// 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);
const validated = validateSchema({
'username': 'foo',
'password': 'bar'
}, schema);
```
## Tests
Run `npm test` to run complete unit tests with *Istanbul* code coverage.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc