UNPKG

levenshtein-search

Version:

A Javascript library for fuzzy substring searches.

28 lines (23 loc) 516 B
function * searchExact (needle, haystack, startIndex = 0, endIndex = null) { const needleLen = needle.length if (needleLen === 0) return if (endIndex === null) { endIndex = haystack.length } let index while ((index = haystack.indexOf(needle, startIndex)) > -1) { if (index + needle.length > endIndex) break yield index startIndex = index + 1 } } function reverse (string) { return string .split('') .reverse() .join('') } module.exports = { searchExact, reverse }