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

validate-value

Package Overview
Dependencies
Maintainers
3
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-value - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

build/lib/index.d.ts

7

CHANGELOG.md

@@ -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 @@

10

package.json
{
"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 @@

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