Class: ValidationBase

ValidationBase(value)

Utility class for validating and manipulating data types and structures.

Constructor

new ValidationBase(value)

Constructs a ValidationBase instance with the provided value for validation.

Parameters:
Name Type Description
value *

The value to be validated.

Source:

Members

value

Gets the current value being validated.

Source:

Methods

array() → {ValidationBase}

Validates if the value is an array.

Source:
Returns:
  • Returns the current instance if the value is an array; otherwise, rejects the validation.
Type
ValidationBase

arrayFilled() → {boolean}

Validates if the array is non-empty.

Source:
Returns:
  • Returns true if the array is non-empty; otherwise, false.
Type
boolean

eval(dontReturnValueopt) → {boolean|*}

Checks if the validation was successful and evaluates the result.

Parameters:
Name Type Attributes Default Description
dontReturnValue boolean <optional>
false

A flag indicating whether to return the value on success.

Source:
Returns:
  • Returns true if successful, the validated value if dontReturnValue is false, or false on failure.
Type
boolean | *

filled(zeroIsFalse) → {Object}

Determines if the current value is considered filled based on its type and optional condition.

Parameters:
Name Type Description
zeroIsFalse boolean

A flag indicating whether the value 0 should be treated as false (optional).

Source:
Returns:
  • Returns the current object instance if the value is considered filled, otherwise rejects the object.
Type
Object

function() → {ValidationBase}

Validates if the value is a function.

Source:
Returns:
  • Returns the current instance if the value is a function; otherwise, rejects the validation.
Type
ValidationBase

number() → {ValidationBase}

Validates if the value is a number and not NaN.

Source:
Returns:
  • Returns the current instance if the value is a valid number; otherwise, rejects the validation.
Type
ValidationBase

numberFilled() → {boolean}

Validates if the number is non-zero and not NaN.

Source:
Returns:
  • Returns true if the number is non-zero and not NaN; otherwise, false.
Type
boolean

object() → {ValidationBase}

Validates if the value is an object (excluding arrays).

Source:
Returns:
  • Returns the current instance if the value is a non-array object; otherwise, rejects the validation.
Type
ValidationBase

objectFilled() → {boolean}

Validates if the object is non-empty (not null, undefined, or empty object).

Source:
Returns:
  • Returns true if the object is non-empty; otherwise, false.
Type
boolean

path(zeroIsFalseopt) → {ValidationBase}

Validates if the value exists and is not null, undefined, empty string, empty object, empty array, or zero (if zeroIsFalse is true for numbers).

Parameters:
Name Type Attributes Default Description
zeroIsFalse boolean <optional>
false

A flag indicating whether zero should be considered a false value for numbers.

Source:
Returns:
  • Returns the current instance if the value is non-empty; otherwise, rejects the validation.
Type
ValidationBase

reject() → {ValidationBase}

Marks the validation as unsuccessful and sets the success flag to false.

Source:
Returns:
  • Returns the current instance after marking it as unsuccessful.
Type
ValidationBase

setValue(newValue) → {*}

Sets a new value for validation.

Parameters:
Name Type Description
newValue *

The new value to be set for validation.

Source:
Returns:
  • The new value after setting.
Type
*

string() → {ValidationBase}

Validates if the value is a string.

Source:
Returns:
  • Returns the current instance if the value is a string; otherwise, rejects the validation.
Type
ValidationBase

stringFilled() → {boolean}

Validates if the string is non-empty.

Source:
Returns:
  • Returns true if the string is non-empty; otherwise, false.
Type
boolean

(static) isCompleteDoc(obj) → {boolean}

Static method to determine if the provided object IS A COMPLETE DOC

Parameters:
Name Type Description
obj *

The object to be checked.

Source:
Returns:
  • true if the object is a MongoDB ObjectID, false otherwise.
Type
boolean

(static) isObjectID(obj) → {boolean}

Static method to determine if the provided object is a MongoDB ObjectID.

Parameters:
Name Type Description
obj *

The object to be checked.

Source:
Returns:
  • true if the object is a MongoDB ObjectID, false otherwise.
Type
boolean