1.0.1 • Published 5 years ago

xoty v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Xoty: An extensible object type validation tool

Overview

Xoty is a type validation library to accelerate the data validation in RESTful APIS.

To use XOTY:

  • Define your object template
  • Use the template to validate objects

Basic use

let contactT = xoty.Template {
    firstName : xoty.string( { required: true, maxLength: 18, autoTruncate: true }),
    lastName : xoty.string( { required: true, maxLength: 18, autoTruncate: true }),
    age: xoty.int( required: false, min:1, max: 77 )
}    

myObject = { firstName: "John", lastName = "Doe"}

console.log(JSON.stringify(contactT.checkType(myObject),undefined,4 ))

Xoty will not only check the field values. It will also modify the values based on the formatting parametes provided.

Template reference

Types

Xoty currently supports the following types:

  • int: integer (value will be truncated)
  • number: any number
  • boolean: any value that can be interpreted as a boolean (true, false, Y, N, 1, 0)
  • string: a string that meets the defined criteria

Template parameters

  • required: indicates if a field must be present and not undefined (Default false)
  • default: when undefined, default value to use
  • acceptNull: true if a "null" value is accepted (Default false)
  • min, max: boundaries for numbers
  • maxLength: maximum length for string values
  • autoTruncate: if true, string value will be truncated to maxLength
  • values: an list of accepted values in an array
1.0.1

5 years ago

1.0.0

5 years ago