f0cff27e99
* setup typescript * covert to TypeScript
19 lines
554 B
TypeScript
19 lines
554 B
TypeScript
const baseUrl = window.location.pathname
|
|
// remove index.html if it's there
|
|
.replace(/index.html$/, '')
|
|
// remove tests prefix which is added by testem (starting with a number)
|
|
.replace(/\/\d+\/tests/, '')
|
|
// remove tests prefix which is added by tests run in browser
|
|
.replace(/tests/, '')
|
|
// remove leading and trailing slash
|
|
.replace(/\/$/, '')
|
|
// add api/index.php
|
|
.concat('/api/index.php');
|
|
|
|
function apiUrl(path: string) {
|
|
return `${baseUrl}/${path}`;
|
|
}
|
|
|
|
class NotFoundError extends Error {}
|
|
|
|
export { apiUrl, NotFoundError };
|