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]
|
||||
* @copyright Crown Copyright 2016
|
||||
|
@ -4,8 +4,10 @@
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import nwmatcher from "nwmatcher";
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import xmldom from "xmldom";
|
||||
import nwmatcher from "nwmatcher";
|
||||
|
||||
/**
|
||||
* CSS selector operation
|
||||
@ -44,7 +46,7 @@ class CSSSelector extends Operation {
|
||||
*/
|
||||
run(input, args) {
|
||||
const [query, delimiter] = args,
|
||||
parser = new DOMParser();
|
||||
parser = new xmldom.DOMParser();
|
||||
let dom,
|
||||
result;
|
||||
|
||||
@ -55,14 +57,14 @@ class CSSSelector extends Operation {
|
||||
try {
|
||||
dom = parser.parseFromString(input);
|
||||
} catch (err) {
|
||||
return "Invalid input HTML.";
|
||||
throw new OperationError("Invalid input HTML.");
|
||||
}
|
||||
|
||||
try {
|
||||
const matcher = nwmatcher({document: dom});
|
||||
result = matcher.select(query, dom);
|
||||
} catch (err) {
|
||||
return "Invalid CSS Selector. Details:\n" + err.message;
|
||||
throw new OperationError("Invalid CSS Selector. Details:\n" + err.message);
|
||||
}
|
||||
|
||||
const nodeToString = function(node) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import JsDiff from "diff";
|
||||
import * as JsDiff from "diff";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
@ -71,36 +71,39 @@ class Diff extends Operation {
|
||||
let output = "",
|
||||
diff;
|
||||
|
||||
// Node and Webpack load modules slightly differently
|
||||
const jsdiff = JsDiff.default ? JsDiff.default : JsDiff;
|
||||
|
||||
if (!samples || samples.length !== 2) {
|
||||
throw new OperationError("Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?");
|
||||
}
|
||||
|
||||
switch (diffBy) {
|
||||
case "Character":
|
||||
diff = JsDiff.diffChars(samples[0], samples[1]);
|
||||
diff = jsdiff.diffChars(samples[0], samples[1]);
|
||||
break;
|
||||
case "Word":
|
||||
if (ignoreWhitespace) {
|
||||
diff = JsDiff.diffWords(samples[0], samples[1]);
|
||||
diff = jsdiff.diffWords(samples[0], samples[1]);
|
||||
} else {
|
||||
diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
|
||||
diff = jsdiff.diffWordsWithSpace(samples[0], samples[1]);
|
||||
}
|
||||
break;
|
||||
case "Line":
|
||||
if (ignoreWhitespace) {
|
||||
diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
|
||||
diff = jsdiff.diffTrimmedLines(samples[0], samples[1]);
|
||||
} else {
|
||||
diff = JsDiff.diffLines(samples[0], samples[1]);
|
||||
diff = jsdiff.diffLines(samples[0], samples[1]);
|
||||
}
|
||||
break;
|
||||
case "Sentence":
|
||||
diff = JsDiff.diffSentences(samples[0], samples[1]);
|
||||
diff = jsdiff.diffSentences(samples[0], samples[1]);
|
||||
break;
|
||||
case "CSS":
|
||||
diff = JsDiff.diffCss(samples[0], samples[1]);
|
||||
diff = jsdiff.diffCss(samples[0], samples[1]);
|
||||
break;
|
||||
case "JSON":
|
||||
diff = JsDiff.diffJson(samples[0], samples[1]);
|
||||
diff = jsdiff.diffJson(samples[0], samples[1]);
|
||||
break;
|
||||
default:
|
||||
throw new OperationError("Invalid 'Diff by' option.");
|
||||
|
@ -21,7 +21,13 @@ class ExtractEXIF extends Operation {
|
||||
|
||||
this.name = "Extract EXIF";
|
||||
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.outputType = "string";
|
||||
this.args = [];
|
||||
|
@ -20,7 +20,7 @@ class FindReplace extends Operation {
|
||||
|
||||
this.name = "Find / Replace";
|
||||
this.module = "Regex";
|
||||
this.description = "Replaces all occurrences of the first string with the second.<br><br> Includes support for regular expressions (regex), simple strings and extended strings (which support \\n, \\r, \\t, \\b, \\f and escaped hex bytes using \\x notation, e.g. \\x00 for a null byte).";
|
||||
this.description = "Replaces all occurrences of the first string with the second.<br><br>Includes support for regular expressions (regex), simple strings and extended strings (which support \\n, \\r, \\t, \\b, \\f and escaped hex bytes using \\x notation, e.g. \\x00 for a null byte).";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
|
@ -198,8 +198,6 @@ ${extensions}`;
|
||||
|
||||
}
|
||||
|
||||
export default ParseX509Certificate;
|
||||
|
||||
/**
|
||||
* Formats dates.
|
||||
*
|
||||
@ -214,3 +212,5 @@ function formatDate (dateStr) {
|
||||
dateStr[8] + dateStr[9] + ":" +
|
||||
dateStr[10] + dateStr[11];
|
||||
}
|
||||
|
||||
export default ParseX509Certificate;
|
||||
|
@ -7,6 +7,7 @@
|
||||
import XRegExp from "xregexp";
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* Regular expression operation
|
||||
@ -133,14 +134,12 @@ class RegularExpression extends Operation {
|
||||
* @returns {html}
|
||||
*/
|
||||
run(input, args) {
|
||||
const userRegex = args[1],
|
||||
i = args[2],
|
||||
m = args[3],
|
||||
s = args[4],
|
||||
u = args[5],
|
||||
a = args[6],
|
||||
displayTotal = args[7],
|
||||
outputFormat = args[8];
|
||||
const [,
|
||||
userRegex,
|
||||
i, m, s, u, a,
|
||||
displayTotal,
|
||||
outputFormat
|
||||
] = args;
|
||||
let modifiers = "g";
|
||||
|
||||
if (i) modifiers += "i";
|
||||
@ -166,7 +165,7 @@ class RegularExpression extends Operation {
|
||||
return "Error: Invalid output format";
|
||||
}
|
||||
} catch (err) {
|
||||
return "Invalid regex. Details: " + err.message;
|
||||
throw new OperationError("Invalid regex. Details: " + err.message);
|
||||
}
|
||||
} else {
|
||||
return Utils.escapeHtml(input);
|
||||
@ -175,8 +174,6 @@ class RegularExpression extends Operation {
|
||||
|
||||
}
|
||||
|
||||
export default RegularExpression;
|
||||
|
||||
/**
|
||||
* Creates a string listing the matches within a string.
|
||||
*
|
||||
@ -261,3 +258,5 @@ function regexHighlight (input, regex, displayTotal) {
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
export default RegularExpression;
|
||||
|
@ -21,7 +21,11 @@ class RemoveEXIF extends Operation {
|
||||
|
||||
this.name = "Remove EXIF";
|
||||
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.outputType = "byteArray";
|
||||
this.args = [];
|
||||
|
@ -7,6 +7,7 @@
|
||||
import { fromBase64, toBase64 } from "../lib/Base64";
|
||||
import { fromHex } from "../lib/Hex";
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Utils from "../Utils";
|
||||
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)",
|
||||
"flags": "",
|
||||
"args": [
|
||||
"Raw"
|
||||
],
|
||||
"args": ["Raw"],
|
||||
"useful": true
|
||||
}
|
||||
];
|
||||
@ -77,7 +76,7 @@ class RenderImage extends Operation {
|
||||
if (type && type.mime.indexOf("image") === 0) {
|
||||
dataURI += type.mime + ";";
|
||||
} else {
|
||||
throw "Invalid file type";
|
||||
throw new OperationError("Invalid file type");
|
||||
}
|
||||
|
||||
// Add image data to URI
|
||||
|
@ -4,9 +4,10 @@
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import xpath from "xpath";
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import xmldom from "xmldom";
|
||||
import xpath from "xpath";
|
||||
|
||||
/**
|
||||
* XPath expression operation
|
||||
@ -48,7 +49,7 @@ class XPathExpression extends Operation {
|
||||
|
||||
let doc;
|
||||
try {
|
||||
doc = new DOMParser().parseFromString(input, "application/xml");
|
||||
doc = new xmldom.DOMParser().parseFromString(input, "application/xml");
|
||||
} catch (err) {
|
||||
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",
|
||||
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"]
|
||||
}
|
||||
]
|
||||
}*/
|
||||
}
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user