All files / dist/types string.js

78.57% Statements 77/98
74.22% Branches 72/97
90.47% Functions 19/21
80.2% Lines 77/96

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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212  4x 4x 4x     4x   4x 4x   4x 4x 4x     4x 4x 4x 4x 4x 4x 4x                               4x 4x   211x 211x 211x             4x 13x     13x 13x             4x 13x     13x 13x             4x 30x     30x 30x               4x 22x     22x     22x 22x             4x 5x     5x 5x               4x 25x     25x     25x 25x             4x 5x     5x 5x               4x 22x     22x     22x 22x               4x 27x     27x     27x 27x             4x 13x     13x 13x             4x 113x     113x 113x             4x 13x     13x 13x   4x   4x 4x 211x    
"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.StringValidator = 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 string_1 = require("../messages/string");
/**
 * String Validator Class
 *
 * @method alphanumeric
 * @method credit_card
 * @method email
 * @method equal
 * @method fqdn
 * @method in
 * @method isbn
 * @method maxlength
 * @method minlength
 * @method required
 * @method url
 */
var StringValidator = /** @class */ (function (_super) {
    __extends(StringValidator, _super);
    function StringValidator() {
        var _this = _super.call(this) || this;
        _this.validators.push({ validator: constants_1.TYPES.STRING, type: constants_1.STRING_VALIDATOR_TYPES.TYPE, message: (0, errors_1.string_type_error_message)("${{}}") });
        return _this;
    }
    /**
     * Alphanumeric Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.alphanumeric = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.ALPHANUMERIC, message: message || (0, string_1.string_alphanumeric_error_message)() });
        return this;
    };
    /**
     * Credit Card Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.credit_card = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.CREDIT_CARD, message: message || (0, string_1.string_credit_card_error_message)() });
        return this;
    };
    /**
     * Email Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.email = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.EMAIL, message: message || (0, string_1.string_email_error_message)() });
        return this;
    };
    /**
     * Equal Validator
     *
     * @param {String} value
     * @param {String} message
     */
    StringValidator.prototype.equals = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!(0, validators_1.isString)(value)) {
            throw new Error((0, errors_1.string_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.STRING, type: constants_1.STRING_VALIDATOR_TYPES.EQUAL, value: value, message: message || (0, string_1.string_equal_error_message)() });
        return this;
    };
    /**
     * FQDN Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.fqdn = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.FQDN, message: message || (0, string_1.string_fqdn_error_message)() });
        return this;
    };
    /**
     * In Validator
     *
     * @param {Array} value
     * @param {String} message
     */
    StringValidator.prototype.in = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!(0, validators_1.isArray)(value)) {
            throw new Error((0, errors_1.array_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.STRING, type: constants_1.STRING_VALIDATOR_TYPES.IN, value: value, message: message || (0, string_1.string_in_error_message)() });
        return this;
    };
    /**
     * ISBN Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.isbn = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.ISBN, message: message || (0, string_1.string_isbn_error_message)() });
        return this;
    };
    /**
     * Maxlength Validator
     *
     * @param {String} value
     * @param {String} message
     */
    StringValidator.prototype.maxlength = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!(0, validators_1.isNumber)(value)) {
            throw new Error((0, errors_1.number_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.STRING, type: constants_1.STRING_VALIDATOR_TYPES.MAXLENGTH, value: value, message: message || (0, string_1.string_maxlength_error_message)(value) });
        return this;
    };
    /**
     * Minlength Validator
     *
     * @param {String} value
     * @param {String} message
     */
    StringValidator.prototype.minlength = function (value, message) {
        Iif (message && !(0, validators_1.isString)(message)) {
            throw new Error((0, errors_1.string_type_error_message)("message"));
        }
        Iif (!(0, validators_1.isNumber)(value)) {
            throw new Error((0, errors_1.number_type_error_message)("value"));
        }
        this.validators.push({ validator: constants_1.TYPES.STRING, type: constants_1.STRING_VALIDATOR_TYPES.MINLENGTH, value: value, message: message || (0, string_1.string_minlength_error_message)(value) });
        return this;
    };
    /**
     * Numeric Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.numeric = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.NUMERIC, message: message || (0, string_1.string_numeric_error_message)() });
        return this;
    };
    /**
     * Required Validator
     *
     * @param {String} message
     */
    StringValidator.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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.REQUIRED, message: message || (0, string_1.string_required_error_message)() });
        return this;
    };
    /**
     * URL Validator
     *
     * @param {String} message
     */
    StringValidator.prototype.url = 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.STRING, type: constants_1.STRING_VALIDATOR_TYPES.URL, message: message || (0, string_1.string_url_error_message)() });
        return this;
    };
    return StringValidator;
}(abstract_1.default));
exports.StringValidator = StringValidator;
exports.default = (function () {
    return new StringValidator();
});