Add pl-api to workspace

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-08-28 13:43:23 +02:00
parent 966b04fdf0
commit 036fa32cd3
114 changed files with 11923 additions and 1 deletions

View File

@ -0,0 +1,7 @@
/**
* Resolve a type into a flat POJO interface if it's been wrapped by generics.
* https://gleasonator.com/@alex/posts/AWfK4hyppMDCqrT2y8
*/
type Resolve<T> = Pick<T, keyof T>;
export type { Resolve };

View File

@ -0,0 +1,25 @@
import queryString from 'query-string';
// Adapted from Axios https://github.com/axios/axios/blob/v1.x/lib/core/buildFullPath.js
const isAbsoluteURL = (url: string) => /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
const combineURLs = (baseURL: string, relativeURL: string) => relativeURL
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
: baseURL;
const buildFullPath = (requestedURL: string, baseURL?: string, params?: Record<string, any>) => {
const path = (baseURL && !isAbsoluteURL(requestedURL)) ? combineURLs(baseURL, requestedURL) : requestedURL;
if (params && Object.entries(params).length) {
const { url, query } = queryString.parseUrl(path);
return `${url}?${queryString.stringify({ ...query, ...params }, { arrayFormat: 'bracket' })}`;
}
return path;
};
export {
isAbsoluteURL,
combineURLs,
buildFullPath,
};