Added Magic operation with the ability to detect language, file type and some encoding types.

This commit is contained in:
n1474335 2018-01-14 16:07:39 +00:00
parent aa6890432c
commit fc2828fee3
7 changed files with 273 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import Recipe from "./Recipe.js";
import Dish from "./Dish.js";
import Magic from "./lib/Magic.js";
/**
@ -253,6 +254,29 @@ const FlowControl = {
},
/**
* Magic operation.
*
* @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on.
* @param {Operation[]} state.opList - The list of operations in the recipe.
* @returns {Object} The updated state of the recipe.
*/
runMagic: function(state) {
const dish = state.dish;
const magic = new Magic(dish.get(Dish.ARRAY_BUFFER));
const output = JSON.stringify(magic.detectLanguage(), null, 2) + "\n\n" +
JSON.stringify(magic.detectFileType(), null, 2) + "\n\n" +
JSON.stringify(magic.findMatchingOps(), null, 2);
dish.set(output, Dish.STRING);
return state;
},
/**
* Returns the index of a label.
*