2019-10-15 17:08:16 +07:00
|
|
|
import { PackageMetaInterface } from '../../types/packageMeta';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-08 03:19:18 +07:00
|
|
|
import API from './api';
|
|
|
|
|
2019-10-11 03:20:05 +07:00
|
|
|
export async function callReadme(packageName: string, packageVersion?: string): Promise<string | {}> {
|
2019-09-01 18:09:23 +07:00
|
|
|
return await API.request<string | {}>(`package/readme/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
|
2019-06-20 19:37:28 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
export async function callDetailPage(packageName: string, packageVersion?: string): Promise<PackageMetaInterface | {}> {
|
|
|
|
const packageMeta = await API.request<PackageMetaInterface | {}>(`sidebar/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
return packageMeta;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
2019-08-25 22:39:15 +07:00
|
|
|
|
2019-10-23 03:31:39 +07:00
|
|
|
export function callSearch(value: string, signal: AbortSignal) {
|
2019-08-25 22:39:15 +07:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility
|
|
|
|
// FUTURE: signal is not well supported for IE and Samsung Browser
|
|
|
|
return API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal, headers: {} });
|
|
|
|
}
|