UNPKG

transbank-sdk

Version:
24 lines (23 loc) 1.09 kB
class ValidationUtil { static hasText(value, valueName) { if (value == null || value == undefined || value.trim() == "") throw new Error("'" + valueName + "'" + " can't be null or white space"); } static hasTextWithMaxLength(value, length, valueName) { ValidationUtil.hasText(value, valueName); if (value.length > length) throw new Error("'" + valueName + "'" + " is too long, the maximum length is " + length); } static hasTextTrimWithMaxLength(value, length, valueName) { ValidationUtil.hasText(value, valueName); if (value.length > value.trim().length) throw new Error("'" + valueName + "'" + " has spaces at the beginning or the end"); if (value.length > length) throw new Error("'" + valueName + "'" + " is too long, the maximum length is " + length); } static hasElements(value, valueName) { if (value == null || value.length == 0) throw new Error("list '" + valueName + "'" + " can't be null or empty"); } } export default ValidationUtil;