MCPcopy Create free account
hub / github.com/chhoumann/quickadd / normalizeGeneratedFilePathSegment

Function normalizeGeneratedFilePathSegment

src/utils/generatedFilePath.ts:98–124  ·  view source on GitHub ↗
(
	segment: string,
	label: string,
)

Source from the content-addressed store, hash-verified

96}
97
98function normalizeGeneratedFilePathSegment(
99 segment: string,
100 label: string,
101): string {
102 if (segment.length === 0) return segment;
103
104 const startsWithControl =
105 STARTS_WITH_CONTROL_OR_LINE_SEPARATOR.test(segment);
106 const endsWithControl = ENDS_WITH_CONTROL_OR_LINE_SEPARATOR.test(segment);
107 let normalized = collapseControlRunsWithSpaces(segment);
108
109 if (startsWithControl) normalized = normalized.replace(/^ /u, "");
110 if (endsWithControl) normalized = normalized.replace(/ $/u, "");
111
112 const withoutTrailingSpaces = trimTrailingCharsLinear(normalized, " ");
113 if (withoutTrailingSpaces === "." || withoutTrailingSpaces === "..") {
114 throw new Error(`${label} cannot contain "." or ".." path segments.`);
115 }
116
117 normalized = trimTrailingCharsLinear(normalized, ". ");
118
119 if (!normalized) {
120 throw new Error(`${label} contains an empty path segment after formatting.`);
121 }
122
123 return normalized;
124}

Callers 1

Calls 2

trimTrailingCharsLinearFunction · 0.85

Tested by

no test coverage detected