validate-value
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -0,1 +1,8 @@ | ||
# [8.1.0](https://github.com/thenativeweb/validate-value/compare/8.0.0...8.1.0) (2020-10-31) | ||
### Features | ||
* Add the isOfType function. ([#194](https://github.com/thenativeweb/validate-value/issues/194)) ([368a97c](https://github.com/thenativeweb/validate-value/commit/368a97cdb559828125fcc3d8d77738c815158356)) | ||
# [8.0.0](https://github.com/thenativeweb/validate-value/compare/7.3.1...8.0.0) (2020-10-29) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "validate-value", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "validate-value validates values against JSON schemas.", | ||
@@ -19,4 +19,4 @@ "contributors": [ | ||
], | ||
"main": "build/lib/Value.js", | ||
"types": "build/lib/Value.d.ts", | ||
"main": "build/lib/index.js", | ||
"types": "build/lib/index.d.ts", | ||
"dependencies": { | ||
@@ -28,4 +28,4 @@ "ajv": "6.12.6", | ||
"assertthat": "5.2.1", | ||
"roboter": "11.4.5", | ||
"semantic-release-configuration": "1.0.23" | ||
"roboter": "11.4.8", | ||
"semantic-release-configuration": "1.0.24" | ||
}, | ||
@@ -32,0 +32,0 @@ "repository": { |
@@ -26,3 +26,3 @@ # validate-value | ||
```javascript | ||
const { Value } = require('validate-value'); | ||
const { Value, isOfType } = require('validate-value'); | ||
``` | ||
@@ -33,3 +33,3 @@ | ||
```typescript | ||
import { Value } from 'validate-value'; | ||
import { Value, isOfType } from 'validate-value'; | ||
``` | ||
@@ -93,2 +93,55 @@ | ||
### Verifying that a variable is of a specific type | ||
To verify that a variable is of a specific type, use the `isOfType` function. Hand over a value you would like to verify, and a JSON schema describing that type. The function returns `true` if the given variable matches the schema, and `false` if it doesn't: | ||
```javascript | ||
const user = { | ||
username: 'Jane Doe', | ||
password: 'secret' | ||
}; | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
username: { type: 'string' }, | ||
password: { type: 'string' } | ||
}, | ||
additionalProperties: false, | ||
required: [ 'username', 'password' ] | ||
}; | ||
if (isOfType(user, schema)) { | ||
// ... | ||
} | ||
``` | ||
When using TypeScript, you may even specify a generic type parameter, and use the function as a type guard: | ||
```typescript | ||
interface User { | ||
username: string; | ||
password: string; | ||
} | ||
const user = { | ||
username: 'Jane Doe', | ||
password: 'secret' | ||
}; | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
username: { type: 'string' }, | ||
password: { type: 'string' } | ||
}, | ||
additionalProperties: false, | ||
required: [ 'username', 'password' ] | ||
}; | ||
if (isOfType<User>(user, schema)) { | ||
// ... | ||
} | ||
``` | ||
## Running the build | ||
@@ -95,0 +148,0 @@ |
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
15055
19
197
151