11'use strict' ;
22
3- var TEST_REGEX = / ^ \$ | \. / ,
4- REPLACE_REGEX = / ^ \$ | \. / g;
3+ const TEST_REGEX = / ^ \$ | \. / ;
4+ const REPLACE_REGEX = / ^ \$ | \. / g;
55
66function isPlainObject ( obj ) {
77 return typeof obj === 'object' && obj !== null ;
88}
99
1010function withEach ( target , cb ) {
11- var act = function ( obj ) {
11+ ( function act ( obj ) {
1212 if ( Array . isArray ( obj ) ) {
1313 obj . forEach ( act ) ;
1414
1515 } else if ( isPlainObject ( obj ) ) {
1616 Object . keys ( obj ) . forEach ( function ( key ) {
17- var val = obj [ key ] ;
18- var resp = cb ( obj , val , key ) ;
17+ const val = obj [ key ] ;
18+ const resp = cb ( obj , val , key ) ;
1919 if ( resp . shouldRecurse ) {
2020 act ( obj [ resp . key || key ] ) ;
2121 }
2222 } ) ;
2323 }
24- } ;
24+ } ) ( target ) ;
2525
26- act ( target ) ;
2726}
2827
2928function has ( target ) {
30- var hasProhibited = false ;
29+ let hasProhibited = false ;
3130 withEach ( target , function ( obj , val , key ) {
3231 if ( TEST_REGEX . test ( key ) ) {
3332 hasProhibited = true ;
@@ -43,13 +42,13 @@ function has(target) {
4342function sanitize ( target , options ) {
4443 options = options || { } ;
4544
46- var replaceWith = null ;
45+ let replaceWith = null ;
4746 if ( ! ( TEST_REGEX . test ( options . replaceWith ) ) ) {
4847 replaceWith = options . replaceWith ;
4948 }
5049
5150 withEach ( target , function ( obj , val , key ) {
52- var shouldRecurse = true ;
51+ let shouldRecurse = true ;
5352
5453 if ( TEST_REGEX . test ( key ) ) {
5554 delete obj [ key ] ;
@@ -72,7 +71,7 @@ function sanitize(target, options) {
7271
7372function middleware ( options ) {
7473 return function ( req , res , next ) {
75- [ 'body' , 'params' , 'query' ] . forEach ( function ( k ) {
74+ [ 'body' , 'params' , 'headers' , ' query'] . forEach ( function ( k ) {
7675 if ( req [ k ] ) {
7776 req [ k ] = sanitize ( req [ k ] , options ) ;
7877 }
0 commit comments