Skip to content

Commit

Permalink
Merge pull request #20 from zhzy0077/jq
Browse files Browse the repository at this point in the history
Adds JQ support
  • Loading branch information
bee-san authored Dec 21, 2023
2 parents 49fde14 + 721061d commit 3b8f2e6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"geodesy": "1.1.3",
"highlight.js": "^11.7.0",
"jimp": "^0.16.13",
"jq-web": "^0.5.1",
"jquery": "3.6.4",
"js-crc": "^0.2.0",
"js-sha3": "^0.8.0",
Expand Down
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
"CSS Minify",
"XPath expression",
"JPath expression",
"jq",
"CSS selector",
"PHP Deserialize",
"Microsoft Script Decoder",
Expand Down
57 changes: 57 additions & 0 deletions src/core/operations/Jq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @author zhzy0077 [zhzy0077@hotmail.com]
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import jq from "jq-web";

/**
* jq operation
*/
class Jq extends Operation {

/**
* Jq constructor
*/
constructor() {
super();

this.name = "jq";
this.module = "Code";
this.description = "jq is a lightweight and flexible command-line JSON processor.";
this.infoURL = "https://github.com/jqlang/jq";
this.inputType = "JSON";
this.outputType = "string";
this.args = [
{
name: "Query",
type: "string",
value: ""
}
];
}

/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [query] = args;
let result;

try {
result = jq.json(input, query);
} catch (err) {
throw new OperationError(`Invalid jq expression: ${err.message}`);
}

return JSON.stringify(result);
}

}

export default Jq;

0 comments on commit 3b8f2e6

Please sign in to comment.