-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
73 lines (46 loc) · 1.16 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
exports = module.exports = search;
exports.connect = connect;
exports.params = params;
function search(val) {
if (!val)
return val;
var type = typeof val;
if (type === 'string') {
val = fix(val);
} else if (type === 'object' && val.constructor === Array) {
for (var i = 0; i < val.length; i++) {
val[i] = search(val[i]);
}
} else if (type === 'object') {
var keys = Object.keys(val);
for (var i = 0; i < keys.length; i++) {
val[keys[i]] = search(val[keys[i]]);
}
}
return val;
}
function fix(val) {
return String(val)
.replace(/٠/g, '0')
.replace(/١/g, '1')
.replace(/٢/g, '2')
.replace(/٣/g, '3')
.replace(/٤/g, '4')
.replace(/٥/g, '5')
.replace(/٦/g, '6')
.replace(/٧/g, '7')
.replace(/٨/g, '8')
.replace(/٩/g, '9')
.replace(/٪/g, '%');
}
function connect(req, res, next) {
req.body = search(req.body);
req.query = search(req.query);
req.params = search(req.params);
next();
}
function params(req, res, next) {
req.params = search(req.params);
next();
}