x-validate-form

1.0.5 • Public • Published

Validate Form

Purpose

The goal of this project is to develop an validation library for NodeJS and also to enhance my knowledge in javascript

Future Plans

  • Customization of validation
  • Support Async function for Customize validation
  • Custom Message Injection
  • Custom Attribute Injection
  • Handle Common validations e.g (required, email, number)

To apply SOLID principles to the provided code, here are some suggestions:

  1. Single Responsibility Principle (SRP):

    • The Validator class is responsible for validating fields based on defined rules. It should focus solely on validation logic and error handling. Consider moving the code related to rule registration (registerDefaultRules) to a separate class or module dedicated to rule management.
  2. Open/Closed Principle (OCP):

    • The Validator class could be extended to support custom rules without modifying its existing code. Currently, the extend function is directly modifying the rules object. Instead, consider using an interface or abstract class for rules, and allow external modules to implement and register custom rules by extending that interface or class.
  3. Liskov Substitution Principle (LSP):

    • Ensure that any derived classes (custom rules) used in place of the base class (default rules) maintain the same behavior and can be used interchangeably. Ensure that the registeredRule class follows the same contract as the default rule classes.
  4. Interface Segregation Principle (ISP):

    • Identify the minimal set of methods and properties required by clients of the Validator class. Extract those into an interface to decouple the class from its dependencies and allow clients to depend on abstractions rather than concrete implementations.
  5. Dependency Inversion Principle (DIP):

    • Currently, the Validator class directly depends on concrete implementations of rules (rules). Instead, consider using dependency injection to inject the rules as dependencies into the Validator class. This allows for easier testing, swapping out rule implementations, and reducing coupling.

By applying these principles, you can improve the modularity, maintainability, and flexibility of the codebase. Remember that SOLID principles are guidelines, and their application may vary depending on the specific requirements and constraints of your project.

Package Sidebar

Install

npm i x-validate-form

Weekly Downloads

33

Version

1.0.5

License

ISC

Unpacked Size

20.5 kB

Total Files

31

Last publish

Collaborators

  • tsunaweak