import qs from 'query-string' ; import { IS_PRODUCTION } from '@frogpond/constants' ; let root ; export function setApiRoot ( url ) { root = url ; } export const API = ( path , query ? ) : string => { if ( ! IS_PRODUCTION ) { if ( ! path . startsWith ( '/' ) ) { throw new Error ( 'invalid path requested from the api!' ) ; } } let url = root + path ; if ( query ) { url += `?${ qs . stringify ( query ) }` ; } return url ; } ;