UNPKG

para-client-js

Version:

JavaScript Client for Para

102 lines (101 loc) 3.28 kB
/** * Represents a validation constraint. * @author Alex Bogdanovski <alex@erudika.com> * @param {String} constraintName name * @param {Object} constraintPayload payload * @returns {Constraint} */ export default class Constraint { /** * The 'required' constraint - marks a field as required. * @returns {Constraint} */ static required(): Constraint; /** * The 'min' constraint - field must contain a number larger than or equal to min. * @param {Number} min the minimum value * @returns {Constraint} */ static min(min: number): Constraint; /** * The 'max' constraint - field must contain a number smaller than or equal to max. * @param {Number} max the maximum value * @returns {Constraint} */ static max(max: number): Constraint; /** * The 'size' constraint - field must be a String, Object or Array * with a given minimum and maximum length. * @param {Number} min the minimum length * @param {Number} max the maximum length * @returns {Constraint} */ static size(min: number, max: number): Constraint; /** * The 'digits' constraint - field must be a Number or String containing digits where the * number of digits in the integral part is limited by 'integer', and the * number of digits for the fractional part is limited * by 'fraction'. * @param {Number} i the max number of digits for the integral part * @param {Number} f the max number of digits for the fractional part * @returns {Constraint} */ static digits(i: number, f: number): Constraint; /** * The 'pattern' constraint - field must contain a value matching a regular expression. * @param {String} regex a regular expression * @returns {Constraint} */ static pattern(regex: string): Constraint; /** * The 'email' constraint - field must contain a valid email. * @returns {Constraint} */ static email(): Constraint; /** * The 'falsy' constraint - field value must not be equal to 'true'. * @returns {Constraint} */ static falsy(): Constraint; /** * The 'truthy' constraint - field value must be equal to 'true'. * @returns {Constraint} */ static truthy(): Constraint; /** * The 'future' constraint - field value must be a Date or a timestamp in the future. * @returns {Constraint} */ static future(): Constraint; /** * The 'past' constraint - field value must be a Date or a timestamp in the past. * @returns {Constraint} */ static past(): Constraint; /** * The 'url' constraint - field value must be a valid URL. * @returns {Constraint} */ static url(): Constraint; constructor(constraintName: any, constraintPayload: any); /** * The constraint name. * @returns {String} a name */ getName: () => string; /** * Sets the name of the constraint. * @param {String} n name */ setName: (n: string) => void; /** * The payload (a map) * @returns {Object} an object */ getPayload: () => any; /** * Sets the payload. * @param {Object} p the payload object */ setPayload: (p: any) => void; }