Add JSON/YAML components (#267)

Add CodeMirrorInput and VariablesField

Add components for syntax highlighting, YAML/JSON toggle
This commit is contained in:
Keith Grant
2019-06-18 12:32:22 -07:00
committed by GitHub
parent 0b10ff7fe6
commit e3cb8d0447
11 changed files with 459 additions and 2 deletions

17
src/util/yaml.js Normal file
View 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);
}