Giter Club home page Giter Club logo

java-project-3's Introduction

Hexlet tests and linter status:

Actions Status Java CI

Welcome

Project Data Validator.

Description:

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

  • Usage example:

    Validator validator = new Validator();

        // strings structure check
        
    StringSchema schema = validator.string().required();
    schema.isValid("what does the fox say"); // true
    schema.isValid(""); // false
        
        // numbers structure check
        
    NumberSchema schema = validator.number().required().positive();
    schema.isValid(-10); // false
    schema.isValid(10); // true
        
        // map structure check
        
    MapSchema schema = validator.map();
    Map<String, String> data = new HashMap<>();
    data.put("key", "value");
    schema.isValid(data); // true
        
    schema.sizeof(2);
    schema.isValid(data); // false
    data.put("key2", "value2");
    schema.isValid(data); // true
        
        // shape - allows you to describe validation for Map object values by keys.
        
    Map<String, BaseSchema> schemas = new HashMap<>();
    schemas.put("name", v.string().required());
    schemas.put("age", v.number().positive());
    schema.shape(schemas);

    Map<String, Object> human1 = new HashMap<>();
    human1.put("name", "Kolya");
    human1.put("age", 100);
    schema.isValid(human1); // true

    Map<String, Object> human2 = new HashMap<>();
    human2.put("name", "Maya");
    human2.put("age", null);
    schema.isValid(human2); // true

    Map<String, Object> human3 = new HashMap<>();
    human3.put("name", "");
    human3.put("age", null);
    schema.isValid(human3); // false

    Map<String, Object> human4 = new HashMap<>();
    human4.put("name", "Valya");
    human4.put("age", -5);
    schema.isValid(human4); // false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.