npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

validue

v1.1.3

Published

This library is based on the "class-validator" library. It will help you easily validate your fields, forms and etc.. All you need to use is @PropertyValidate and @ActionValidate decorators, and all decorators from “class validator” such as @Max, @IsEmail

Downloads

15

Readme

enter image description here

This library is based on the "class-validator" library. It will help you easily validate your fields, forms and etc.. All you need to use is @PropertyValidator , @ErrorValidator, @ActionValidator decorators, and all decorators from “class validator” such as @Max, @IsEmail and etc..

Instalation

npm i validue

Demo

Go to the link bellow for watch demo

Link demo on the codesandbox

Example

Validation errors check automatically because Validue create a Vue Watcher for watching field editing. This example close to the real task, all you need to append for work it's a business logic in the SignUp method

<template>
  <form>
    <div class="text-field">
      <label class="text-field__label" for="username"> Your username </label>
      <input class="text-field__input" id="username" placeholder="Enter username">
      <p class="text-field__error" v-if="usernameErrors.isNotEmpty || usernameErrors.length">
        {{usernameErrors.isNotEmpty || usernameErrors.length}} 
      </p>
    </div>
    <div class="text-field">
      <label class="text-field__label" for="email"> Your email </label>
      <input class="text-field__input" id="email" placeholder="Enter email">
      <p class="text-field__error" v-if="emailErrors.isNotEmpty || emailErrors.isEmail">
        {{emailErrors.isNotEmpty || emailErrors.isEmail}}
      </p>
    </div>
    <button @click="signUp"> Sign up </button>
  </form>
</template>
<script lang="ts">
import {Component, Vue} from "vue-property-decorator";
import {ActionValidator, PropertyValidator, ErrorValidator, IsNotEmpty, IsEmail, Length} from "validue";

@Component({})
export default class App extends Vue {

  @IsNotEmpty({message: "Required field"})
  @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})
  username = "";

  @IsNotEmpty({message: "Required field"})
  @IsEmail({}, {message: "Wrong email address"})
  email = "";

  @PropertyValidator("username")
  usernameErrors = {};

  @PropertyValidator("email")
  emailErrors = {};
  
  @ActionValidator()
  signUp(@ErrorValidator errors: []){
    if(errors.length){
      console.log('U have some errors');
      return;
    }
    //... your business logic
  }
}
</script>

Usage

@PropertyValidator has 3 override syntax:

PropertyValidator(path: string, validationFunctions?: Function[], options?: WatchOptions)

PropertyValidator(path: string, validationFunctions?:Function[])

PropertyValidator(path: string, options?: WatchOptions)

You need to add this decorator before the field, errors in which are written after validation. First argument is a field that is watched. It works like @Watch decorator in Vue. Second argument receives an array of validation functions. This argument is not required because you can use 2 methods to declare validation of your fields.

All decorators of "class-validator" in here

Example: 1 Way:

    import {Component, Vue} from "vue-property-decorator";    
    import {ActionValidator, PropertyValidator,IsNotEmpty, IsEmail, Length} from "validue";  
      
    @Component({})  
    export default class App extends Vue {  
      
	    @IsNotEmpty({message: "Required field"})  
	    @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
	    firstName = "";  
  
	    @IsNotEmpty({message: "Required field"})  
	    @IsEmail({}, {message: "Wrong email address"})  
	    email = "";  
  
	    @PropertyValidator("firstName")  
	    firstNameErrors = {};  
  
	    @PropertyValidator("email")  
	    emailErrors = {};  
    }

2 Way:

  
   import {Component, Vue} from "vue-property-decorator";  
   import {ActionValidator, PropertyValidator,IsNotEmpty, IsEmail, Length} from "validue";  
     
   @Component({})  
   export default class App extends Vue {  
     
       firstName = "";  
       email = "";  
     
       @PropertyValidator("firstName", [  
           IsNotEmpty({message: "Required field"}),  
           Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
       ])  
       firstNameErrors = {};  
     
       @PropertyValidator("email", [  
           IsNotEmpty({message: "Required field"}),  
           IsEmail({}, {message: "Wrong email address"})  
       ])  
       emailErrors = {};  
   }

@ActionValidator(group?: string[])

This decorator is added before the method. Thus, before the method is called, all fields and field groups are validated, and returned errors are written in fields with @ProperyValidator added before. Example without group:

    import {Component, Vue} from "vue-property-decorator";  
    import {ActionValidator, PropertyValidator,IsNotEmpty, IsEmail, Length} from "validue";  
      
    @Component({})  
    export default class App extends Vue {  
      
        @IsNotEmpty({message: "Required field"})  
        @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
        firstName = "";  
      
        @IsNotEmpty({message: "Required field"})  
        @IsEmail({}, {message: "Wrong email address"})  
        email = "";  
      
        @PropertyValidator("firstName")  
        firstNameErrors = {};  
      
        @PropertyValidator("email")  
        emailErrors = {};  
      
        @ActionValidator()  
        send(){  
            console.log(this.firstNameErrors, this.emailErrors);  
        }  
    } 

