mirror of
https://github.com/ansible/awx.git
synced 2026-04-12 21:49:24 -02:30
Add JSON/YAML components (#267)
Add CodeMirrorInput and VariablesField Add components for syntax highlighting, YAML/JSON toggle
This commit is contained in:
17
src/util/yaml.js
Normal file
17
src/util/yaml.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export function yamlToJson (yamlString) {
|
||||
const value = yaml.safeLoad(yamlString);
|
||||
if (!value) { return '{}'; }
|
||||
if (typeof value !== 'object') {
|
||||
throw new Error('yaml is not in object format');
|
||||
}
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
|
||||
export function jsonToYaml (jsonString) {
|
||||
if (jsonString.trim() === '') { return '---\n'; }
|
||||
const value = JSON.parse(jsonString);
|
||||
if (Object.entries(value).length === 0) { return '---\n'; }
|
||||
return yaml.safeDump(value);
|
||||
}
|
||||
Reference in New Issue
Block a user