From bc5e687250c95f0f95becdf6c0760558ee1bb4b5 Mon Sep 17 00:00:00 2001 From: Cole Lawrence Date: Tue, 17 May 2022 13:39:04 -0400 Subject: [PATCH] docs: slashPaths normalizeSlashedPath --- theatre/shared/src/utils/slashedPaths.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/theatre/shared/src/utils/slashedPaths.ts b/theatre/shared/src/utils/slashedPaths.ts index 42c4d37..0e40675 100644 --- a/theatre/shared/src/utils/slashedPaths.ts +++ b/theatre/shared/src/utils/slashedPaths.ts @@ -1,11 +1,19 @@ import logger from '@theatre/shared/logger' import {InvalidArgumentError} from './errors' -const sanifySlashedPath = (p: string): string => +/** + * Make the given string's "path" slashes normalized with preceding and trailing spaces. + * + * Prev "sanifySlashedPath". + */ +const normalizeSlashedPath = (p: string): string => p + // remove starting slashes .replace(/^[\s\/]*/, '') + // remove ending slashes .replace(/[\s\/]*$/, '') - .replace(/\s*\/\s*/, ' / ') + // make middle slashes consistent + .replace(/\s*\/\s*/g, ' / ') const getValidationErrorsOfSlashedPath = (p: string): void | string => { if (typeof p !== 'string') return `it is not a string. (it is a ${typeof p})` @@ -25,7 +33,7 @@ export function validateAndSanitiseSlashedPathOrThrow( unsanitisedPath: string, fnName: string, ) { - const sanitisedPath = sanifySlashedPath(unsanitisedPath) + const sanitisedPath = normalizeSlashedPath(unsanitisedPath) if (process.env.NODE_ENV !== 'development') { return sanitisedPath }