Levenshtein implemented into api
This commit is contained in:
parent
b6e6797f14
commit
71e1d64938
@ -13,6 +13,7 @@ import NodeRecipe from "./NodeRecipe.mjs";
|
|||||||
import OperationConfig from "../core/config/OperationConfig.json";
|
import OperationConfig from "../core/config/OperationConfig.json";
|
||||||
import { sanitise, removeSubheadingsFromArray, sentenceToCamelCase } from "./apiUtils.mjs";
|
import { sanitise, removeSubheadingsFromArray, sentenceToCamelCase } from "./apiUtils.mjs";
|
||||||
import ExcludedOperationError from "../core/errors/ExcludedOperationError.mjs";
|
import ExcludedOperationError from "../core/errors/ExcludedOperationError.mjs";
|
||||||
|
import levenshteinDistance from "../core/lib/Levenshtein.mjs";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,8 +48,13 @@ function transformArgs(opArgsList, newArgs) {
|
|||||||
if (newArgs) {
|
if (newArgs) {
|
||||||
Object.keys(newArgs).map((key) => {
|
Object.keys(newArgs).map((key) => {
|
||||||
const index = opArgs.findIndex((arg) => {
|
const index = opArgs.findIndex((arg) => {
|
||||||
return arg.name.toLowerCase().replace(/ /g, "") ===
|
const argLower = arg.name.toLowerCase();
|
||||||
key.toLowerCase().replace(/ /g, "");
|
const keyLower = key.toLowerCase();
|
||||||
|
|
||||||
|
if (argLower.length === 1 || keyLower === 1)
|
||||||
|
return argLower === keyLower;
|
||||||
|
else
|
||||||
|
return (argLower === keyLower) ? true : levenshteinDistance(argLower.replace(/ /g, ""), keyLower.replace(/ /g, "")) < 2;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user