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

validate-value validates values against JSON schemas.

  • 7.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63
decreased by-46.61%
Maintainers
3
Weekly downloads
 
Created
Source

validate-value

validate-value validates values against JSON schemas.

Status

CategoryStatus
Versionnpm
DependenciesDavid
Dev dependenciesDavid
BuildGitHub Actions
LicenseGitHub

Installation

$ npm install validate-value

Quick start

First you need to integrate validate-value into your application:

const { Value } = require('validate-value');

If you use TypeScript, use the following code instead:

import { Value } from 'validate-value';

Then, create a new instance and provide a JSON schema that you would like to use for validation:

const value = new Value({
  type: 'object',
  properties: {
    username: { type: 'string' },
    password: { type: 'string' }
  },
  additionalProperties: false,
  required: [ 'username', 'password' ]
});

Afterwards, you may use the validate function to validate a value:

const user = {
  username: 'Jane Doe',
  password: 'secret'
};

try {
  value.validate(user);
} catch (ex) {
  // ...
}

By default, the error message uses value as identifier and . as the separator for the object that is validated, but sometimes you may want to change this. Therefor, provide the desired identifier and separator as second parameter to the validate function:

const user = {
  username: 'Jane Doe',
  password: 'secret'
};

try {
  value.validate(user, { valueName: 'person', separator: '/' });
} catch (ex) {
  // ...
}

From time to time, you may not be interested in the actual error, but only in the fact whether the given object is valid or not. For these cases, use the isValid function:

const user = {
  username: 'Jane Doe',
  password: 'secret'
};

console.log(value.isValid(user));
// => true

Running the build

To build this module use roboter.

$ npx roboter

Keywords

FAQs

Package last updated on 13 Sep 2020

Did you know?

Socket

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.

Install

Related posts

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