This commit is contained in:
sai praneeth 2025-06-07 15:14:27 +00:00 committed by GitHub
commit 54c3d8e7bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 103 additions and 5 deletions

10
package-lock.json generated
View file

@ -54,6 +54,7 @@
"jq-web": "^0.5.1", "jq-web": "^0.5.1",
"jquery": "3.7.1", "jquery": "3.7.1",
"js-sha3": "^0.9.3", "js-sha3": "^0.9.3",
"js-yaml": "^4.1.0",
"jsesc": "^3.0.2", "jsesc": "^3.0.2",
"json5": "^2.2.3", "json5": "^2.2.3",
"jsonata": "^2.0.3", "jsonata": "^2.0.3",
@ -12366,7 +12367,6 @@
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"argparse": "^2.0.1" "argparse": "^2.0.1"
@ -19245,16 +19245,16 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/yaml": { "node_modules/yaml": {
"version": "2.7.0", "version": "2.8.0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.0.tgz",
"integrity": "sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==", "integrity": "sha512-4lLa/EcQCB0cJkyts+FpIRx5G/llPxfP6VQU5KByHEhLxY3IJCH0f0Hy1MHI8sClTvsIb8qwRJ6R/ZdlDJ/leQ==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {
"yaml": "bin.mjs" "yaml": "bin.mjs"
}, },
"engines": { "engines": {
"node": ">= 14" "node": ">= 14.6"
} }
}, },
"node_modules/yargs": { "node_modules/yargs": {

View file

@ -140,6 +140,7 @@
"jq-web": "^0.5.1", "jq-web": "^0.5.1",
"jquery": "3.7.1", "jquery": "3.7.1",
"js-sha3": "^0.9.3", "js-sha3": "^0.9.3",
"js-yaml": "^4.1.0",
"jsesc": "^3.0.2", "jsesc": "^3.0.2",
"json5": "^2.2.3", "json5": "^2.2.3",
"jsonata": "^2.0.3", "jsonata": "^2.0.3",

View file

@ -470,6 +470,7 @@
"SQL Beautify", "SQL Beautify",
"SQL Minify", "SQL Minify",
"CSS Beautify", "CSS Beautify",
"YAML Beautify",
"CSS Minify", "CSS Minify",
"XPath expression", "XPath expression",
"JPath expression", "JPath expression",

View file

@ -0,0 +1,51 @@
/**
* @author MrMadFox [c.saipraneeth888@gmail.com]
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import YAML from "js-yaml";
import OperationError from "../errors/OperationError.mjs";
/**
* YAMLBeautify operation
*/
class YAMLBeautify extends Operation {
/**
* YAMLBeautify constructor
*/
constructor() {
super();
this.name = "YAML Beautify";
this.module = "Code";
this.description = "Indents and prettifies YAML code.";
this.infoURL = "https://yaml.org/";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
try {
return YAML.dump(YAML.load(input), {
styles: {
"!!null": "empty"
}
});
} catch (err) {
if (err instanceof YAML.YAMLException) {
throw new OperationError(err.message);
}
}
}
}
export default YAMLBeautify;

View file

@ -0,0 +1,45 @@
/**
* YamlBeautifier tests.
*
* @author MrMadFox [c.saipraneeth888@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests(
[{
name: "YAML Beautify: basic YAML",
input: "key1: value1\nkey2: value2",
expectedOutput: "key1: value1\nkey2: value2\n",
recipeConfig: [{
"op": "YAML Beautify",
"args": []
}]
}, {
name: "YAML Beautify: nested YAML",
input: "key1:\n subkey1: value1\n subkey2: value2\nkey2: value3",
expectedOutput: "key1:\n subkey1: value1\n subkey2: value2\nkey2: value3\n",
recipeConfig: [{
"op": "YAML Beautify",
"args": []
}]
}, {
name: "YAML Beautify: empty YAML",
input: "",
expectedOutput: "",
recipeConfig: [{
"op": "YAML Beautify",
"args": []
}]
}, {
name: "YAML Beautify: malformed YAML",
input: "key1: value1\nkey2: value2\nkey3",
expectedOutput: "key1: value",
recipeConfig: [{
"op": "YAML Beautify",
"args": []
}]
}
]);