string-find-malformed
Search for a malformed string. Think of Levenshtein distance but in search.
Install
npm i string-find-malformed
Quick Take
import { strict as assert } from "assert";
import strFindMalformed from "string-find-malformed";
// Below, we look for dodgy cases of `<!--`
const gathered = [];
strFindMalformed(
"<div><!-something--></div>",
"<!--",
// your callback function:
(obj) => {
gathered.push(obj);
},
{
maxDistance: 1, // Levenshtein distance
}
);
assert.deepEqual(gathered, [
{
idxFrom: 5,
idxTo: 8,
},
]);
Documentation
Please visit codsen.com for a full description of the API and examples.
Licence
MIT License
Copyright (c) 2010-2020 Roy Revelt and other contributors