@@ -15,7 +15,8 @@ class Abstract {
1515 required = true ,
1616 nullable = false ,
1717 normalize = true ,
18- getter = null
18+ getter = null ,
19+ lowercase = false
1920 } = { } ) {
2021 assert ( Object . keys ( positionMapping ) . includes ( position ) , `Unknown Parameter Position: ${ position } ` ) ;
2122 assert (
@@ -29,6 +30,7 @@ class Abstract {
2930 this . required = required ;
3031 this . nullable = nullable ;
3132 this . normalize = normalize ;
33+ this . lowercase = lowercase ;
3234 this . getter = getter ;
3335 this . type = null ;
3436 }
@@ -38,7 +40,7 @@ class Abstract {
3840 }
3941
4042 get ( event ) {
41- const result = get ( event , `${ positionMapping [ this . position ] } .${
43+ let result = get ( event , `${ positionMapping [ this . position ] } .${
4244 this . position === 'header'
4345 ? this . name . toLowerCase ( )
4446 : this . name
@@ -56,18 +58,23 @@ class Abstract {
5658 value : result
5759 } ) ;
5860 }
59- const r = this . getter !== null && ! [ undefined , null ] . includes ( result )
61+ result = this . getter !== null && ! [ undefined , null ] . includes ( result )
6062 ? ( params ) => this . getter ( result , params )
6163 : result ;
62- if ( typeof r !== 'string' || this . normalize === false ) {
63- return r ;
64+ if ( typeof result === 'string' ) {
65+ if ( this . normalize !== false ) {
66+ result = result
67+ // eslint-disable-next-line no-control-regex
68+ . replace ( / [ \x00 - \x09 \x0B \x1F \x7F - \x9F ] / g, ' ' )
69+ . replace ( / (?< = \s ) / g, '' )
70+ . replace ( / (? = \s ) / g, '' )
71+ . replace ( / \s + $ | ^ \s + / g, '' ) ;
72+ }
73+ if ( this . lowercase === true ) {
74+ result = result . toLowerCase ( ) ;
75+ }
6476 }
65- return r
66- // eslint-disable-next-line no-control-regex
67- . replace ( / [ \x00 - \x09 \x0B \x1F \x7F - \x9F ] / g, ' ' )
68- . replace ( / (?< = \s ) / g, '' )
69- . replace ( / (? = \s ) / g, '' )
70- . replace ( / \s + $ | ^ \s + / g, '' ) ;
77+ return result ;
7178 }
7279}
7380
0 commit comments