File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ const stylish = ( tree ) => {
2+ const replacer = ' ' ;
3+ const spacesCount = 2 ;
4+
5+ const indentSize = spacesCount ;
6+ const currentIndent = replacer . repeat ( indentSize ) ;
7+ const closingBracketIndent = replacer . repeat ( indentSize - spacesCount ) ;
8+
9+ const properties = tree
10+ . map ( ( property ) => {
11+ switch ( property . type ) {
12+ case 'added' :
13+ return `${ currentIndent } + ${ property . key } : ${ property . value } ` ;
14+ case 'deleted' :
15+ return `${ currentIndent } - ${ property . key } : ${ property . value } ` ;
16+ case 'changed' :
17+ return `${ currentIndent } - ${ property . key } : ${ property . oldValue } \n${ currentIndent } + ${ property . key } : ${ property . newValue } ` ;
18+ default :
19+ return `${ currentIndent } ${ property . key } : ${ property . value } ` ;
20+ }
21+ } ) ;
22+
23+ return [
24+ '{' ,
25+ ...properties ,
26+ `${ closingBracketIndent } }` ,
27+ ] . join ( '\n' ) ;
28+ } ;
29+
30+ export default stylish ;
You can’t perform that action at this time.
0 commit comments