bigbuffet-rw/app/soapbox/entity-store/hooks/utils.ts

27 lines
660 B
TypeScript
Raw Normal View History

import type { EntitiesPath, EntityRequest, ExpandedEntitiesPath } from './types';
import type { AxiosRequestConfig } from 'axios';
2023-03-22 14:12:05 -07:00
function parseEntitiesPath(expandedPath: ExpandedEntitiesPath) {
const [entityType, ...listKeys] = expandedPath;
const listKey = (listKeys || []).join(':');
2023-03-22 14:12:05 -07:00
const path: EntitiesPath = [entityType, listKey];
return {
entityType,
listKey,
path,
};
}
function toAxiosRequest(req: EntityRequest): AxiosRequestConfig {
if (typeof req === 'string' || req instanceof URL) {
return {
method: 'get',
url: req.toString(),
};
}
return req;
}
export { parseEntitiesPath, toAxiosRequest };