Module: util/Validator

Useful and commonly used validation functions used throughout the app

Author:
  • Serge Babayan
Source:

Requires

  • module:underscore

Methods


<inner> isBooleanInt(number)

Checks if a value is a bollean integer (1 or 0)

Parameters:
Name Type Description
number string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isFloat(number)

Checks if a value is a float only

Parameters:
Name Type Description
number string | Number

The value to check

Source:
Returns:
Type
boolean
Example
Validator.isFloat('23.23') //true
Validator.isFloat(34.44) //true
Validator.isFloat(4) //false
Validator.isFloat('4') //false

<inner> isInteger(number)

Checks if a value is an integer only

Parameters:
Name Type Description
number string | Number

The value to check

Source:
Returns:
Type
boolean
Example
Validator.isInteger('23.23') //false
Validator.isInteger(34.44) //false
Validator.isInteger(4) //true
Validator.isInteger('4') //true

<inner> isNonEmptyString(value)

Checks if a value is a string

Parameters:
Name Type Description
value string

The value to check

Source:
Returns:
Type
boolean

<inner> isObject(object)

Checks if a value is an object

Parameters:
Name Type Description
object Object

The value to check

Source:
Returns:
Type
boolean

<inner> isPositiveNumber(number)

Checks if a value is a positive number

Parameters:
Name Type Description
number string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isString(value)

Checks if a value is a string

Parameters:
Name Type Description
value mixed

The value to check

Source:
Returns:
Type
boolean

<inner> isValidAltitude(altitude)

Checks if a value is valid altitude (number above -5m)

Parameters:
Name Type Description
altitude string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidBattery(battery)

Checks if a value is valid battery level

Parameters:
Name Type Description
battery string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidFlap(flap)

Checks if a value is valid flap (between -1024 and 1024)

Parameters:
Name Type Description
flap string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidGpsStatus(gps)

Checks if a value is valid gps status

Parameters:
Name Type Description
gps string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidHeading(heading)

Checks if a value is valid roll (number between 0 and 360)

Parameters:
Name Type Description
heading string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidLatitude(lat)

Checks if a value is valid latitude

Parameters:
Name Type Description
lat string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidLongitude(lon)

Checks if a value is valid longitude

Parameters:
Name Type Description
lon string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidNumber(number)

Checks if a value is numeric (Note: '123.32' and 123.32 are both numeric)

Parameters:
Name Type Description
number string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidPercentage(percentage)

Checks if a value is valid percentage between 0 and 100

Parameters:
Name Type Description
percentage string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidPitch(pitch)

Checks if a value is valid pitch (number between -180 and 180)

Parameters:
Name Type Description
pitch string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidPWM(value)

Checks if a value is valid 10-bit pwm value (between -1024 and 1024)

Parameters:
Name Type Description
value string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidRoll(roll)

Checks if a value is valid roll (number between -180 and 180)

Parameters:
Name Type Description
roll string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidSpeed(speed)

Checks if a value is valid, positive speed

Parameters:
Name Type Description
speed string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidThrottle(throttle)

Checks if a value is valid throttle (between -1024 and 1024)

Parameters:
Name Type Description
throttle string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidTime(timestring)

Checks if a value is valid UTC time

Parameters:
Name Type Description
timestring string | Number

The value to check

Source:
Returns:
Type
boolean

<inner> isValidYaw(yaw)

Checks if a value is valid roll

Parameters:
Name Type Description
yaw string | Number

The value to check

Source:
Returns:
Type
boolean