<commit_before>import qs from 'query-string'

import {IS_PRODUCTION} from '@frogpond/constants'

let root: string

export function setApiRoot(url: string): void {
	root = url
}

export const API = (path: string, query?: Record<string, any>): 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
}<commit_msg>ensure that paths passed to API start with /<commit_after>import qs from 'query-string'

import {IS_PRODUCTION} from '@frogpond/constants'

let root: string

export function setApiRoot(url: string): void {
	root = url
}

export const API = (path: `/${string}`, query?: Record<string, any>): string => {
	let url = root + path

	if (query) {
		url += `?${qs.stringify(query)}`
	}

	return url
}
{'fraction_non_alphanumeric': 0.15172413793103448, 'fraction_numerical': 0.0, 'mean_word_length': 4.2155688622754495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '73445', 'n_tokens_mistral': 311, 'n_tokens_neox': 301, 'n_words': 94}