DEV Community

Cover image for VfyJs Package
mahdi
mahdi

Posted on • Edited on

VfyJs Package

Introducing VfyJS:

Simplifying Data Validation and More

VfyJS is a robust JavaScript library designed to streamline data validation, string manipulation, and error handling in your projects. Whether you're handling user inputs, configuration data, or API responses, VfyJS offers a comprehensive set of utilities to ensure data integrity and enhance code reliability.

What is VfyJS?

At its core, VfyJS provides a set of functions and tools to validate data, manipulate strings, and handle errors effectively. It simplifies common tasks that developers often face, allowing you to concentrate on building robust applications without compromising data integrity.

In Node.js

After installing the package, you can import it into your Node.js application. Below is an example demonstrating how to use vfyjs for password validation:

const vfyjs = require('vfyjs');

// Example usage
const data = '123!#@ScsA';
const validationResult = vfyjs.isPassword(data);
console.log(validationResult);
Enter fullscreen mode Exit fullscreen mode

The isPassword function checks whether the provided string meets the criteria for a valid password. Adjust the password variable with your actual password data for validation.

In Browser

To utilize vfyjs in a browser environment, include the vfyjs.browser.js script in your HTML file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Your Webpage</title>
</head>
<body>
    <!-- Include vfyjs script -->
    <script src="path/to/vfyjs.browser.js"></script>
    <script>
        // Example usage in browser
        const data = '123!#@ScsA';
        const validationResult = vfyjs.isPassword(data);
        console.log(validationResult);
    </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Ensure to replace "path/to/vfyjs.browser.js" with the correct path relative to your HTML file.

Features

Data Validation

  • Colors: Validate various color formats (hex, name, RGB, RGBA, etc.).
  • Links: Detect and validate HTTP or HTTPS links.
  • Passwords: Strong password detection with customization options.
  • Emails: Recognize and validate email addresses.
  • Phone Numbers: Validate phone numbers from 50 countries, providing detailed information.
  • Custom Validation Functions: Validate various aspects of a string input.

String Manipulation

  • getSubstring: Retrieve substrings from a given string based on specified indexes.
  • trimValue: Remove extra spaces from the beginning and end of a string.

Error Handling

  • HandleError: A utility for consistent error handling and type validation.

Benefits and Capabilities

  • Simplified Validation: Easily validate complex data like colors, links, and passwords.
  • String Manipulation: Efficiently manipulate strings with functions like getSubstring and trimValue.
  • Error Handling: Ensure consistent error handling and type validation with HandleError.
  • Customization: Tailor validation functions to your specific needs using customizable configurations.
  • Comprehensive Phone Number Validation: Obtain detailed information about phone numbers, including country, code, and type (landline or mobile).

What Sets VfyJS Apart?

1. Versatility and Coverage

  • Colors: Validate various color formats, including hex, name, RGB, RGBA, etc.
  • Links: Detect and validate HTTP or HTTPS links.
  • Passwords: Strong password detection with customization options.
  • Emails: Recognize and validate email addresses.
  • Phone Numbers: Validate phone numbers from 50 countries, providing detailed information.

2. String Manipulation Made Easy

  • getSubstring: Retrieve substrings from a given string based on specified indexes.
  • trimValue: Remove extra spaces from the beginning and end of a string.

3. Robust Error Handling

  • HandleError: A utility for consistent error handling and type validation.

Key Features and Benefits

1. Simplified Validation

  • Easily validate complex data like colors, links, and passwords.

2. Efficient String Manipulation

  • Perform operations like extracting substrings and trimming spaces with ease.

3. Consistent Error Handling

  • Ensure reliability with consistent error handling and type validation.

4. Customization Options

  • Tailor validation functions to your specific needs using customizable configurations.

5. Comprehensive Phone Number Validation

  • Obtain detailed information about phone numbers, including country, code, and type (landline or mobile).

Why Use VfyJS?

  • Efficiency: Save time and effort with pre-built functions for common validation tasks.
  • Reliability: Ensure data integrity and reliability with consistent error handling.
  • Clarity: Clearly defined functions and configurations for easy integration and use.

How to Use VfyJS

  1. Installation:
   npm install vfyjs
Enter fullscreen mode Exit fullscreen mode
  1. Usage Example:
   const { validatePhoneNumber, getSubstring, trimValue, HandleError } = require('vfyjs');

   // Validate a phone number
   validatePhoneNumber('1', '1234567890').then(result => {
      console.log(result);
   });

   // Get a substring
   const inputString = "Hello, World!";
   const result = getSubstring(inputString, [0, 5], [7, 12]);
   console.log(result); // Hello-World

   // Trim a value
   const inputString = ' H ell o, World! ';
   const result = trimValue(inputString);
   console.log(result); // Output: 'Hello, World!'

   // Handle an error
   const userAge = '25'; // Note: '25' is a string, not a number
   try {
       HandleError.IfNotType('number', userAge, 'Age should be a number');
       console.log('Age is valid.');
   } catch (error) {
       console.error(error.name); // 'TypeError'
       console.error(error.message); // 'Age should be a number'
   }
Enter fullscreen mode Exit fullscreen mode

Why Choose VfyJS?

  • Efficiency: Save time and effort with pre-built functions for common validation tasks.
  • Reliability: Ensure data integrity and reliability with consistent error handling.
  • Clarity: Clearly defined functions and configurations for easy integration and use.

Explore VfyJS

Documentation

For more detailed and comprehensive documentation, visit the GitHub Readme or the npm Readme. This documentation provides in-depth insights into the library's features, usage, and examples.

Key Links

Get Involved and Share Feedback

We value your feedback and involvement! Feel free to:

  • Explore the GitHub Discussions for community interaction and support.

  • Send a message on Telegram or Twitter to suggest improvements, provide criticism, report bugs, or share any concerns.

License

VfyJS is licensed under the MIT License, offering flexibility for usage and distribution in your projects.

In conclusion, VfyJS is your go-to JavaScript toolkit for simplifying data validation, string manipulation, and error handling. Whether you're a seasoned developer or just getting started, VfyJS provides the tools you need to build robust and reliable applications.

Explore VfyJS on GitHub and npm.

Top comments (0)