Skip to content

Commit

Permalink
Update: Deprecate fuzzySearch
Browse files Browse the repository at this point in the history
  • Loading branch information
dhershman1 committed Oct 13, 2024
1 parent 99cd042 commit 0510709
Showing 1 changed file with 56 additions and 55 deletions.
111 changes: 56 additions & 55 deletions src/string/fuzzySearch.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import _curry2 from '../_internals/_curry2.js'

/* eslint-disable no-labels */

/**
* @name fuzzySearch
* @function
* @since v0.1.0
* @sig a -> Boolean
* @category String
* @description Fuzzy search setup to look find things fast, effective, and probably the most out of place function here. But it works well so it's hard to get rid of
* @param {String} needle The Item to search
* @param {String} haystack The value to search for
* @return {Boolean} Returns a boolean determined by if the value is found or not by the search
*
* @example
* import { fuzzySearch } from 'kyanite'
*
* fuzzySearch('te', 'test') // => true
* fuzzySearch('dog', 'testing') // => false
*
* // search is also curried
*
* const search = fuzzySearch('te')
* search('test') // => true
*/
const fuzzySearch = (needle, haystack) => {
const hLen = haystack.length
const nLen = needle.length
let j = 0

if (nLen > hLen) {
return false
}

if (nLen === hLen) {
return needle === haystack
}

outer: for (let i = 0; i < nLen; i++) {
const nChar = needle.charCodeAt(i)

for (j; j < hLen; j++) {
if (haystack.charCodeAt(j) === nChar) {
continue outer
}
}

return false
}

return true
}

export default _curry2(fuzzySearch)
import _curry2 from '../_internals/_curry2.js'

/* eslint-disable no-labels */

/**
* @name fuzzySearch
* @deprecated since v3.2.0
* @function
* @since v0.1.0
* @sig a -> Boolean
* @category String
* @description Fuzzy search setup to look find things fast, effective, and probably the most out of place function here. But it works well so it's hard to get rid of
* @param {String} needle The Item to search
* @param {String} haystack The value to search for
* @return {Boolean} Returns a boolean determined by if the value is found or not by the search
*
* @example
* import { fuzzySearch } from 'kyanite'
*
* fuzzySearch('te', 'test') // => true
* fuzzySearch('dog', 'testing') // => false
*
* // search is also curried
*
* const search = fuzzySearch('te')
* search('test') // => true
*/
const fuzzySearch = (needle, haystack) => {
const hLen = haystack.length
const nLen = needle.length
let j = 0

if (nLen > hLen) {
return false
}

if (nLen === hLen) {
return needle === haystack
}

outer: for (let i = 0; i < nLen; i++) {
const nChar = needle.charCodeAt(i)

for (j; j < hLen; j++) {
if (haystack.charCodeAt(j) === nChar) {
continue outer
}
}

return false
}

return true
}

export default _curry2(fuzzySearch)

0 comments on commit 0510709

Please sign in to comment.