GithubHelp home page GithubHelp logo

homework4's Introduction

Task 7, validateObject

Example

const { validateObject } = require('./tasks/task7');

// Define the schema
const schema = {
  name: { type: 'string', descriptors: { enumerable: true } },
  age: { type: 'number', min: 0, max: 120 },
  isAdmin: { type: 'boolean', value: false }
};

// Object to validate
const user = {
  name: 'John Doe',
  age: 30,
  isAdmin: false
};

// Validate the object against the schema
const isValid = validateObject(user, schema);

console.log(isValid); // Output: true

What could be validated:

  • object property type:

    • string
    • number
    • object
    • bigint
    • function
    • array
    • boolean
    {
      name: {
          type: 'string'
      }
    }
  • descriptors:

    • enumarable
    • writable
    • configurable
    {
      name: {
          descriptors: {
              enumerable: true,
              writable: true,
              configurable: false
          }
      }
    }
  • strings:

    • max length
    • min length
    • length
    • value
    { name: {
        type: 'string',
        min: 2,
        max: 100,
        length: 10,
        value: 'Robert'
    }}
  • numbers:

    • max
    • min
    • value
    {
        age: {
            type: 'number',
            min: 1,
            max: 140,
            value: 22
        }
    }
  • BigInt:

    • max
    • min
    • value
    {
        bigNumber: {
            type: 'bigint',
            min: 100n,
            max: 1000000000000000000000n,
            value: 10000000000000000000000n
        }
    }
  • boolean:

    • value
    {
        isAlive: {
            type: 'boolean',
            value: true
        }
    }
  • array:

    • min length
    • max length
    • length
    {
        adress: 'array',
        min: 2,
        max: 5,
        length: 3
    }
  • object:

    • recursively calls validateObject using value as argument for schema
    {
        user: {
            type:'object',
            value: {
              name: {
                  type:'string',
                  min: 2
              },
              age: {
                  type: 'number',
                  value: 33
              }
            }
        }
    }
  • function

    • validate type only
    {
        getId: {
            type: 'function'
        }
    }

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.