-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (35 loc) · 1.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ParamCheck = function () {
function ParamCheck(adapter) {
_classCallCheck(this, ParamCheck);
this.adapter = adapter;
}
_createClass(ParamCheck, [{
key: "withValidation",
value: function withValidation(name, schema, callback) {
var _this = this;
return function () {
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
var _adapter = _this.adapter(params, schema),
error = _adapter.error;
if (!error) return callback.apply(undefined, params);
throw new Error("ParamCheck:" + name + ":" + error);
};
}
}], [{
key: "funcContainer",
value: function funcContainer(fn, cb) {
try {
return fn();
} catch (error) {
return cb(error);
}
}
}]);
return ParamCheck;
}();
module.exports = ParamCheck;