File

projects/maplander/shared/src/lib/pipes/string-manipulation/string-manipulation.pipe.ts

Metadata

Name stringManipulation

Methods

transform
transform(value: string, type: "lowerCase" | "upperCase" | "capitalize")
Parameters :
Name Type Optional
value string No
type "lowerCase" | "upperCase" | "capitalize" No
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;
  }

}

result-matching ""

    No results matching ""