@springworks/input-validator
Advanced tools
Comparing version 3.0.4 to 3.0.5
{ | ||
"name": "@springworks/input-validator", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Module to help validate and filter input parameters.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,3 @@ # Node.js Input Validator module | ||
```js | ||
var input_validator = require('input-validator'); | ||
var input_validator = require('@springworks/input-validator'); | ||
@@ -35,53 +35,2 @@ // Filter object to only include `foo` and `bar` | ||
### `isMissingParams(params, required)` | ||
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); | ||
``` | ||
### `missingParams(params, required)` | ||
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); | ||
``` | ||
### `isTypesValid(params, types)` | ||
Checks that the parameters have the correct datatype. Returns true if all params are of valid types. | ||
```js | ||
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. | ||
```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); | ||
``` | ||
### `getType(obj)` | ||
Returns a string with the name of the datatype of `obj`. | ||
```js | ||
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`. | ||
```js | ||
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)` | ||
@@ -112,6 +61,31 @@ Validates `obj` against a `Joi.schema`. It will filter unknown | ||
### ~~`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); | ||
``` | ||
### ~~`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); | ||
``` | ||
### ~~`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); | ||
``` | ||
## Tests | ||
Run `npm test` to run complete unit tests with *Istanbul* code coverage. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17233
89