JavaScript validation library

Usage no npm install needed!

<script type="module">
  import valtors from '';


Valtors npm package

Valtors is a small flexible and extensible validation library for TypeScript/JavaScript. It provides decorators for classes and properties. Perfect worked with MobX.

Class decorator @validatable injects method validate(propName?: keyof this) and property with validation errors (default is validationErrors) which will available after validate method will be called.

React + MobX + Valtors Example

// Store for react component

import { action, observable } from 'mobx';
import { email, required, validatable } from 'valtors';

// @validatable without arguments injects `validationErrors` property for validation errors
export default class AuthCredentialsStore {

  @required('Password is required')

  submit() {
    // Validate all fields.
    if (!this.validate()) return;
    // If store is valid submit.

// React component

import React, { useCallback } from 'react';
import { action } from 'mobx';
import { observer } from 'mobx-react-lite';
import styles from './SignIn.css';

function SignIn({ store }) {
  const onSubmit = useCallback(action((e) => {
  }), [store]);

  const onChange = useCallback(action(({ target: { name, value } }) => {
    store[name] = value;
    store.validate(name); // Validate only one field.
  }), [store]);

  const { errors } = store;
  return (
    <form onSubmit={onSubmit} noValidate>
      <input value={store.username} onChange={onChange} name="username" type="email" placeholder="email">
      <span className={errors.username.error ? styles['error'] : styles['hide']}>{errors.username.error}</span>

      <input value={store.password} onChange={onChange} name="password" type="password" placeholder="password">
      <span className={errors.password.error ? styles['error'] : styles['hide']}>{errors.password.error}</span>

      <button className={styles['btn-login']} type="submit">Login</button>

export default observer(SignIn);