UNPKG

guarder

Version:

Guarder provides simple validation logic to reduce clutter with inline guard statements

27 lines 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Guarder_1 = require("../Guarder"); const ArgumentError_1 = require("../errors/ArgumentError"); /** * Whitespace Guard validates that the string does not contain only whitespace */ class WhitespaceGuard { /** * @inheritDoc */ guard(property, errorMessage, error) { const parsedProperty = Guarder_1.Guarder.empty(property) .toString(); const isEmptyString = typeof parsedProperty === 'string' ? parsedProperty.trim() .length === 0 : false; if (isEmptyString) { const message = errorMessage !== null && errorMessage !== void 0 ? errorMessage : 'Property is not allowed to contain only whitespace'; if (error) throw new error(message); throw new ArgumentError_1.ArgumentError(message); } return property; } } exports.WhitespaceGuard = WhitespaceGuard; //# sourceMappingURL=WhitespaceGuard.js.map