projects/maplander/shared/src/lib/pipes/string-manipulation/string-manipulation.pipe.ts
Name | stringManipulation |
transform | |||||||||
transform(value: string, type: "lowerCase" | "upperCase" | "capitalize")
|
|||||||||
Parameters :
Returns :
string
|
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'stringManipulation'
})
export class StringManipulationPipe implements PipeTransform {
transform(value: string, type: 'lowerCase' | 'upperCase' | 'capitalize'): string {
if (!value) {
return;
}
value = value.replace(/ /g, '');
switch (type) {
case 'upperCase':
value = value.toUpperCase();
break;
case 'lowerCase':
value = value.toUpperCase();
break;
case 'capitalize':
const fistLetter = value.slice(0, 1);
value = value.replace(fistLetter, '');
value = `${fistLetter.toUpperCase()}${value}`;
break;
}
return value;
}
}