UNPKG

sluicebox

Version:

Quickly and elegantly add search, sort and pagination to your plural resource endpoints.

41 lines (33 loc) 949 B
(function() { var Errors, slice = [].slice; Errors = (function() { function Errors() { this.value = {}; this.empty = true; } Errors.prototype.add = function() { var base, ctx, errors, ref; ctx = arguments[0], errors = 2 <= arguments.length ? slice.call(arguments, 1) : []; this.empty = false; if (!errors.length) { errors = [ctx]; ctx = 'global'; } if ((base = this.value)[ctx] == null) { base[ctx] = { errors: [] }; } (ref = this.value[ctx].errors).push.apply(ref, errors); return this; }; Errors.wrap = function() { var ctx, messages, ref; ctx = arguments[0], messages = 2 <= arguments.length ? slice.call(arguments, 1) : []; return (ref = new Errors).add.apply(ref, [ctx].concat(slice.call(messages))).value; }; return Errors; })(); module.exports = Errors; }).call(this);