1 | const _ = require('lodash');
|
2 |
|
3 | exports.toString = require('../utils/to-string');
|
4 | exports.formatParamOutput = require('../utils/format-param-output');
|
5 |
|
6 | exports.mapAndExtend = function mapAndExtend(src, dest, mapFunction) {
|
7 | Object.keys(src).forEach(function (name) {
|
8 | dest[name] = mapFunction(name, src);
|
9 | });
|
10 | };
|
11 |
|
12 | exports.makeSanitizer = function makeSanitizer(methodName, container) {
|
13 | return function() {
|
14 | var _arguments = arguments;
|
15 | var result;
|
16 | this.values.forEach(function(value, i) {
|
17 | if (value != null) {
|
18 | var args = [value];
|
19 | args = args.concat(Array.prototype.slice.call(_arguments));
|
20 | result = container[methodName].apply(container, args);
|
21 |
|
22 | _.set(this.req[this.locations[i]], this.param, result);
|
23 | this.values[i] = result;
|
24 | }
|
25 | }.bind(this));
|
26 |
|
27 | return result;
|
28 | };
|
29 | };
|
30 |
|
31 | exports.replaceArgs = function replaceArgs(msg, args) {
|
32 | if (typeof msg !== 'string') {
|
33 | return msg;
|
34 | }
|
35 |
|
36 | return args.reduce((msg, arg, index) => msg.replace('%' + index, arg), msg);
|
37 | }; |
\ | No newline at end of file |