3
3
var TEST_REGEX = / ^ \$ | \. / ,
4
4
REPLACE_REGEX = / ^ \$ | \. / g;
5
5
6
- var withEach = function ( target , cb ) {
6
+ function isPlainObject ( obj ) {
7
+ if ( obj === null || typeof obj !== 'object' ) {
8
+ return false ;
9
+ }
10
+ var proto = Object . getPrototypeOf ( obj ) ;
11
+ return proto === Object . prototype || proto === null ;
12
+ }
13
+
14
+ function withEach ( target , cb ) {
7
15
var act = function ( obj ) {
8
16
if ( Array . isArray ( obj ) ) {
9
17
obj . forEach ( act ) ;
10
18
11
- } else if ( obj instanceof Object ) {
19
+ } else if ( isPlainObject ( obj ) ) {
12
20
Object . keys ( obj ) . forEach ( function ( key ) {
13
21
var val = obj [ key ] ;
14
22
var resp = cb ( obj , val , key ) ;
@@ -20,9 +28,9 @@ var withEach = function(target, cb) {
20
28
} ;
21
29
22
30
act ( target ) ;
23
- } ;
31
+ }
24
32
25
- var has = function ( target ) {
33
+ function has ( target ) {
26
34
var hasProhibited = false ;
27
35
withEach ( target , function ( obj , val , key ) {
28
36
if ( TEST_REGEX . test ( key ) ) {
@@ -34,9 +42,9 @@ var has = function(target) {
34
42
} ) ;
35
43
36
44
return hasProhibited ;
37
- } ;
45
+ }
38
46
39
- var sanitize = function ( target , options ) {
47
+ function sanitize ( target , options ) {
40
48
options = options || { } ;
41
49
42
50
var replaceWith = null ;
@@ -64,9 +72,9 @@ var sanitize = function(target, options) {
64
72
} ) ;
65
73
66
74
return target ;
67
- } ;
75
+ }
68
76
69
- var middleware = function ( options ) {
77
+ function middleware ( options ) {
70
78
return function ( req , res , next ) {
71
79
[ 'body' , 'params' , 'query' ] . forEach ( function ( k ) {
72
80
if ( req [ k ] ) {
@@ -75,7 +83,7 @@ var middleware = function(options) {
75
83
} ) ;
76
84
next ( ) ;
77
85
} ;
78
- } ;
86
+ }
79
87
80
88
module . exports = middleware ;
81
89
module . exports . sanitize = sanitize ;
0 commit comments