validata
Version:
Type safe data validation and sanitization
32 lines • 1.02 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Issue = exports.exists = exports.isIssue = exports.isValue = void 0;
const isValue = (result) => {
return !!result && ('value' in result);
};
exports.isValue = isValue;
const isIssue = (result) => {
return !!result && result.issues !== undefined;
};
exports.isIssue = isIssue;
const exists = (value) => {
return value !== undefined;
};
exports.exists = exists;
class Issue {
constructor(path, value, reason, info) {
this.path = path;
this.value = value;
this.reason = reason;
this.info = info;
}
}
exports.Issue = Issue;
Issue.forPath = (path, value, reason, info) => {
return new Issue(Array.isArray(path) ? path : [path], value, reason, info);
};
Issue.nest = (parentPath, issue) => {
const path = Array.isArray(parentPath) ? parentPath : [parentPath];
return new Issue([...path, ...issue.path], issue.value, issue.reason, issue.info);
};
//# sourceMappingURL=types.js.map
;