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

request-validator-csima

v1.0.15

Published

Extension to make web request validations easier

Downloads

35

Readme

Instalation

npm install request-validator-csima --save

How to use?

var RequestValidator = require('request-validator-csima');

var request_validator = new RequestValidator(configuration);
var validation_response = request_validator.validate(parameters, properties, extra_validation);

Description

Parameter configuration is an object with the following properties.

  • language: String language to use for messages response. Available: English(english) and Spanish(spanish).
  • remove_unknown: Boolean indicating if in the processed parameters, properties not recognized or properties with the the required flag as false would be removed. Properties with a final value will not be removed.
  • regex: JSON object with the following format example:
{
    "regex": {
        "password": "^(?=.*?[A-ZÑ])(?=.*?[a-zñ])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,40}$",
        "email": "(^(?=.{3,40}$)[a-zA-Z0-9_\\.-ñÑ]+@[\\da-zA-Z\\.-ñÑ]+\\.[\\da-zA-Z\\.-ñÑ]+$)"
    },
    "message": {
        "english": {
            "password": "The password must contain at least one number, one uppercase letter...",
            "email": "The string must be in email format"
        },
        "spanish": {
            "password": "La contraseña debe contener al menos un número, una letra minúscula...",
            "email": "La cadena debe estar en formato de correo electrónico",
        }
    }
}

Parameter parameters is an object to be evaluated.

Parameter properties is an object that describes how parameters need to be. Allowed properties:

  • id: String property name.
  • type: String property type. Allowed values: string, number, boolean, object and array.
  • try_parse: Boolean property type. If the current type is different to the target type, it will try to convert.
  • default_value: Default value for a property in case that it is undefined.
  • allowed: Array with the allowed values. Only for number and string type.
  • allow_single: Boolean indicating if the value of an array can be directly an element type of the array, so in this case the value will automatically be inside an array when the parameter is processed. Only for the array type.
  • allow_undefined: Boolean indicating if the value can be undefined, so when this property is true and the value is undefined the value will not be evaluated. Available for all types.
  • allow_null: Boolean indicating if the value can be null, so when this property is true and the value is null the value will not be evaluated. Available for all types.
  • properties: Array with objects that describe properties. Only for the object type.
  • item: Object that contains validations for elements inside of an array. Only for the array type.
  • regex: String regular expresion to use for the property. Available for all types. For types object and array the value used would be the serialized.
  • regex_type: String regular expresion key to use for the property. Available for all types. For types object and array the value used would be the serialized.
  • min_items: Minimum number of elements. For object type, it indicates the minumum of properties to be a valid value, while for array type, it indicaste the minimum of elements inside to be a valid value.
  • max_items: Minimum number of elements. For object type, it indicates the maximum of properties to be a valid value, while for array type, it indicaste the maximum of elements inside to be a valid value.
  • exact_items: Exact number of elements. For object type, it indicates the number of properties to be a valid value, while for array type, it indicaste the number of elements inside to be a valid value.
  • min_length: Minumum number of characteres. Only for string type.
  • max_length: Maximum number of characteres. Only for string type.
  • min_value: Minumum value allowed. Only for number type.
  • max_value: Maximum value allowed. Only for number type.
  • exact_length: Exact number of characteres. Only for string type.
  • required: Boolean indicating if the value is necessary and if it will be evaluated.
  • final_value: Any type of value to final assing to the property if it is not required.

A referential operation is when a property depends on other operation. To do this the value must be a string that starts and ends with |. To make a reference in the operation for the parameters you need to use $. The resulting value will be the assigned value. Only available for the property required, allow_undefined and allow_null. Example:

required: '|$.persona.age > 20|'

Parameter extra_validation is an optional function callback to make a extra validation for parameters. The function handles an only parameter, the proccesed parameters, in case to fail the validation, it will be necessary return a string with the fail detail to be shown, otherwise is not necessary to make a return.

The validation_response will be an object with next parameters:

  • status: Boolean that indicates the operation status.
  • message: String message with the operation description.
  • data: Parameters proccesed.