From 5987e2ed7ea0ab6560463828af2439f5a4a3fecd Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sat, 27 Feb 2021 17:45:44 +0100 Subject: [PATCH] Refactor config utils to use functions instead of consts Signed-off-by: David Mehren --- src/config/utils.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/config/utils.ts b/src/config/utils.ts index 2064ce19f..50a695f6e 100644 --- a/src/config/utils.ts +++ b/src/config/utils.ts @@ -4,22 +4,17 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -export const toArrayConfig: ( - configValue: string, - separator?: string, -) => string[] = (configValue: string, separator = ',') => { +export function toArrayConfig(configValue: string, separator = ','): string[] { if (!configValue) { return []; } - if (!configValue.includes(separator)) { return [configValue.trim()]; } - return configValue.split(separator).map((arrayItem) => arrayItem.trim()); -}; +} -export const buildErrorMessage = (errorMessages: string[]): string => { +export function buildErrorMessage(errorMessages: string[]): string { let totalErrorMessage = 'There were some errors with your configuration:'; for (const message of errorMessages) { totalErrorMessage += '\n - '; @@ -28,14 +23,14 @@ export const buildErrorMessage = (errorMessages: string[]): string => { totalErrorMessage += '\nFor further information, have a look at our configuration docs at https://docs.hedgedoc.org/configuration'; return totalErrorMessage; -}; +} -export const replaceAuthErrorsWithEnvironmentVariables = ( +export function replaceAuthErrorsWithEnvironmentVariables( message: string, name: string, replacement: string, arrayOfNames: string[], -): string => { +): string { // this builds a regex like /"gitlab\[(\d+)]\./ to extract the position in the arrayOfNames const regex = new RegExp('"' + name + '\\[(\\d+)]\\.', 'g'); message = message.replace( @@ -91,4 +86,4 @@ export const replaceAuthErrorsWithEnvironmentVariables = ( message = message.replace('.rolesClaim', '_ROLES_CLAIM'); message = message.replace('.accessRole', '_ACCESS_ROLE'); return message; -}; +}