2015-06-22 17:11:55 -07:00
|
|
|
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
|
2015-05-14 10:14:26 -07:00
|
|
|
import {Pipe} from './pipe';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements uppercase transforms to text.
|
|
|
|
*
|
|
|
|
* # Example
|
|
|
|
*
|
|
|
|
* In this example we transform the user text uppercase.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component({
|
|
|
|
* selector: "username-cmp"
|
|
|
|
* })
|
|
|
|
* @View({
|
2015-05-18 02:58:13 -07:00
|
|
|
* template: "Username: {{ user | uppercase }}"
|
2015-05-14 10:14:26 -07:00
|
|
|
* })
|
|
|
|
* class Username {
|
2015-05-18 02:58:13 -07:00
|
|
|
* user:string;
|
2015-05-14 10:14:26 -07:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @exportedAs angular2/pipes
|
|
|
|
*/
|
2015-06-18 15:40:12 -07:00
|
|
|
export class UpperCasePipe implements Pipe {
|
2015-06-16 08:47:24 +02:00
|
|
|
_latestValue: string = null;
|
|
|
|
|
2015-05-14 10:14:26 -07:00
|
|
|
supports(str): boolean { return isString(str); }
|
|
|
|
|
|
|
|
onDestroy(): void { this._latestValue = null; }
|
|
|
|
|
|
|
|
transform(value: string): string {
|
|
|
|
if (this._latestValue !== value) {
|
|
|
|
this._latestValue = value;
|
|
|
|
return StringWrapper.toUpperCase(value);
|
|
|
|
} else {
|
|
|
|
return this._latestValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @exportedAs angular2/pipes
|
|
|
|
*/
|
2015-06-22 17:11:55 -07:00
|
|
|
@CONST()
|
2015-05-14 10:14:26 -07:00
|
|
|
export class UpperCaseFactory {
|
|
|
|
supports(str): boolean { return isString(str); }
|
|
|
|
|
|
|
|
create(): Pipe { return new UpperCasePipe(); }
|
|
|
|
}
|