@darkobits/valida
Version:
Type-aware object validator.
38 lines (31 loc) • 853 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.decorateMethod = decorateMethod;
exports.formatMessage = formatMessage;
exports.isPredicate = isPredicate;
var _ow = require("ow");
function formatMessage(err) {
if (!err || typeof err.stack !== 'string') return;
return err.message.split('\n').map(line => {
if (line.endsWith(':') || line.endsWith('.')) {
return line;
}
return `${line}.`;
}).join('\n');
}
function isPredicate(value) {
return value instanceof _ow.Predicate;
}
function decorateMethod(ctor, methodName, decorator) {
const originalMethod = ctor.prototype[methodName];
ctor.prototype[methodName] = function (...args) {
return decorator({
args,
method: originalMethod.bind(this),
instance: this
});
};
}
//# sourceMappingURL=utils.js.map