1.0.3 • Published 4 years ago

invalidando v1.0.3

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

invalidando

Valida tus JSON rápidamente | validate your JSON's fast

Import

var invalidando = require('invalidando');

Functions

  • invalidando.template(parameter)
    • Function: Create a template to compare the input JSONs with
    • Parameter: an Object with parameters and values
    • Returns: nothing
  • invalidando.valida(parameter)
    • Function: Validate weather the input JSON follows the template criteria
    • Parameter: A String containing JSON formated data
    • Returns:
      • A String when an error or invalid input is detected
      • An Object when the JSON meets the template criteria
  • invalidando.queTipo(parameter)
    • Function: Return the data type of the input parameter
    • Parameter: Number, Array, Object, String...
    • Returns: A string with the data type of the given parameter

First Step

Create a template

//Create an object to use it as template
var templateObject = new Object();
//Give the object properties and values
templateObject.firstProperty = 15;
//Create a template using an object as template
invalidando.template(templateObject);
//With the given object a template will be created and search for the given property names and data type
/*
	In the current example the template is used to tell the code that you want a template with a property called firstProperty and a value of type number
*/

Second Step

Validate your JSON

let someJSON='{"firstProperty":15}';
//Pass a JSON string as parameter
let isValid = invalidando.valida(someJSON);
if(typeof isValid == 'string'){
   //Some error ocurred, print error
   console.log(isValid);
 }else{
   //The JSON is valid, an Object has been returned
   console.log(isValid);  
}

Hecho en 🇵🇷 por Radamés J. Valentín Reyes