11import _ from 'lodash' ;
22import getPath from '../getPath.js' ;
33
4- const getValue = ( elem ) => {
5- if ( elem . keyOld || elem . keyNew ) {
6- return `"oldValue": ${ formatValue ( elem . keyOld ) } , "newValue": ${ formatValue ( elem . keyNew ) } ` ;
7- }
8- return `"value": ${ formatValue ( elem . value ) } ` ;
9- } ;
10-
114const formatValue = ( value ) => {
125 if ( _ . isNull ( value ) || _ . isBoolean ( value ) || _ . isNumber ( value ) ) {
136 return value ;
14- } else if ( _ . isPlainObject ( value ) ) {
7+ } else if ( _ . isPlainObject ( value ) ) {
158 return JSON . stringify ( value ) ;
169 }
1710 return `"${ value } "` ;
1811} ;
1912
13+ const getValue = ( elem ) => {
14+ if ( elem . keyOld || elem . keyNew ) {
15+ return `"oldValue": ${ formatValue ( elem . keyOld ) } , "newValue": ${ formatValue (
16+ elem . keyNew
17+ ) } `;
18+ }
19+ return `"value": ${ formatValue ( elem . value ) } ` ;
20+ } ;
21+
2022const formatJson = ( data , parentPath = '' ) => {
21- const iner = ( data , parentPath ) => data
22- . filter ( ( elem ) => elem . condition !== 'dash' )
23- . map ( ( elem ) => {
24- const { condition, children } = elem ;
25- const currentPath = getPath ( elem , parentPath ) ;
26- if ( condition === 'unchanged' ) {
27- return `${ iner ( children , currentPath ) } ` ;
28- }
29- return `{"name": "${ currentPath } ", ${ getValue ( elem ) } , "condition": "${ condition } "}` ;
30- } ) ;
23+ const iner = ( data , parentPath ) =>
24+ data
25+ . filter ( ( elem ) => elem . condition !== 'dash' )
26+ . map ( ( elem ) => {
27+ const { condition, children } = elem ;
28+ const currentPath = getPath ( elem , parentPath ) ;
29+ if ( condition === 'unchanged' ) {
30+ return `${ iner ( children , currentPath ) } ` ;
31+ }
32+ return `{"name": "${ currentPath } ", ${ getValue (
33+ elem
34+ ) } , "condition": "${ condition } "}`;
35+ } ) ;
3136 const result = iner ( data , parentPath ) . join ( ',' ) ;
3237 return `[${ result } ]` ;
3338} ;
3439
35- export default formatJson ;
40+ export default formatJson ;
0 commit comments