All files / dist/types date.js

78.57% Statements 44/56
69.81% Branches 37/53
84.61% Functions 11/13
81.48% Lines 44/54

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105  4x 4x 4x     4x   4x 4x   4x 4x 4x     4x 4x 4x 4x 4x 4x 4x                 4x 4x   59x 59x 59x               4x 20x     20x     20x 20x               4x 20x     20x     20x 20x               4x 20x     20x     20x 20x             4x 38x     38x 38x   4x   4x 4x 59x    
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        Iif (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateValidator = void 0;
var abstract_1 = require("./abstract");
var validators_1 = require("../utils/validators");
var constants_1 = require("../utils/constants");
var errors_1 = require("../utils/errors");
var date_1 = require("../messages/date");
/**
 * Date Validator Class
 *
 * @method after
 * @method before
 * @method equals
 * @method required
 */
var DateValidator = /** @class */ (function (_super) {
    __extends(DateValidator, _super);
    function DateValidator() {
        var _this = _super.call(this) || this;
        _this.validators.push({ validator: constants_1.TYPES.DATE, type: constants_1.DATE_VALIDATOR_TYPES.TYPE, message: (0, errors_1.date_type_error_message)("${{}}") });
        return _this;
    }
    /**
     * After Validator
     *
     * @param {Date} value
     * @param {String} message
     */
    DateValidator.prototype.after = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!value || !(0, validators_1.isDate)(value)) {
            throw new Error((0, errors_1.date_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.DATE, type: constants_1.DATE_VALIDATOR_TYPES.AFTER, message: message || (0, date_1.date_after_error_message)(value), value: value });
        return this;
    };
    /**
     * Before Validator
     *
     * @param {Date} value
     * @param {String} message
     */
    DateValidator.prototype.before = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!value || !(0, validators_1.isDate)(value)) {
            throw new Error((0, errors_1.date_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.DATE, type: constants_1.DATE_VALIDATOR_TYPES.BEFORE, value: value, message: message || (0, date_1.date_before_error_message)(value) });
        return this;
    };
    /**
     * Equal Validator
     *
     * @param {Date} value
     * @param {String} message
     */
    DateValidator.prototype.equals = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!value || !(0, validators_1.isDate)(value)) {
            throw new Error((0, errors_1.date_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.DATE, type: constants_1.DATE_VALIDATOR_TYPES.EQUAL, value: value, message: message || (0, date_1.date_equal_error_message)() });
        return this;
    };
    /**
     * Required Validator
     *
     * @param {String} message
     */
    DateValidator.prototype.required = function (message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        this.validators.push({ validator: constants_1.TYPES.DATE, type: constants_1.DATE_VALIDATOR_TYPES.REQUIRED, message: message || (0, date_1.date_required_error_message)() });
        return this;
    };
    return DateValidator;
}(abstract_1.default));
exports.DateValidator = DateValidator;
exports.default = (function () {
    return new DateValidator();
});