UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

38 lines (37 loc) 964 B
import { merge } from '../utils/object-utils.js'; import { validations } from '../jhipster/index.js'; const { Validations: { REQUIRED, PATTERN }, } = validations; export default class JDLValidation { name; value; constructor(args) { const merged = merge(defaults(), args); this.name = merged.name; this.value = merged.value; } toString() { let string = `${this.name}`; if (this.value || this.value === 0) { string += `(${formatValidationValue(this.name, this.value)})`; } return string; } } function defaults() { return { name: REQUIRED, value: '', }; } function formatValidationValue(name, value) { if (name === PATTERN) { return getPatternValidationValue(value); } return value; } function getPatternValidationValue(value) { if (value instanceof RegExp) { return value.toString(); } return `/${value}/`; }