Skip to content

Instantly share code, notes, and snippets.

@SubZane
Created December 13, 2022 19:43
Show Gist options
  • Save SubZane/e45e087fafc44f3815910d31c2950a2a to your computer and use it in GitHub Desktop.
Save SubZane/e45e087fafc44f3815910d31c2950a2a to your computer and use it in GitHub Desktop.
genericFilterSearch
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