File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -4,20 +4,24 @@ var jsonPatch = require('fast-json-patch');
44
55export class JsonPatcher implements patch . IPatcher {
66 constructor (
7- private patches : patch . IPatch [ ] ,
8- private parse ?: ( content : string ) => any
7+ private patches : patch . IPatch [ ]
98 ) {
10- if ( ! this . parse ) {
11- this . parse = ( content ) => JSON . parse ( content ) ;
12- }
9+ }
10+
11+ protected parse ( content : string ) : any {
12+ return JSON . parse ( content ) ;
13+ }
14+
15+ protected stringify ( content : any ) : string {
16+ return JSON . stringify ( content ) ;
1317 }
1418
1519 apply ( content : string ) : string {
1620 var json = this . parse ( content ) ;
1721 var prevalidate = jsonPatch . validate ( this . patches , json ) ;
1822 var result = jsonPatch . apply ( json , this . patches , false ) ;
1923 if ( result ) {
20- return JSON . stringify ( json ) ;
24+ return this . stringify ( json ) ;
2125 } else {
2226 throw new Error ( 'Failed to apply patch' )
2327 }
Original file line number Diff line number Diff line change @@ -4,7 +4,11 @@ import patch = require('./common/patch');
44
55export class YamlPatcher extends jsonPatcher . JsonPatcher {
66
7- constructor ( patches : patch . IPatch [ ] ) {
8- super ( patches , ( content ) => jsYaml . safeLoad ( content ) ) ;
7+ parse ( content : string ) : any {
8+ return jsYaml . safeLoad ( content ) ;
9+ }
10+
11+ stringify ( content : any ) : string {
12+ return jsYaml . safeDump ( content ) ;
913 }
1014}
You can’t perform that action at this time.
0 commit comments