-
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 (#1105)
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
Showing
8 changed files
with
73 additions
and
42 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
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