npm.io
1.3.0 • Published 3 years ago

simp-validator

Licence
ISC
Version
1.3.0
Deps
0
Size
29 kB
Vulns
0
Weekly
0
Stars
2

Simp Validator

GitHub release issues - simp-validator CircleCI codecov npm License

The Simp Validator is a lightweight JavaScript library for validating data against a schema. It's simple, flexible, and easily transferable over the network. It can be used in both browser and Node.js environments, making it versatile for various development scenarios. Its key feature is the ability to validate data on both the frontend and backend using a single schema, which can be easily migrated or serialized/deserialized without impacting the validation process.

Installation

You can install the Simp Validator using npm:

npm install simp-validator

Usage

To use the Simp Validator in your project, follow these steps:

  1. Import the necessary functions and types from the library:
import { validate, schemaValidate, Rule, Schema, toSchema } from 'simp-validator';

The validate function is used to validate a single value against a rule. The schemaValidate function is used to validate an entire data object against a schema. The Rule and Schema types are used to define validation rules and schemas, respectively. The toSchema function is used to generate a schema from a TypeScript interface.

  1. Define your validation rules using the Rule type:
const rule: Rule = {
  type: 'string',
  min: 2,
  max: 10,
  pattern: '^[a-zA-Z]+

The Rule type is an object that defines the validation rules for a single value. The type property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the validate function:
const value = 'hello';
const result = validate(value, rule);

The validate function takes a value and a rule, and returns a ValidationResult object. The ValidationResult object contains a success property indicating whether the validation was successful, and a message property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the schemaValidate function:
const data = {
  name: 'John',
  age: 25,
  email: 'john@example.com',
  hobbies: ['reading', 'swimming'],
};

const schema: Schema = {
  name: { type: 'string' },
  age: { type: 'number', min: 18 },
  email: { type: 'string', pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+

The schemaValidate function takes a data object and a schema, and returns a SchemaValidationResult object. The SchemaValidationResult object contains a success property indicating whether the validation was successful, a data property containing the parsed data if the validation was successful, and a details property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The name field is a required string. The age field is a number that must be at least 18. The email field is a string that must match a specific pattern. The hobbies field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
if (validationResult.success) {
  // Validation succeeded
  console.log('Validation passed!');
} else {
  // Validation failed
  console.error('Validation failed!');
  // Value validation error message
  console.error('Error messages:', validationResult.message);
  // Schema validation error object
  console.error('Error messages:', validationResult.details);
}

Check the success property of the ValidationResult or SchemaValidationResult object to determine whether the validation was successful. If the validation failed, check the message or details property for error messages.

  1. Generate a schema from a TypeScript interface using the toSchema function:
const rules: Rule[] = [
  { name: 'username', type: 'string' },
  { name: 'age', type: 'number', optional: true },
  { name: 'email', type: 'string', pattern: '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}

This code creates an array of Rule objects, calls the toSchema function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

validate(value: any, rule: Rule): ValidationResult

The validate function is used to validate a value against a given rule.

  • value: The value to validate.
  • rule: The rule to validate against.

Returns a ValidationResult object containing the result of the validation.

schemaValidate(data: any, schema: Schema): SchemaValidationResult

The schemaValidate function is used to validate an entire data object against a schema.

  • data: The data object to validate.
  • schema: The schema to validate against.

Returns a SchemaValidationResult object containing the result of the schema validation.

Rule

The Rule type represents a rule for validating a value. It has the following properties:

  • type: The allowed data type of the value.
  • optional: A boolean indicating whether the value is optional. Defaults to false.
  • valid: An array of valid values.
  • Additional properties depending on the data type:
    • For string: min, max, pattern, len
    • For number: integer, min, max
    • For boolean: No additional properties
    • For array: items, min, max, len
    • For date: min, max
  • name (required for schema conversion): The name of the field.
  • description: The description of the field.
  • message: The custom error message to display if the validation fails.
Schema

The Schema type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

ValidationResult

Validate a value against a rule. Returns a ValidationResult object containing the result of the validation.

  • success: A boolean indicating whether the validation was successful.
  • message: An error message if the validation failed.
SchemaValidationResult

Validate an entire data object against a schema. Returns a SchemaValidationResult object containing the result of the schema validation.

  • success: A boolean indicating whether the validation was successful.
  • data: The parsed data if the validation was successful.
  • details: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, hobbies: { type: 'array', items: { type: 'string', pattern: '^[a-zA-Z]+

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, min: 1, max: 5, }, }; const validationResult = schemaValidate(data, schema);

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, { name: 'hobbies', type: 'array', items: { type: 'string', pattern: '^[a-zA-Z]+

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, hobbies: { type: 'array', items: { type: 'string', pattern: '^[a-zA-Z]+

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, min: 1, max: 5, }, }; const validationResult = schemaValidate(data, schema);

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
} }, ]; const { schema, message } = toSchema(rules); if (schema) { console.log('Schema:', schema); } else { console.error('Error:', message); }

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, hobbies: { type: 'array', items: { type: 'string', pattern: '^[a-zA-Z]+

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
}, min: 1, max: 5, }, }; const validationResult = schemaValidate(data, schema);

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.
, len: 5, };

The __INLINE_CODE_6__ type is an object that defines the validation rules for a single value. The __INLINE_CODE_7__ property is required and specifies the data type of the value being validated. Other properties depend on the data type being validated. In this example, we're validating a string value that is required, must be between 2 and 10 characters long, must match the pattern /^[a-zA-Z]+$/, and must be exactly 5 characters long.

  1. Validate a single value using the __INLINE_CODE_8__ function:
__CODE_BLOCK_3__

The __INLINE_CODE_9__ function takes a value and a rule, and returns a __INLINE_CODE_10__ object. The __INLINE_CODE_11__ object contains a __INLINE_CODE_12__ property indicating whether the validation was successful, and a __INLINE_CODE_13__ property containing an error message if the validation failed.

  1. Validate an entire data object against a schema using the __INLINE_CODE_14__ function:
__CODE_BLOCK_4__

The __INLINE_CODE_15__ function takes a data object and a schema, and returns a __INLINE_CODE_16__ object. The __INLINE_CODE_17__ object contains a __INLINE_CODE_18__ property indicating whether the validation was successful, a __INLINE_CODE_19__ property containing the parsed data if the validation was successful, and a __INLINE_CODE_20__ property containing an object with error messages for each field if the validation failed.

In this example, we're validating an object with several fields. The __INLINE_CODE_21__ field is a required string. The __INLINE_CODE_22__ field is a number that must be at least 18. The __INLINE_CODE_23__ field is a string that must match a specific pattern. The __INLINE_CODE_24__ field is an array of strings that must match a specific pattern, must have at least one item, must have no more than five items, and must have unique items

  1. Check the validation result:
__CODE_BLOCK_5__

Check the __INLINE_CODE_25__ property of the __INLINE_CODE_26__ or __INLINE_CODE_27__ object to determine whether the validation was successful. If the validation failed, check the __INLINE_CODE_28__ or __INLINE_CODE_29__ property for error messages.

  1. Generate a schema from a TypeScript interface using the __INLINE_CODE_30__ function:
__CODE_BLOCK_6__

This code creates an array of __INLINE_CODE_31__ objects, calls the __INLINE_CODE_32__ function with that array, and then logs the resulting schema object to the console if there were no errors. If there was an error, it logs the error message to the console instead.

Supported Data Types

The Simp Validator supports the following data types for validation:

  • String
  • Number
  • Boolean
  • Array
  • Date

Each data type has its own set of validation rules that can be customized according to your needs.

API

__INLINE_CODE_33__

The __INLINE_CODE_34__ function is used to validate a value against a given rule.

  • __INLINE_CODE_35__: The value to validate.
  • __INLINE_CODE_36__: The rule to validate against.

Returns a __INLINE_CODE_37__ object containing the result of the validation.

__INLINE_CODE_38__

The __INLINE_CODE_39__ function is used to validate an entire data object against a schema.

  • __INLINE_CODE_40__: The data object to validate.
  • __INLINE_CODE_41__: The schema to validate against.

Returns a __INLINE_CODE_42__ object containing the result of the schema validation.

__INLINE_CODE_43__

The __INLINE_CODE_44__ type represents a rule for validating a value. It has the following properties:

  • __INLINE_CODE_45__: The allowed data type of the value.
  • __INLINE_CODE_46__: A boolean indicating whether the value is optional. Defaults to __INLINE_CODE_47__.
  • __INLINE_CODE_48__: An array of valid values.
  • Additional properties depending on the data type:
    • For __INLINE_CODE_49__: __INLINE_CODE_50__, __INLINE_CODE_51__, __INLINE_CODE_52__, __INLINE_CODE_53__
    • For __INLINE_CODE_54__: __INLINE_CODE_55__, __INLINE_CODE_56__, __INLINE_CODE_57__
    • For __INLINE_CODE_58__: No additional properties
    • For __INLINE_CODE_59__: __INLINE_CODE_60__, __INLINE_CODE_61__, __INLINE_CODE_62__, __INLINE_CODE_63__
    • For __INLINE_CODE_64__: __INLINE_CODE_65__, __INLINE_CODE_66__
  • __INLINE_CODE_67__ (required for schema conversion): The name of the field.
  • __INLINE_CODE_68__: The description of the field.
  • __INLINE_CODE_69__: The custom error message to display if the validation fails.
__INLINE_CODE_70__

The __INLINE_CODE_71__ type represents a schema for validating an entire data object. It is a record where the keys are the field names, and the values are the validation rules.

__INLINE_CODE_72__

Validate a value against a rule. Returns a __INLINE_CODE_73__ object containing the result of the validation.

  • __INLINE_CODE_74__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_75__: An error message if the validation failed.
__INLINE_CODE_76__

Validate an entire data object against a schema. Returns a __INLINE_CODE_77__ object containing the result of the schema validation.

  • __INLINE_CODE_78__: A boolean indicating whether the validation was successful.
  • __INLINE_CODE_79__: The parsed data if the validation was successful.
  • __INLINE_CODE_80__: An object containing error messages for each field if the validation failed.

Keywords