Skip to content

Releases: debuggers-dev/mobikit-typescript

Mobikit TypeScript v1.0.2

09 May 18:33
Compare
Choose a tag to compare

Mobikit TypeScript v1.0.2

Mobikit TypeScript is a powerful validation library for TypeScript applications, providing a comprehensive set of validation rules for form inputs and data structures.

Features

  • 🚀 TypeScript Support: Built from the ground up with TypeScript
  • 🔍 Extensive Validation Rules: Over 20 built-in validation rules
  • 🌐 Internationalization: Support for multiple languages
  • Async Validation: Support for asynchronous validation rules
  • 🧩 Extensible: Easy to add custom validation rules

Validation Rules

This release includes the following validation rules:

  • required: Ensures a field is not empty
  • min: Validates minimum numeric values
  • max: Validates maximum numeric values
  • email: Validates email addresses
  • regex: Validates against regular expressions
  • same: Ensures two fields have the same value
  • numeric: Ensures a field contains only numbers
  • maxLen: Validates maximum string length
  • minLen: Validates minimum string length
  • required_if: Conditionally requires a field based on another field's value
  • required_unless: Conditionally requires a field unless another field has a specific value
  • required_with: Requires a field when another specified field is present
  • required_without: Requires a field when another specified field is not present
  • required_with_all: Requires a field when all other specified fields are present
  • required_without_all: Requires a field when all other specified fields are not present
  • uppercase: Ensures a field contains only uppercase characters
  • lowercase: Ensures a field contains only lowercase characters
  • json: Validates that a field contains valid JSON
  • alpha: Ensures a field contains only alphabetic characters
  • in: Validates that a field's value is in a given list
  • not_in: Validates that a field's value is not in a given list

Installation

npm install mobikit-typescript

or

yarn add mobikit-typescript

Basic Usage

import { Validator } from 'mobikit-typescript';

const validator = new Validator('en');

const data = {
  username: 'test',
  email: 'invalid-email',
  age: '25'
};

const rules = {
  username: {
    required: { value: true, message: 'Username is required.' },
    minLen: { value: 5, message: 'Username must have at least 5 characters.' }
  },
  email: {
    required: { value: true, message: 'Email is required.' },
    email: { value: true, message: 'Please enter a valid email address.' }
  },
  age: {
    numeric: { value: true, message: 'Age must be a number.' }
  }
};

async function validate() {
  const errors = await validator.validate(data, rules);
  if (errors) {
    console.log(errors);
  } else {
    console.log('Validation passed!');
  }
}

validate();

Breaking Changes

None (initial release)

Bug Fixes

None (initial release)

Future Plans

  • Add more validation rules
  • Improve error messages
  • Add more language support
  • Enhance documentation