-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99cd042
commit 0510709
Showing
1 changed file
with
56 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |