arch-unit-ts
Version:
34 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Assert = void 0;
class Assert {
static notNullOrUndefined(field, input) {
if (input == null) {
throw new Error(`${field} should not be null or undefined`);
}
}
static notBlank(field, input) {
this.notNullOrUndefined(field, input);
if (input.trim().length === 0) {
throw new Error(`${field} should not be blank`);
}
}
static path(field, path) {
this.notBlank(field, path);
const filePathPattern = /^(\/?[a-zA-Z0-9_@+.-]+)+(\.[a-zA-Z]+)*$/;
if (!filePathPattern.test(path)) {
throw new Error(`${field} '${path}' should be a path`);
}
}
static min(field, value, min) {
if (value < min) {
throw new Error(`${field} should not be less than ${min}`);
}
}
static notEmpty(field, collection) {
this.notNullOrUndefined(field, collection);
this.min(`${field} size`, collection.length, 1);
}
}
exports.Assert = Assert;
//# sourceMappingURL=Assert.js.map