Skip to content

A data validator is a library that can be used to check the correctness of any data.

Notifications You must be signed in to change notification settings

gpiento/data-validator-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Validator

hexlet-check GitHub Workflow Status Maintainability Test Coverage

A data validator is a library that can be used to check the correctness of any data. There are many such libraries in every language, because almost all programs work with external data that need to be checked for correctness. First of all, we are talking about form data filled in by users. The yup library is taken as a basis for the project.

Valid data types:

  • String
  • Integer
  • Map

Example of using strings:

import hexlet.code.Validator;
import hexlet.code.schemas.StringSchema;

var v = new Validator();

var schema = v.string();

schema.isValid(""); // true
schema.isValid(null); // true

schema.required();

schema.isValid(null); // false
schema.isValid(""); // false
schema.isValid("what does the fox say"); // true
schema.isValid("hexlet"); // true

schema.contains("wh").isValid("what does the fox say"); // true
schema.contains("what").isValid("what does the fox say"); // true
schema.contains("whatthe").isValid("what does the fox say"); // false

schema.isValid("what does the fox say"); // false

var schema1 = v.string();
schema1.minLength(10).minLength(4).isValid("Hexlet"); // true

Example of using integers:

import hexlet.code.Validator;
import hexlet.code.schemas.NumberSchema;

var v = new Validator();

var schema = v.number();

schema.isValid(5); // true

schema.isValid(null); // true
schema.positive().isValid(null); // true

schema.required();

schema.isValid(null); // false
schema.isValid(10); // true

schema.isValid(-10); // false
schema.isValid(0); // false

schema.range(5, 10);

schema.isValid(5); // true
schema.isValid(10); // true
schema.isValid(4); // false
schema.isValid(11); // false

Example of using maps:

import hexlet.code.Validator;
import hexlet.code.schemas.MapSchema;

var v = new Validator();

var schema = v.map();

schema.isValid(null); // true

schema.required();

schema.isValid(null); // false
schema.isValid(new HashMap<>()); // true
var data = new HashMap<String, String>();
data.put("key1", "value1");
schema.isValid(data); // true

schema.sizeof(2);

schema.isValid(data);  // false
data.put("key2", "value2");
schema.isValid(data); // true

About

A data validator is a library that can be used to check the correctness of any data.

Resources

Stars

Watchers

Forks

Packages

No packages published