Example with group:

    import {Component, Vue} from "vue-property-decorator";  
    import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";  
      
    @Component({})  
    export default class App extends Vue {  
      
        @IsNotEmpty({message: "Required field",
        groups: ['registration']})  
        @Length(1, 10, {message: "Field more then 10 chars or less then 1 char", 
        groups: ['registration']})  
        firstName = "";  
      
        @IsNotEmpty({message: "Required field", 
        groups: ['registration']})  
        @Length(1, 10, {message: "Field more then 10 chars or less then 1 char", 
        groups: ['registration']})  
        lastName = "";  
      
        @PropertyValidator("firstName")  
        firstNameErrors = {};  
      
        @PropertyValidator("lastName")  
        lastNameErrors = {};  
      
        @IsNotEmpty({message: "Required field", 
        groups: ['auth']})  
        @IsEmail({}, {message: "Wrong email address", groups: ['auth']})  
        email = "";  
      
        @IsNotEmpty({message: "Required field", 
        groups: ['auth']})  
        @IsEmail({}, {message: "Wrong email address", groups: ['auth']})  
        password = "";  
      
        @PropertyValidator("email")  
        emailErrors = {};  
      
        @PropertyValidator("password")  
        passwordErrors = {};  
      
        @ActionValidator(['registration'])  
        register(){  
            //Will validate fields which have group 'registration'  
        }  
      
        @ActionValidator(['auth'])  
        auth(){  
            //Will validate fields which have group 'auth'  
        }  
    } 

All decorators of "class-validator" in here

Example: 1 Way:

    import {Component, Vue} from "vue-property-decorator";  
    import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";  
      
    @Component({})  
    export default class App extends Vue {  
      
	    @IsNotEmpty({message: "Required field"})  
	    @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
	    firstName = "";  
  
	    @IsNotEmpty({message: "Required field"})  
	    @IsEmail({}, {message: "Wrong email address"})  
	    email = "";  
  
	    @PropertyValidator("firstName")  
	    firstNameErrors = {};  
  
	    @PropertyValidator("email")  
	    emailErrors = {};  
    }

2 Way:

  
   import {Component, Vue} from "vue-property-decorator";  
   import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";  
     
   @Component({})  
   export default class App extends Vue {  
     
       firstName = "";  
       email = "";  
     
       @PropertyValidator("firstName", [  
           IsNotEmpty({message: "Required field"}),  
           Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
       ])  
       firstNameErrors = {};  
     
       @PropertyValidator("email", [  
           IsNotEmpty({message: "Required field"}),  
           IsEmail({}, {message: "Wrong email address"})  
       ])  
       emailErrors = {};  
   }

@ActionValidator(group?: string[])

This decorator is added before the method. Thus, before the method is called, all fields and field groups are validated, and returned errors are written in fields with @ProperyValidator added before. Example without group:

    import {Component, Vue} from "vue-property-decorator";   
    import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";  
      
    @Component({})  
    export default class App extends Vue {  
      
        @IsNotEmpty({message: "Required field"})  
        @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})  
        firstName = "";  
      
        @IsNotEmpty({message: "Required field"})  
        @IsEmail({}, {message: "Wrong email address"})  
        email = "";  
      
        @PropertyValidator("firstName")  
        firstNameErrors = {};  
      
        @PropertyValidator("email")  
        emailErrors = {};  
      
        @ActionValidator()  
        send(){  
            console.log(this.firstNameErrors, this.emailErrors);  
        }  
    } 

Example with group:

    import {Component, Vue} from "vue-property-decorator";
import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";

@Component({})
export default class App extends Vue {

    @IsNotEmpty({message: "Required field",
        groups: ['registration']})
    @Length(1, 10, {message: "Field more then 10 chars or less then 1 char",
        groups: ['registration']})
    firstName = "";

    @IsNotEmpty({message: "Required field",
        groups: ['registration']})
    @Length(1, 10, {message: "Field more then 10 chars or less then 1 char",
        groups: ['registration']})
    lastName = "";

    @PropertyValidator("firstName")
    firstNameErrors = {};

    @PropertyValidator("lastName")
    lastNameErrors = {};

    @IsNotEmpty({message: "Required field",
        groups: ['auth']})
    @IsEmail({}, {message: "Wrong email address", groups: ['auth']})
    email = "";

    @IsNotEmpty({message: "Required field",
        groups: ['auth']})
    @IsEmail({}, {message: "Wrong email address", groups: ['auth']})
    password = "";

    @PropertyValidator("email")
    emailErrors = {};

    @PropertyValidator("password")
    passwordErrors = {};

    @ActionValidator(['registration'])
    register(){
        //Will validate fields which have group 'registration'  
    }

    @ActionValidator(['auth'])
    auth(){
        //Will validate fields which have group 'auth'  
    }
} 

@ErrorValidator paramName

This decorator is added in method's param and after call the method in this variable will write all need errors ('need' cuz u can use Groups, see upper)

import {Component, Vue} from "vue-property-decorator";
import {ActionValidator, PropertyValidator, IsNotEmpty, IsEmail, Length} from "validue";
import {ErrorValidator} from './validue-decorators';

@Component({})
export default class App extends Vue {

    @IsNotEmpty({message: "Required field"})
    @Length(1, 10, {message: "Field more then 10 chars or less then 1 char"})
    firstName = "";

    @IsNotEmpty({message: "Required field"})
    @IsEmail({}, {message: "Wrong email address"})
    email = "";

    @PropertyValidator("firstName")
    firstNameErrors = {};

    @PropertyValidator("email")
    emailErrors = {};

    @ActionValidator()
    send(@ErrorValidator errors) {
        console.log(errors) // errors = [ {firstNameErrors: {...errors-here...}}, {emailErrors: {...errors-here...}}]
    }
}