import tlds from "tlds" ; import { engines } from "./engines" ; export function buildUrl ( query , engineUrl ) { if ( /^https?:\/\/\w+/ . test ( query ) ) { return query ; } if ( tlds . some ( ( tld ) => query . endsWith ( `.${ tld }` ) ) ) { return `https://${ query }` ; } return engineUrl . replace ( "{searchTerms}" , encodeURIComponent ( query ) ) ; } export function getSearchUrl ( key ) { const engine = engines . find ( ( engine ) => engine . key === key ) ; return ( engine || engines [ 0 ] ) . search_url ; } export function getSuggestUrl ( key ? ) { const engine = engines . find ( ( engine ) => engine . key === key ) ; return engine ? engine . suggest_url : undefined ; }