@codeparticle/formal
Version:
A <2kb library for validating data of any kind
45 lines (43 loc) • 995 B
JavaScript
import {
checkIsValidationM
} from "./chunk-BWJJJL7W.mjs";
// src/fail.ts
var Fail = class {
constructor(value, errors = []) {
this.value = null;
this.errors = [];
this.isSuccess = false;
this.value = value;
this.errors = errors;
}
static of(value, errors = []) {
return new Fail(value, errors);
}
map() {
return new Fail(this.value, this.errors);
}
chain(validationM) {
var _a;
try {
const result = validationM(this.value, this.errors);
checkIsValidationM(result);
return new Fail(result.value, [...this.errors, ...(_a = result == null ? void 0 : result.errors) != null ? _a : []]);
} catch (error) {
console.error(error.message);
console.error(error.stack);
}
}
fold({ onFail }) {
return onFail(this.errors);
}
};
export {
Fail
};
/**
* @file class to describe validation failures.
* @name Failure.js
* @author Nick Krause
* @license MIT
*/
//# sourceMappingURL=chunk-PTDFSPAW.mjs.map