refactor: Use declarations style for functions.

This commit is contained in:
Ruben Verborgh
2021-01-06 11:24:43 +01:00
parent e70e060225
commit f9a20799eb
23 changed files with 208 additions and 162 deletions

View File

@@ -14,8 +14,9 @@ const logger = getLoggerFor('MapperUtil');
*
* @returns Absolute path of the file.
*/
export const getAbsolutePath = (rootFilepath: string, path: string, identifier = ''): string =>
joinFilePath(rootFilepath, path, identifier);
export function getAbsolutePath(rootFilepath: string, path: string, identifier = ''): string {
return joinFilePath(rootFilepath, path, identifier);
}
/**
* Strips the baseRequestURI from the identifier and checks if the stripped base URI matches the store's one.
@@ -27,13 +28,13 @@ export const getAbsolutePath = (rootFilepath: string, path: string, identifier =
*
* @returns A string representing the relative path.
*/
export const getRelativePath = (baseRequestURI: string, identifier: ResourceIdentifier): string => {
export function getRelativePath(baseRequestURI: string, identifier: ResourceIdentifier): string {
if (!identifier.path.startsWith(baseRequestURI)) {
logger.warn(`The URL ${identifier.path} is outside of the scope ${baseRequestURI}`);
throw new NotFoundHttpError();
}
return decodeUriPathComponents(identifier.path.slice(baseRequestURI.length));
};
}
/**
* Check if the given relative path is valid.
@@ -44,7 +45,7 @@ export const getRelativePath = (baseRequestURI: string, identifier: ResourceIden
* @param path - A relative path, as generated by {@link getRelativePath}.
* @param identifier - A resource identifier.
*/
export const validateRelativePath = (path: string, identifier: ResourceIdentifier): void => {
export function validateRelativePath(path: string, identifier: ResourceIdentifier): void {
if (!path.startsWith('/')) {
logger.warn(`URL ${identifier.path} needs a / after the base`);
throw new BadRequestHttpError('URL needs a / after the base');
@@ -54,4 +55,4 @@ export const validateRelativePath = (path: string, identifier: ResourceIdentifie
logger.warn(`Disallowed /.. segment in URL ${identifier.path}.`);
throw new BadRequestHttpError('Disallowed /.. segment in URL');
}
};
}