@@ -32,13 +32,15 @@ export class Utils {
32
32
return hash ;
33
33
}
34
34
35
- public static getCookies ( cookies :string ) : Object {
35
+ public static getCookies ( cookies :string , exclusions ?: string [ ] ) : Object {
36
36
let result :Object = { } ;
37
37
38
38
let parts :string [ ] = ( cookies || '' ) . split ( '; ' ) ;
39
39
for ( let index = 0 ; index < parts . length ; index ++ ) {
40
40
let cookie :string [ ] = parts [ index ] . split ( '=' ) ;
41
- result [ cookie [ 0 ] ] = cookie [ 1 ] ;
41
+ if ( ! Utils . isMatch ( cookie [ 0 ] , exclusions ) ) {
42
+ result [ cookie [ 0 ] ] = cookie [ 1 ] ;
43
+ }
42
44
}
43
45
44
46
return result ;
@@ -84,7 +86,7 @@ export class Utils {
84
86
return null ;
85
87
}
86
88
87
- public static parseQueryString ( query :string ) {
89
+ public static parseQueryString ( query :string , exclusions ?: string [ ] ) {
88
90
if ( ! query || query . length === 0 ) {
89
91
return null ;
90
92
}
@@ -97,7 +99,9 @@ export class Utils {
97
99
let result :Object = { } ;
98
100
for ( let index = 0 ; index < pairs . length ; index ++ ) {
99
101
let pair = pairs [ index ] . split ( '=' ) ;
100
- result [ decodeURIComponent ( pair [ 0 ] ) ] = decodeURIComponent ( pair [ 1 ] ) ;
102
+ if ( ! Utils . isMatch ( pair [ 0 ] , exclusions ) ) {
103
+ result [ decodeURIComponent ( pair [ 0 ] ) ] = decodeURIComponent ( pair [ 1 ] ) ;
104
+ }
101
105
}
102
106
103
107
return result ;
@@ -108,20 +112,23 @@ export class Utils {
108
112
}
109
113
110
114
/**
111
- * Stringifys an object with optional exclusions and max depth.
112
- * @param data The data object to add.
113
- * @param exclusions Any property names that should be excluded.
114
- * @param maxDepth The max depth of the object to include.
115
+ * Checks to see if a value matches a pattern.
116
+ * @param input the value to check against the @pattern.
117
+ * @param pattern The pattern to check, supports wild cards (*).
115
118
*/
116
- public static stringify ( data :any , exclusions ?:string [ ] , maxDepth ?:number ) : string {
117
- function checkForMatch ( pattern :string , value :string ) : boolean {
118
- if ( ! pattern || ! value || typeof value !== 'string' ) {
119
+ public static isMatch ( input :string , patterns :string [ ] ) :boolean {
120
+ if ( ! input || typeof input !== 'string' ) {
121
+ return false ;
122
+ }
123
+
124
+ let trim = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g;
125
+ return ( patterns || [ ] ) . some ( pattern => {
126
+ if ( ! pattern ) {
119
127
return false ;
120
128
}
121
129
122
- let trim = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g;
123
130
pattern = pattern . toLowerCase ( ) . replace ( trim , '' ) ;
124
- value = value . toLowerCase ( ) . replace ( trim , '' ) ;
131
+ input = input . toLowerCase ( ) . replace ( trim , '' ) ;
125
132
126
133
if ( pattern . length <= 0 ) {
127
134
return false ;
@@ -138,27 +145,33 @@ export class Utils {
138
145
}
139
146
140
147
if ( startsWithWildcard && endsWithWildcard ) {
141
- return value . indexOf ( pattern ) !== - 1 ;
148
+ return input . indexOf ( pattern ) !== - 1 ;
142
149
}
143
150
144
151
if ( startsWithWildcard ) {
145
- return value . lastIndexOf ( pattern ) === ( value . length - pattern . length ) ;
152
+ return input . lastIndexOf ( pattern ) === ( input . length - pattern . length ) ;
146
153
}
147
154
148
155
if ( endsWithWildcard ) {
149
- return value . indexOf ( pattern ) === 0 ;
156
+ return input . indexOf ( pattern ) === 0 ;
150
157
}
151
158
152
- return value === pattern ;
153
- }
159
+ return input === pattern ;
160
+ } ) ;
161
+ }
154
162
163
+ /**
164
+ * Stringifys an object with optional exclusions and max depth.
165
+ * @param data The data object to add.
166
+ * @param exclusions Any property names that should be excluded.
167
+ * @param maxDepth The max depth of the object to include.
168
+ */
169
+ public static stringify ( data :any , exclusions ?:string [ ] , maxDepth ?:number ) : string {
155
170
function stringifyImpl ( obj :any , excludedKeys :string [ ] ) : string {
156
171
let cache :string [ ] = [ ] ;
157
172
return JSON . stringify ( obj , function ( key :string , value :any ) {
158
- for ( let index = 0 ; index < ( excludedKeys || [ ] ) . length ; index ++ ) {
159
- if ( checkForMatch ( excludedKeys [ index ] , key ) ) {
160
- return ;
161
- }
173
+ if ( Utils . isMatch ( key , excludedKeys ) ) {
174
+ return ;
162
175
}
163
176
164
177
if ( typeof value === 'object' && ! ! value ) {
@@ -177,12 +190,12 @@ export class Utils {
177
190
if ( ( { } ) . toString . call ( data ) === '[object Array]' ) {
178
191
let result = [ ] ;
179
192
for ( let index = 0 ; index < data . length ; index ++ ) {
180
- result [ index ] = JSON . parse ( stringifyImpl ( data [ index ] , exclusions || [ ] ) ) ;
193
+ result [ index ] = JSON . parse ( stringifyImpl ( data [ index ] , exclusions ) ) ;
181
194
}
182
195
183
196
return JSON . stringify ( result ) ;
184
197
}
185
198
186
- return stringifyImpl ( data , exclusions || [ ] ) ;
199
+ return stringifyImpl ( data , exclusions ) ;
187
200
}
188
201
}
0 commit comments