Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

validate

  • Validates the target object.

    Example

    class Invalid {
    @IsDefined() p0: any = null;
    }
    const I = new Invalid();
    let oes = validate(I);
    expect(oes.valid).toBeFalsy();
    const key = getPropertyKey(I, 'p0');//Invalid_p0
    expect(oes.getErrors(key).length).toBeGreaterThan(0);
    expect(oes.errors[0].errorMessage).toContain('p0');

    Parameters

    • target: any

      The object being validated.

    • Optional exclude: string[]

      Array of property values to exclude from validation.

    Returns ObjectErrors

    The ObjectErrors instance

validateN

  • validateN(entities: any[], exlude?: string[]): ObjectErrors[]
  • Validate multiple entity instances

    Example

    class Invalid {
    @IsDefined() p0: any = null;
    }

    let entities:Invalid[] = [ new Invalid(), new Invalid() ]
    let oesArr:ObjectErrors[] = validateN(entities)
    expect(oesArr[0].valid).toBeFalsy();
    expect(oesArr[1].valid).toBeFalsy();

    Parameters

    • entities: any[]

      The array of entities to be validated.

    • Optional exlude: string[]

    Returns ObjectErrors[]

    The ObjectErrors array which is empty if there are no errors

validateProperty

  • validateProperty(o: any, propertyName: string, oes?: ObjectErrors, skipErrorGeneration?: boolean): boolean
  • Validates a property contained on the object. Errors are added to the ObjectErrors, instance, unless skipErrorGeneration is true.

    Example

    class Invalid {
    @IsDefined() p0: any = null;
    }
    const I = new Invalid();
    let oes = new ObjectErrors();
    expect(validateProperty(I, 'p0', oes)).toBeFalsy();
    const key = getPropertyKey(I, 'p0');
    expect(oes.getErrors(key).length).toBeGreaterThan(0);
    throws

    An exception if the ValidationContextContainer instance for the object and property does not exist.

    Parameters

    • o: any

      The object being validated

    • propertyName: string

      The name of the property holding the value being validated

    • Optional oes: ObjectErrors

      The ObjectErrors instance used to collect ValidationErrors

    • skipErrorGeneration: boolean = false

      Skips the generation of validation errors

    Returns boolean

    true if the property is valid, false otherwise.

Generated using TypeDoc