From d2da11c79a59412b3ae480a5c2e05ff4421bd113 Mon Sep 17 00:00:00 2001 From: zhzy0077 Date: Tue, 25 Jul 2023 14:42:43 +0800 Subject: [PATCH 1/6] Support jq. --- package-lock.json | 11 +++++++ package.json | 1 + src/core/config/Categories.json | 1 + src/core/operations/Jq.mjs | 57 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/core/operations/Jq.mjs diff --git a/package-lock.json b/package-lock.json index 3cccfa6c..a53ba37e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,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", @@ -8662,6 +8663,11 @@ "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.4.tgz", "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==" }, + "node_modules/jq-web": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.5.1.tgz", + "integrity": "sha512-3Fa3E6g3U1O1j46ljy0EM10yRr4txzILga8J7bqOG8F89gZ6Lilz82WG9z6TItWpYEO0YGa4W8yFGj+NMM1xqQ==" + }, "node_modules/jquery": { "version": "3.6.4", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz", @@ -19681,6 +19687,11 @@ "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.4.tgz", "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==" }, + "jq-web": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.5.1.tgz", + "integrity": "sha512-3Fa3E6g3U1O1j46ljy0EM10yRr4txzILga8J7bqOG8F89gZ6Lilz82WG9z6TItWpYEO0YGa4W8yFGj+NMM1xqQ==" + }, "jquery": { "version": "3.6.4", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz", diff --git a/package.json b/package.json index 45328dd1..7bb14e9b 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,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", diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index cf4d91be..3cf600fd 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -422,6 +422,7 @@ "CSS Minify", "XPath expression", "JPath expression", + "Jq", "CSS selector", "PHP Deserialize", "Microsoft Script Decoder", diff --git a/src/core/operations/Jq.mjs b/src/core/operations/Jq.mjs new file mode 100644 index 00000000..38aa5abb --- /dev/null +++ b/src/core/operations/Jq.mjs @@ -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; From 721061d0548a4b9cc9e1d48aa9043ce5c38e8ef2 Mon Sep 17 00:00:00 2001 From: zhzy0077 Date: Tue, 25 Jul 2023 14:48:03 +0800 Subject: [PATCH 2/6] fix typo. --- src/core/config/Categories.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 3cf600fd..9283fe65 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -422,7 +422,7 @@ "CSS Minify", "XPath expression", "JPath expression", - "Jq", + "jq", "CSS selector", "PHP Deserialize", "Microsoft Script Decoder", From a74e2e585eba835439105d0e7918de530d895342 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Mon, 17 Feb 2025 13:49:17 +0800 Subject: [PATCH 3/6] add lock. --- package-lock.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index 50639ea8..e4fb240d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,7 @@ "highlight.js": "^11.9.0", "ieee754": "^1.2.1", "jimp": "^0.22.12", + "jq-web": "^0.6.1", "jquery": "3.7.1", "js-crc": "^0.2.0", "js-sha3": "^0.9.3", @@ -12290,6 +12291,12 @@ "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==", "license": "BSD-3-Clause" }, + "node_modules/jq-web": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.6.1.tgz", + "integrity": "sha512-7qZb0KP0Xd3OSRcEtdR8nI0h1pN7RQQRhL8UXM/Hq0zh/ZFAIncFkRcctNjKHlvHLZ29fMNxR9j+pRVJ1SKAcA==", + "license": "ISC" + }, "node_modules/jquery": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", From 95044ab767ce35d75152dc231ce3a8765016087b Mon Sep 17 00:00:00 2001 From: zhzy0077 Date: Wed, 12 Mar 2025 20:15:00 +0800 Subject: [PATCH 4/6] Making it depending on 0.5.1 version. --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4fb240d..e731efff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "highlight.js": "^11.9.0", "ieee754": "^1.2.1", "jimp": "^0.22.12", - "jq-web": "^0.6.1", + "jq-web": "^0.5.1", "jquery": "3.7.1", "js-crc": "^0.2.0", "js-sha3": "^0.9.3", @@ -12292,9 +12292,9 @@ "license": "BSD-3-Clause" }, "node_modules/jq-web": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.6.1.tgz", - "integrity": "sha512-7qZb0KP0Xd3OSRcEtdR8nI0h1pN7RQQRhL8UXM/Hq0zh/ZFAIncFkRcctNjKHlvHLZ29fMNxR9j+pRVJ1SKAcA==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/jq-web/-/jq-web-0.5.1.tgz", + "integrity": "sha512-3Fa3E6g3U1O1j46ljy0EM10yRr4txzILga8J7bqOG8F89gZ6Lilz82WG9z6TItWpYEO0YGa4W8yFGj+NMM1xqQ==", "license": "ISC" }, "node_modules/jquery": { diff --git a/package.json b/package.json index 24b3a653..3785508e 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "highlight.js": "^11.9.0", "ieee754": "^1.2.1", "jimp": "^0.22.12", - "jq-web": "^0.6.1", + "jq-web": "^0.5.1", "jquery": "3.7.1", "js-crc": "^0.2.0", "js-sha3": "^0.9.3", From 464c92e7bfc6259dc9653f5afdc66255f09f276f Mon Sep 17 00:00:00 2001 From: zhzy0077 Date: Wed, 12 Mar 2025 20:15:09 +0800 Subject: [PATCH 5/6] Rename to "Jq" --- src/core/config/Categories.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index b31083c5..2ea73f3b 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -465,7 +465,7 @@ "CSS Minify", "XPath expression", "JPath expression", - "jq", + "Jq", "CSS selector", "PHP Deserialize", "Microsoft Script Decoder", From b62def3d3e1bcae03729245813e9929d4243345c Mon Sep 17 00:00:00 2001 From: zhzy0077 Date: Wed, 12 Mar 2025 20:15:23 +0800 Subject: [PATCH 6/6] making it a seperate module. --- src/core/operations/Jq.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/Jq.mjs b/src/core/operations/Jq.mjs index 38aa5abb..c1e02b34 100644 --- a/src/core/operations/Jq.mjs +++ b/src/core/operations/Jq.mjs @@ -19,8 +19,8 @@ class Jq extends Operation { constructor() { super(); - this.name = "jq"; - this.module = "Code"; + this.name = "Jq"; + this.module = "Jq"; this.description = "jq is a lightweight and flexible command-line JSON processor."; this.infoURL = "https://github.com/jqlang/jq"; this.inputType = "JSON";