1
1
'use strict'
2
2
3
- const { map, fromPairs, isEmpty, isArray } = require ( 'lodash' )
3
+ const { map, fromPairs, isEmpty, isObject , isArray, mapValues , isPlainObject } = require ( 'lodash' )
4
4
const xss = require ( 'xss' )
5
5
6
6
const getValue = async ( { htmlDom, url, conditions, meta } ) => {
@@ -15,11 +15,14 @@ const getValue = async ({ htmlDom, url, conditions, meta }) => {
15
15
return value
16
16
}
17
17
18
- const escapeValue = ( value , { escape } ) => {
19
- if ( ! escape ) return value
20
- return isArray ( value ) ? map ( value , xss ) : xss ( value )
18
+ const mapValuesDeep = ( object , fn ) => {
19
+ if ( isArray ( object ) ) return map ( object , innerObject => mapValuesDeep ( innerObject , fn ) )
20
+ if ( isObject ( object ) ) return mapValues ( object , value => mapValuesDeep ( value , fn ) )
21
+ return fn ( object )
21
22
}
22
23
24
+ const escapeValue = ( value , { escape } ) => ( ! escape ? value : mapValuesDeep ( value , xss ) )
25
+
23
26
const getData = async ( { rules, htmlDom, url, escape } ) => {
24
27
const data = await Promise . all (
25
28
map ( rules , async ( [ propName , conditions ] ) => {
0 commit comments