Skip to content

Instantly share code, notes, and snippets.

@sunnyg1210
Created February 6, 2020 16:27
Show Gist options
  • Save sunnyg1210/bb9fc144142b0353f8db8a2ec4c30eca to your computer and use it in GitHub Desktop.
Save sunnyg1210/bb9fc144142b0353f8db8a2ec4c30eca to your computer and use it in GitHub Desktop.
Takes Camelcase string and splits it into a separated word string in Angular
import { Pipe, PipeTransform } from '@angular/core';
/*
* Author: SVS IT Solutions LTD (www.svsitsolutions.co.uk)
* Takes Camelcase string and splits it into a separated word string.
* Usage:
* camelCaseString | camelCaseSplit
* Example:
* {{ "thisIsAString" | camelCaseSplit}}
* formats to: "this Is A String"
*/
@Pipe({ name: 'camelCaseSplit' })
export class CamelCasePipe implements PipeTransform {
transform(camelCase: string): string {
let ccSplit = camelCase.split(/(?=[A-Z])/).join(" ")
return ccSplit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment