simple-body-validator
Version:
This package is inspired by Laravel validation, and aims to make body validation easier for Javascript developers
248 lines (247 loc) • 8.92 kB
TypeScript
import { Rules } from '../types';
declare class validateAttributes {
/**
* Stores the data object
*/
data: object;
/**
* Stores the rules object
*/
rules: Rules;
constructor(data?: object, rules?: Rules);
/**
* Validate that an attribute was "accepted".
*
* This validation rule implies the attribute is "required".
*/
validateAccepted(value: any): boolean;
/**
* Validate that an attribute was "accepted" when another attribute has a given value.
*/
validateAcceptedIf(value: any, parameters: string[]): boolean;
/**
* Validate the date is after a given date.
*/
validateAfter(value: any, parameters: string[]): boolean;
/**
* Validate the date is after or equal a given date.
*/
validateAfterOrEqual(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute contains only alphabetic characters.
*/
validateAlpha(value: any): boolean;
/**
* Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.
*/
validateAlphaDash(value: any): boolean;
/**
* Validate that an attribute contains only alpha-numeric characters.
*/
validateAlphaNum(value: any): boolean;
/**
* Validate that an attribute is an array
*/
validateArray(value: any): boolean;
/**
* Validate that an attribute is an array and that his values are unique
*/
validateArrayUnique(value: any): boolean;
/**
* Always returns true - this method will be used in conbination with other rules and will be used to stop validation of first failure
*/
validateBail(): boolean;
/**
* Validate the date is before a given date.
*/
validateBefore(value: any, parameters: string[]): boolean;
/**
* Validate the date is before or equal a given date.
*/
validateBeforeOrEqual(value: any, parameters: string[]): boolean;
/**
* Validate the size of an attribute is between a set of values
*/
validateBetween(value: any, parameters: number[], attribute: string): boolean;
/**
* Validate that an attribute is boolean
*/
validateBoolean(value: any, parameters: number[], attribute: string): boolean;
/**
* Validate that an attribute has matching confirmation.
*/
validateConfirmed(value: any, parameters: any, attribute: string): boolean;
/**
* Validate that an attribute is a valid date.
*/
validateDate(value: any): boolean;
/**
* Validate that an attribute is equal to another date.
*/
validateDateEquals(value: any, paramters: string[]): boolean;
/**
* Validate that an attribute was "declined".
*
* This validation rule implies the attribute is "required".
*/
validateDeclined(value: any): boolean;
/**
* Validate that an attribute was "declined" when another attribute has a given value.
*/
validateDeclinedIf(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute is different from another attribute.
*/
validateDifferent(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute has a given number of digits.
*/
validateDigits(value: any, parameters: any[]): boolean;
/**
* Validate that an attribute is between a given number of digits.
*/
validateDigitsBetween(value: any, parameters: any[]): boolean;
/**
* Validate that an attribute is a valid email address.
*/
validateEmail(value: any): boolean;
/**
* Validate the attribute ends with a given substring.
*/
validateEndsWith(value: any, parameters: string[]): boolean;
/**
* Validate that two attributes match.
*/
validateSame(value: any, paramaters: string[]): boolean;
/**
* Validate the size of an attribute.
*/
validateSize(value: any, parameters: string[], attribute: string): boolean;
/**
* Validate Optinial attributes. Always return true, just lets us put sometimes in rule.
*/
validateSometimes(): boolean;
/**
* Validate the attribute starts with a given substring.
*/
validateStartsWith(value: any, parameters: string[]): boolean;
/**
* Validate that a required attribute exists
*/
validateRequired(value: any): boolean;
/**
* Validate that an attribute exists when another atteribute has a given value
*/
validateRequiredIf(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute exists when another attribute does not have a given value.
*/
validateRequiredUnless(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute exists when any other attribute exists.
*/
validateRequiredWith(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute exists when all other attributes exist.
*/
validateRequiredWithAll(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute exists when another attribute does not.
*/
validateRequiredWithout(value: any, parameters: string[]): boolean;
/**
* Validate that an attribute exists when all other attributes do not.
*/
validateRequiredWithoutAll(value: any, parameters: string[]): boolean;
/**
* Determine if any of the given attributes fail the required test.
*/
anyFailingRequired(attributes: string[]): boolean;
/**
* Determine if all of the given attributes fail the required test.
*/
allFailingRequired(attributes: string[]): boolean;
/**
* Validate that an attribute is a string.
*/
validateString(value: any): boolean;
/**
* Validate the size of an attribute is less than a maximum value.
*/
validateMax(value: any, parameters: number[], attribute: string): boolean;
/**
* Validate the size of an attribute is greater than a minimum value.
*/
validateMin(value: any, parameters: number[], attribute: string): boolean;
/**
* Validate that an attribute is numeric.
*/
validateNumeric(value: any, parameters: string[], attribute: string): boolean;
/**
* Validate that an attribute is an object
*/
validateObject(value: any): boolean;
/**
* Validate that an attribute exists even if not filled.
*/
validatePresent(value: any, parameters: string[], attribute: string): boolean;
/**
* Validate that an attribute is an integer.
*/
validateInteger(value: any, parameters: string[], attribute: string): boolean;
/**
* Validate that the attribute is a valid JSON string
*/
validateJson(value: any): boolean;
/**
* Validate that an attribute is greater than another attribute.
*/
validateGt(value: any, parameters: any[], attribute: string): boolean;
/**
* Validate that an attribute is greater than or equal another attribute.
*/
validateGte(value: any, parameters: any[], attribute: string): boolean;
/**
* Validate that an attribute is less than another attribute.
*/
validateLt(value: any, parameters: any[], attribute: string): boolean;
/**
* Validate that an attribute is less than or equal another attribute.
*/
validateLte(value: any, parameters: any[], attribute: string): boolean;
/**
* Validate an attribute is contained within a list of values.
*/
validateIn(value: any, parameters: string[]): boolean;
/**
* "Indicate" validation should pass if value is null
*
* Always returns true, just lets us put "nullable" in rules.
*/
validateNullable(): boolean;
/**
* Validate an attribute is not contained within a list of values.
*/
validateNotIn(value: any, parameters: string[]): boolean;
/**
* Always returns true - this method will be used in conbination with other rules
*/
validateStrict(): boolean;
/**
* Validate that an attribute is a valid URL.
*/
validateUrl(value: any): boolean;
/**
* Determine if a comparison passes between the given values.
*/
compareDates(value: any, parameter: any, operator: string, rule: string): boolean;
/**
* Require a certain number of parameters to be present
*/
requireParameterCount(count: number, parameters: string[] | number[], rule: string): void;
/**
* Prepare the values for validation
*/
parseDependentRuleParameters(other: any, parameters: string[]): any[];
}
export default validateAttributes;