ESM: Tidied up recently added operations
This commit is contained in:
parent
6a561185df
commit
3f3a3e0016
4062
package-lock.json
generated
4062
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Public key functions.
|
* Public key resources.
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright 2016
|
* @copyright Crown Copyright 2016
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import nwmatcher from "nwmatcher";
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
|
import OperationError from "../errors/OperationError";
|
||||||
|
import xmldom from "xmldom";
|
||||||
|
import nwmatcher from "nwmatcher";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CSS selector operation
|
* CSS selector operation
|
||||||
@ -44,7 +46,7 @@ class CSSSelector extends Operation {
|
|||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [query, delimiter] = args,
|
const [query, delimiter] = args,
|
||||||
parser = new DOMParser();
|
parser = new xmldom.DOMParser();
|
||||||
let dom,
|
let dom,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@ -55,14 +57,14 @@ class CSSSelector extends Operation {
|
|||||||
try {
|
try {
|
||||||
dom = parser.parseFromString(input);
|
dom = parser.parseFromString(input);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid input HTML.";
|
throw new OperationError("Invalid input HTML.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const matcher = nwmatcher({document: dom});
|
const matcher = nwmatcher({document: dom});
|
||||||
result = matcher.select(query, dom);
|
result = matcher.select(query, dom);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid CSS Selector. Details:\n" + err.message;
|
throw new OperationError("Invalid CSS Selector. Details:\n" + err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeToString = function(node) {
|
const nodeToString = function(node) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import JsDiff from "diff";
|
import * as JsDiff from "diff";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,36 +71,39 @@ class Diff extends Operation {
|
|||||||
let output = "",
|
let output = "",
|
||||||
diff;
|
diff;
|
||||||
|
|
||||||
|
// Node and Webpack load modules slightly differently
|
||||||
|
const jsdiff = JsDiff.default ? JsDiff.default : JsDiff;
|
||||||
|
|
||||||
if (!samples || samples.length !== 2) {
|
if (!samples || samples.length !== 2) {
|
||||||
throw new OperationError("Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?");
|
throw new OperationError("Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (diffBy) {
|
switch (diffBy) {
|
||||||
case "Character":
|
case "Character":
|
||||||
diff = JsDiff.diffChars(samples[0], samples[1]);
|
diff = jsdiff.diffChars(samples[0], samples[1]);
|
||||||
break;
|
break;
|
||||||
case "Word":
|
case "Word":
|
||||||
if (ignoreWhitespace) {
|
if (ignoreWhitespace) {
|
||||||
diff = JsDiff.diffWords(samples[0], samples[1]);
|
diff = jsdiff.diffWords(samples[0], samples[1]);
|
||||||
} else {
|
} else {
|
||||||
diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
|
diff = jsdiff.diffWordsWithSpace(samples[0], samples[1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Line":
|
case "Line":
|
||||||
if (ignoreWhitespace) {
|
if (ignoreWhitespace) {
|
||||||
diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
|
diff = jsdiff.diffTrimmedLines(samples[0], samples[1]);
|
||||||
} else {
|
} else {
|
||||||
diff = JsDiff.diffLines(samples[0], samples[1]);
|
diff = jsdiff.diffLines(samples[0], samples[1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Sentence":
|
case "Sentence":
|
||||||
diff = JsDiff.diffSentences(samples[0], samples[1]);
|
diff = jsdiff.diffSentences(samples[0], samples[1]);
|
||||||
break;
|
break;
|
||||||
case "CSS":
|
case "CSS":
|
||||||
diff = JsDiff.diffCss(samples[0], samples[1]);
|
diff = jsdiff.diffCss(samples[0], samples[1]);
|
||||||
break;
|
break;
|
||||||
case "JSON":
|
case "JSON":
|
||||||
diff = JsDiff.diffJson(samples[0], samples[1]);
|
diff = jsdiff.diffJson(samples[0], samples[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new OperationError("Invalid 'Diff by' option.");
|
throw new OperationError("Invalid 'Diff by' option.");
|
||||||
|
@ -21,7 +21,13 @@ class ExtractEXIF extends Operation {
|
|||||||
|
|
||||||
this.name = "Extract EXIF";
|
this.name = "Extract EXIF";
|
||||||
this.module = "Image";
|
this.module = "Image";
|
||||||
this.description = "Extracts EXIF data from an image.\n<br><br>\nEXIF data is metadata embedded in images (JPEG, JPG, TIFF) and audio files.\n<br><br>\nEXIF data from photos usually contains information about the image file itself as well as the device used to create it.";
|
this.description = [
|
||||||
|
"Extracts EXIF data from an image.",
|
||||||
|
"<br><br>",
|
||||||
|
"EXIF data is metadata embedded in images (JPEG, JPG, TIFF) and audio files.",
|
||||||
|
"<br><br>",
|
||||||
|
"EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
|
||||||
|
].join("\n");
|
||||||
this.inputType = "ArrayBuffer";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
|
@ -198,8 +198,6 @@ ${extensions}`;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ParseX509Certificate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats dates.
|
* Formats dates.
|
||||||
*
|
*
|
||||||
@ -214,3 +212,5 @@ function formatDate (dateStr) {
|
|||||||
dateStr[8] + dateStr[9] + ":" +
|
dateStr[8] + dateStr[9] + ":" +
|
||||||
dateStr[10] + dateStr[11];
|
dateStr[10] + dateStr[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default ParseX509Certificate;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import XRegExp from "xregexp";
|
import XRegExp from "xregexp";
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
|
import OperationError from "../errors/OperationError";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regular expression operation
|
* Regular expression operation
|
||||||
@ -133,14 +134,12 @@ class RegularExpression extends Operation {
|
|||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const userRegex = args[1],
|
const [,
|
||||||
i = args[2],
|
userRegex,
|
||||||
m = args[3],
|
i, m, s, u, a,
|
||||||
s = args[4],
|
displayTotal,
|
||||||
u = args[5],
|
outputFormat
|
||||||
a = args[6],
|
] = args;
|
||||||
displayTotal = args[7],
|
|
||||||
outputFormat = args[8];
|
|
||||||
let modifiers = "g";
|
let modifiers = "g";
|
||||||
|
|
||||||
if (i) modifiers += "i";
|
if (i) modifiers += "i";
|
||||||
@ -166,7 +165,7 @@ class RegularExpression extends Operation {
|
|||||||
return "Error: Invalid output format";
|
return "Error: Invalid output format";
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid regex. Details: " + err.message;
|
throw new OperationError("Invalid regex. Details: " + err.message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Utils.escapeHtml(input);
|
return Utils.escapeHtml(input);
|
||||||
@ -175,8 +174,6 @@ class RegularExpression extends Operation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RegularExpression;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a string listing the matches within a string.
|
* Creates a string listing the matches within a string.
|
||||||
*
|
*
|
||||||
@ -261,3 +258,5 @@ function regexHighlight (input, regex, displayTotal) {
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default RegularExpression;
|
||||||
|
@ -21,7 +21,11 @@ class RemoveEXIF extends Operation {
|
|||||||
|
|
||||||
this.name = "Remove EXIF";
|
this.name = "Remove EXIF";
|
||||||
this.module = "Image";
|
this.module = "Image";
|
||||||
this.description = "Removes EXIF data from a JPEG image.\n<br><br>\nEXIF data embedded in photos usually contains information about the image file itself as well as the device used to create it.";
|
this.description = [
|
||||||
|
"Removes EXIF data from a JPEG image.",
|
||||||
|
"<br><br>",
|
||||||
|
"EXIF data embedded in photos usually contains information about the image file itself as well as the device used to create it.",
|
||||||
|
].join("\n");
|
||||||
this.inputType = "byteArray";
|
this.inputType = "byteArray";
|
||||||
this.outputType = "byteArray";
|
this.outputType = "byteArray";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import { fromBase64, toBase64 } from "../lib/Base64";
|
import { fromBase64, toBase64 } from "../lib/Base64";
|
||||||
import { fromHex } from "../lib/Hex";
|
import { fromHex } from "../lib/Hex";
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
|
import OperationError from "../errors/OperationError";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import Magic from "../lib/Magic";
|
import Magic from "../lib/Magic";
|
||||||
|
|
||||||
@ -37,9 +38,7 @@ class RenderImage extends Operation {
|
|||||||
{
|
{
|
||||||
"match": "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)",
|
"match": "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)",
|
||||||
"flags": "",
|
"flags": "",
|
||||||
"args": [
|
"args": ["Raw"],
|
||||||
"Raw"
|
|
||||||
],
|
|
||||||
"useful": true
|
"useful": true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -77,7 +76,7 @@ class RenderImage extends Operation {
|
|||||||
if (type && type.mime.indexOf("image") === 0) {
|
if (type && type.mime.indexOf("image") === 0) {
|
||||||
dataURI += type.mime + ";";
|
dataURI += type.mime + ";";
|
||||||
} else {
|
} else {
|
||||||
throw "Invalid file type";
|
throw new OperationError("Invalid file type");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add image data to URI
|
// Add image data to URI
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import xpath from "xpath";
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
|
import xmldom from "xmldom";
|
||||||
|
import xpath from "xpath";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XPath expression operation
|
* XPath expression operation
|
||||||
@ -48,7 +49,7 @@ class XPathExpression extends Operation {
|
|||||||
|
|
||||||
let doc;
|
let doc;
|
||||||
try {
|
try {
|
||||||
doc = new DOMParser().parseFromString(input, "application/xml");
|
doc = new xmldom.DOMParser().parseFromString(input, "application/xml");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError("Invalid input XML.");
|
throw new OperationError("Invalid input XML.");
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,6 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
/* Since we don't pack ops before running tests, there's no polyfill for DomParser()
|
|
||||||
{
|
{
|
||||||
name: "CSS selector",
|
name: "CSS selector",
|
||||||
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',
|
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',
|
||||||
@ -332,5 +331,5 @@ TestRegister.addTests([
|
|||||||
"args": ["/div/p[@class=\"a\"]", "\\n"]
|
"args": ["/div/p[@class=\"a\"]", "\\n"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}*/
|
}
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user