2015-08-06 10:39:02 -07:00
|
|
|
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
|
|
|
|
import {Injectable} from 'angular2/di';
|
2015-08-07 11:41:38 -07:00
|
|
|
|
|
|
|
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
|
|
|
|
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
|
|
|
|
|
|
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
2015-05-14 10:14:26 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*/
|
2015-07-22 02:19:16 -07:00
|
|
|
@CONST()
|
2015-08-07 11:41:38 -07:00
|
|
|
@Pipe({name: 'uppercase'})
|
2015-08-06 10:39:02 -07:00
|
|
|
@Injectable()
|
2015-08-07 11:41:38 -07:00
|
|
|
export class UpperCasePipe extends BasePipeTransform {
|
2015-06-26 00:22:06 +04:30
|
|
|
transform(value: string, args: List<any> = null): string {
|
2015-08-06 10:39:02 -07:00
|
|
|
if (isBlank(value)) return value;
|
|
|
|
if (!isString(value)) {
|
|
|
|
throw new InvalidPipeArgumentException(UpperCasePipe, value);
|
|
|
|
}
|
2015-07-22 02:19:16 -07:00
|
|
|
return StringWrapper.toUpperCase(value);
|
2015-05-14 10:14:26 -07:00
|
|
|
}
|
|
|
|
}
|