Skip to content

Instantly share code, notes, and snippets.

@lalogrosz
Created August 11, 2017 16:41
Show Gist options
  • Save lalogrosz/e70af5d693c73959a224e2b218a1c044 to your computer and use it in GitHub Desktop.
Save lalogrosz/e70af5d693c73959a224e2b218a1c044 to your computer and use it in GitHub Desktop.
Angular ucwords Pipe
import { Injectable, Pipe } from '@angular/core';
@Pipe({
name: 'ucwords'
})
@Injectable()
export class UcwordsPipe {
/*
Takes a value and makes it lowercase.
*/
transform(val:string) {
val = val.toLowerCase();
return (val + '').replace(/^([a-z])|\s+([a-z])/g, ($1) => {
return $1.toUpperCase();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment