Last active 4 months ago

michelgentile's Avatar michelgentile revised this gist 4 months ago. Go to revision

1 file changed, 24 insertions

sanitize.js(file created)

@@ -0,0 +1,24 @@
1 + function sanitize( data, config )
2 + {
3 + //Object and arrays
4 + if( typeof( data ) == 'object' )
5 + {
6 + for( let key in data )
7 + {
8 + data[ key ] = sanitize( data[ key ], config );
9 + }
10 +
11 + return data;
12 + }
13 +
14 + //String
15 + if( typeof( data ) == 'string' )
16 + {
17 + //config: e.g. { ALLOWED_TAGS: [] }
18 + return DOMPurify.sanitize( data, config );
19 + }
20 + else
21 + {
22 + return data;
23 + }
24 + }
Newer Older