-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly emit quoted YAML for account numbers
Switch back to the newly-fixed 'yaml' package so that we can get both correct quoting of strings with leading '0' characters and correct quoting of strings with colon ':' characters. Fixes #1100, fixes #1098.
- Loading branch information
Rico Huijbers
committed
Nov 7, 2018
1 parent
d36d563
commit 28232ff
Showing
7 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import YAML = require('yaml'); | ||
|
||
/** | ||
* Stringify to YAML | ||
*/ | ||
export function toYAML(obj: any): string { | ||
return YAML.stringify(obj, { schema: 'yaml-1.1' }); | ||
} | ||
|
||
/** | ||
* Parse YAML | ||
*/ | ||
export function fromYAML(str: string): any { | ||
return YAML.parse(str, { schema: 'yaml-1.1' }); | ||
} | ||
|
||
/** | ||
* Parse either YAML or JSON | ||
*/ | ||
export function deserializeStructure(str: string) { | ||
try { | ||
return fromYAML(str); | ||
} catch (e) { | ||
// This shouldn't really ever happen I think, but it's the code we had so I'm leaving it. | ||
return JSON.parse(str); | ||
} | ||
} | ||
|
||
/** | ||
* Serialize to either YAML or JSON | ||
*/ | ||
export function serializeStructure(object: any, json: boolean) { | ||
if (json) { | ||
return JSON.stringify(object, undefined, 2); | ||
} else { | ||
return toYAML(object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters