From 6f5c233f1d760d91ac3cf9dd12526730bb79dead Mon Sep 17 00:00:00 2001 From: SkyZeroZx <73321943+SkyZeroZx@users.noreply.github.com> Date: Sat, 7 Feb 2026 15:14:38 -0500 Subject: [PATCH] refactor(common): extract argument assertion Deduplicates string argument validation logic across pipes by introducing a local assertion helper (cherry picked from commit 66e8385b6ae1bc775b446ae992b90c44f6e78f8d) --- .../common/src/pipes/case_conversion_pipes.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/common/src/pipes/case_conversion_pipes.ts b/packages/common/src/pipes/case_conversion_pipes.ts index 02beaba7dc4..aa38f7add75 100644 --- a/packages/common/src/pipes/case_conversion_pipes.ts +++ b/packages/common/src/pipes/case_conversion_pipes.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.dev/license */ -import {Pipe, PipeTransform} from '@angular/core'; +import {Pipe, PipeTransform, Type} from '@angular/core'; import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; @@ -39,9 +39,7 @@ export class LowerCasePipe implements PipeTransform { transform(value: string | null | undefined): string | null; transform(value: string | null | undefined): string | null { if (value == null) return null; - if (typeof value !== 'string') { - throw invalidPipeArgumentError(LowerCasePipe, value); - } + assertPipeArgument(LowerCasePipe, value); return value.toLowerCase(); } } @@ -89,9 +87,7 @@ export class TitleCasePipe implements PipeTransform { transform(value: string | null | undefined): string | null; transform(value: string | null | undefined): string | null { if (value == null) return null; - if (typeof value !== 'string') { - throw invalidPipeArgumentError(TitleCasePipe, value); - } + assertPipeArgument(TitleCasePipe, value); return value.replace( unicodeWordMatch, @@ -121,9 +117,13 @@ export class UpperCasePipe implements PipeTransform { transform(value: string | null | undefined): string | null; transform(value: string | null | undefined): string | null { if (value == null) return null; - if (typeof value !== 'string') { - throw invalidPipeArgumentError(UpperCasePipe, value); - } + assertPipeArgument(UpperCasePipe, value); return value.toUpperCase(); } } + +function assertPipeArgument(pipe: Type, value: Object): void { + if (typeof value !== 'string') { + throw invalidPipeArgumentError(pipe, value); + } +}