2021-12-10 23:22:57 +01:00
|
|
|
/**
|
|
|
|
|
* @author ccarpo [ccarpo@gmx.net]
|
|
|
|
|
* @copyright Crown Copyright 2021
|
|
|
|
|
* @license Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
|
import OperationError from "../errors/OperationError.mjs";
|
|
|
|
|
import YAML from "yaml";
|
|
|
|
|
|
|
|
|
|
/**
|
2025-03-10 20:55:35 +01:00
|
|
|
* JSON to YAML operation
|
2021-12-10 23:22:57 +01:00
|
|
|
*/
|
2025-03-10 20:55:35 +01:00
|
|
|
class JSONtoYAML extends Operation {
|
2021-12-10 23:22:57 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-03-10 20:55:35 +01:00
|
|
|
* JSONtoYAML constructor
|
2021-12-10 23:22:57 +01:00
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
2025-03-10 20:55:35 +01:00
|
|
|
this.name = "JSON to YAML";
|
2021-12-10 23:22:57 +01:00
|
|
|
this.module = "Default";
|
2023-11-21 09:19:58 +01:00
|
|
|
this.description = "Format a JSON object into YAML";
|
2021-12-10 23:22:57 +01:00
|
|
|
this.infoURL = "https://en.wikipedia.org/wiki/YAML";
|
|
|
|
|
this.inputType = "JSON";
|
|
|
|
|
this.outputType = "string";
|
|
|
|
|
this.args = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {JSON} input
|
|
|
|
|
* @param {Object[]} args
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
run(input, args) {
|
|
|
|
|
try {
|
|
|
|
|
return YAML.stringify(input);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw new OperationError("Test");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-10 20:55:35 +01:00
|
|
|
export default JSONtoYAML;
|