import log from "electron-log" ; import fuzzysearch from "fuzzysearch" ; import { List } from "immutable" ; import path from "path" ; import * as ReactDOM from "react-dom" ; import { HotKeys } from "react-hotkeys" ; import { IDirectoryItem } from "models" ; import { ItemType } from "types" ; /** Provides several static helper functions. */ export default { param component autoFocus ( component ) { ( ReactDOM . findDOMNode ( component ) as HTMLElement ) . focus ( ) ; } , param pathToFind param items param translate returns fuzzySearchItems < T extends Object > ( pathToFind , items , translate = item => item . toString ( ) ) { const itemsCopy = List ( items ) . toArray ( ) ; if ( ! pathToFind || pathToFind . endsWith ( path . sep ) ) { return itemsCopy ; } return itemsCopy . filter ( item => { const searchTermSuffix = path . basename ( pathToFind . toLocaleLowerCase ( ) ) ; const itemSuffix = path . basename ( translate ( item ) ) ; return fuzzysearch ( searchTermSuffix , itemSuffix ) ; } ) ; } , param JSONString returns tryParseJSON ( JSONString ) { try { const obj = JSON . parse ( JSONString ) ; if ( obj && typeof obj === "object" ) { return obj ; } } catch { } return false ; } , param directoryItem returns parseItemType ( directoryItem ) { return directoryItem . isDirectory ? "folder" : "file" ; } , param message trace ( message ) { process . env . VERBOSE && log . verbose ( message ) ; } } ;