Created
December 13, 2022 19:43
-
-
Save SubZane/e45e087fafc44f3815910d31c2950a2a to your computer and use it in GitHub Desktop.
genericFilterSearch
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
function genericFilterSearch<T>(object: T, properties: Array<keyof T>, query: string): boolean { | |
if (query === '') { | |
return true | |
} | |
return properties.some((property) => { | |
const value = object[property] | |
if (typeof value === 'string' || typeof value === 'number') { | |
return value.toString().toLowerCase().includes(query.toLowerCase()) | |
} | |
return false | |
}) | |
} | |
export default genericFilterSearch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment