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 🙏

© 2026 – Pkg Stats / Ryan Hefner

validations-lib

v1.0.1-0.11

Published

All types validation

Readme

Validations-lib

This library contains all types of validations required for Node and Angular 6

How to use it:

Javascript

var validationsLib=required('validations-lib');

Angular app

import {Validation,FieldValidation} from 'validations-lib'

required object

var object = {
     title: 'number 1',
     type: 'number',
     required:true,
     condition: 'gt',
     currentValue: '1',
     message: 'number 1 must be greater than 25 ',
     params: [25],
     uid:'#1'
}

Pass your object into this validations-lib

javascript


var result= validationsLib.Validation.validate(object)

typescript node 8+

var result= Validation.validate(new FieldValidation(object))

Your output will be

{'result':false,message:'number 1 must be greater than 25'}

Description of the base object

| Property | Details | Default | | ------------- | ------------------------------------|---------| | title | Validation(field) Title(string) |blank | | type | Field Type(type of question) |text | | condition | Conditons like greater than |blank | | currentValue | Input (Field input) |blank | | message | Customise your message |lib generated| | params | Compare the values |blank| | required | Required fields |false| | uid | Unique identifier(numeric-optional) |blank|

Title

Your field or Validation Title

Input Type(s)

| Types | Details |
| ---------------------- | ---------------------------------------------------------------------------------------| | text | By default it is text type | | number | Allows only number type | | multiselect-dropdown | Allows only single dimensional arrray of elements | | date | Date format (moment js) | | time | Time format (moment js) | | datetime | Allow date with time | | timeRange | Allows an array of time [time1,time2] or [[time1],[time2]] | | dateRange | Allows an array of date [date1,date2] or [[date1],[date2]] | | dateTimeRange | Allows an array of date with time [datetime1,datetime2] or [[datetime1],[datetime2]] |

Condition(s) applied on fields

| Types | Details | Support
| ---------------------- | -------------------------------------------------------------------------|---------- | gt | Greater than | all types | lt | Less than | all types | eq | Equal to | all types | lte | Less than or equal to | all types | gte | Greater than or equal to | all types | notEqual | Not equal to | all types | between | Between | all types except(ranges) | notBetween | Not Between | all types except(ranges) | sameAs | This condition is only for text type (String match) | text | notSame | This condition is only for text type (String does not match) | text | contains | Text contains (String that contains specific string of character/s) | text | notContains | Text not contains (String that does not contain specific string of character/s) | text | startwith | Text start with (String starting with a particular character/s) | text | endswith | Text ends with (String starting with a particular character/s) | text

Message

One can have their own customised validation messages otherwise validations-lib provides default messages as well.

Params

Based on the validations-lib here you can pass maximumm 2 parameters as mentioned below

| Types | Details |
| ---------------------- | -------------------------------------------------------------------------| | min | Minimun number of elements | | max | Maximum number of elements |

If one wants to set min value and max value one by one (one after the other) then one can use setParams() method with one argument.

Required (optional)

If you pass a boolean value in this object then it will give you appropriate message accordingly with UID otherwise by default it will return false.

uid (Unique ID)

This property contains unique identification of an object.

Example

If you pass two parameters then it considers is as 'between' or 'not between' case.

In case of 'between' your object will be something like as shown below:

var object ={
     title: 'number 1',
     type: 'number',
     required:true,
     condition: 'between',
     currentValue: '1',
     message: 'number 1 must be between than 25 to 30',
     params: [25,30],
     uid:'#1'
}

Multiple Field Validation

If you have a bunch of fields for validation in a single object, then we have to providee uid in question as well as entry object

Example

var object = [
  {
       title: 'number 1',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 1 must be between than 25 to 30',
       params: [25,30],
       uid:'#1'
  },
  {
       title: 'number 2',
       type: 'number',
       required:true,
       condition: 'between',
       message: 'number 2 must be between than 25 to 30',
       params: [25,30],
       uid:'#2'
  },
  {
       title: 'number 3',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 3 must be between than 20 to 30',
       params: [20,30],
       uid:'#3'
  },
  {
       title: 'number 4',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 4 must be between than 25 to 30',
       params: [25,30],
       uid:'#4'
  }
]  

And your final input object will look something like below:

var entry = {
'#1':1,
'#2':2,
'#3':40,
'#4':6
}
var result = validationsLib.validateWithGroup(entry,object)

Output

{
'#1':{'result':false,message:'number 1 must be between than 25 to 30'},
'#2':{'result':false,message:'number 2 must be between than 25 to 30'},
'#3':{'result':false,message:'number 3 must be between than 20 to 30'},
'#4':{'result':false,message:'number 4 must be between than 25 to 30'}
}

Comparison with another question

If you want to compare your question with another question then specify uid in params, then your object will look something like this

 {
       title: 'number 4',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 4 must be between than 25 to #3 value',
       params: [25,'#3'],
       uid:'#4'
  }
  

output

result Key 'all' field is valid or not

{
'#1':{'result':false,message:'number 1 must be between than 25 to 30'},
'#2':{'result':false,message:'number 2 must be between than 25 to 30'},
'#3':{'result':false,message:'number 3 must be between than 20 to 30'},
'#4':{'result':false,message:'number 4 must be between than 25 to 40'}
'result':false
}

For any other requirements

Feel free to mail me at [email protected]

github URL

https://github.com/saurabhrathod35/validations-lib