|
@@ -77,7 +77,7 @@ function transformArgs(originalArgs, newArgs) {
|
|
|
* @returns {Function} The operation's run function, wrapped in
|
|
|
* some type conversion logic
|
|
|
*/
|
|
|
-export function wrap(opClass) {
|
|
|
+export function wrap(OpClass) {
|
|
|
/**
|
|
|
* Wrapped operation run function
|
|
|
* @param {*} input
|
|
@@ -86,7 +86,7 @@ export function wrap(opClass) {
|
|
|
* @throws {OperationError} if the operation throws one.
|
|
|
*/
|
|
|
return (input, args=null) => {
|
|
|
- const operation = new opClass();
|
|
|
+ const operation = new OpClass();
|
|
|
|
|
|
let dish;
|
|
|
if (input instanceof SyncDish) {
|
|
@@ -107,6 +107,26 @@ export function wrap(opClass) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/**
|
|
|
+ * SomeName => someName
|
|
|
+ * @param {String} name - string to be altered
|
|
|
+ * @returns {String} decapitalised
|
|
|
+ */
|
|
|
+export function decapitalise(name) {
|
|
|
+ // Don't decapitalise names that start with 2+ caps
|
|
|
+ if (/^[A-Z0-9]{2,}/g.test(name)) {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ // reserved. Don't change for now.
|
|
|
+ if (name === "Return") {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ return `${name.charAt(0).toLowerCase()}${name.substr(1)}`;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Extract properties from an operation by instantiating it and
|
|
|
* returning some of its properties for reference.
|
|
@@ -116,7 +136,7 @@ export function wrap(opClass) {
|
|
|
function extractOperationInfo(Operation) {
|
|
|
const operation = new Operation();
|
|
|
return {
|
|
|
- name: operation.name,
|
|
|
+ name: decapitalise(operation.name).replace(/ /g, ""),
|
|
|
module: operation.module,
|
|
|
description: operation.description,
|
|
|
inputType: operation.inputType,
|
|
@@ -133,37 +153,22 @@ function extractOperationInfo(Operation) {
|
|
|
|
|
|
/**
|
|
|
* @namespace Api
|
|
|
- * @param {Object} operations - an object filled with operations.
|
|
|
+ * @param {Operation[]} operations - an object filled with operations.
|
|
|
* @param {String} searchTerm - the name of the operation to get help for.
|
|
|
* Case and whitespace are ignored in search.
|
|
|
- * @returns {Object} listing properties of function
|
|
|
+ * @returns {Function} taking search term and outputting description.
|
|
|
*/
|
|
|
-export function help(operations, searchTerm) {
|
|
|
- if (typeof searchTerm === "string") {
|
|
|
- const operation = operations[Object.keys(operations).find(o =>
|
|
|
- o.toLowerCase() === searchTerm.replace(/ /g, "").toLowerCase())];
|
|
|
- if (operation) {
|
|
|
- return extractOperationInfo(operation);
|
|
|
+export function help(operations) {
|
|
|
+ return function(searchTerm) {
|
|
|
+ if (typeof searchTerm === "string") {
|
|
|
+ const operation = operations
|
|
|
+ .find(o => o.name.toLowerCase() === searchTerm.replace(/ /g, "").toLowerCase());
|
|
|
+ if (operation) {
|
|
|
+ return extractOperationInfo(operation);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/**
|
|
|
- * SomeName => someName
|
|
|
- * @param {String} name - string to be altered
|
|
|
- * @returns {String} decapitalised
|
|
|
- */
|
|
|
-export function decapitalise(name) {
|
|
|
- // Don't decapitalise names that start with 2+ caps
|
|
|
- if (/^[A-Z0-9]{2,}/g.test(name)) {
|
|
|
- return name;
|
|
|
- }
|
|
|
- // reserved. Don't change for now.
|
|
|
- if (name === "Return") {
|
|
|
- return name;
|
|
|
- }
|
|
|
-
|
|
|
- return `${name.charAt(0).toLowerCase()}${name.substr(1)}`;
|
|
|
-}
|