Skip to content

Instantly share code, notes, and snippets.

@skflowne
Created August 4, 2020 22:22
Show Gist options
  • Save skflowne/ed26814eec3623395f519e82d7d87b92 to your computer and use it in GitHub Desktop.
Save skflowne/ed26814eec3623395f519e82d7d87b92 to your computer and use it in GitHub Desktop.
import { derived } from "svelte/store"
import fileSearch from "./fileSearch"
import files from "./files"
const results = derived([fileSearch, files], ([$fileSearch, $files]) => {
const isSearchEmpty = $fileSearch.trim().length === 0
const allFiles = $files.filter((t) => t.type === "file")
if (isSearchEmpty) {
return allFiles
} else {
return allFiles.filter((f) => {
const filename = f.name.toLocaleLowerCase()
const search = $fileSearch.toLocaleLowerCase()
return filename.includes(search)
})
}
})
export default results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment