UNPKG

1.03 kBJavaScriptView Raw
1const _ = require('lodash');
2
3exports.toString = require('../utils/to-string');
4exports.formatParamOutput = require('../utils/format-param-output');
5
6exports.mapAndExtend = function mapAndExtend(src, dest, mapFunction) {
7 Object.keys(src).forEach(function (name) {
8 dest[name] = mapFunction(name, src);
9 });
10};
11
12exports.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
31exports.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