2015-08-20 14:28:25 -07:00
|
|
|
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/core/facade/lang';
|
2015-09-03 22:01:36 -07:00
|
|
|
import {Injectable} from 'angular2/src/core/di';
|
|
|
|
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
|
|
|
|
import {Pipe} from 'angular2/src/core/metadata';
|
2015-08-07 11:41:38 -07:00
|
|
|
|
|
|
|
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
|
|
|
|
2015-05-14 10:14:26 -07:00
|
|
|
/**
|
|
|
|
* Implements lowercase transforms to text.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-05-14 10:14:26 -07:00
|
|
|
*
|
|
|
|
* In this example we transform the user text lowercase.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component({
|
2015-10-11 07:41:19 -07:00
|
|
|
* selector: "username-cmp",
|
2015-05-18 02:58:13 -07:00
|
|
|
* template: "Username: {{ user | lowercase }}"
|
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: 'lowercase'})
|
2015-08-06 10:39:02 -07:00
|
|
|
@Injectable()
|
2015-08-12 12:04:54 -07:00
|
|
|
export class LowerCasePipe implements PipeTransform {
|
2015-08-28 11:29:19 -07:00
|
|
|
transform(value: string, args: any[] = null): string {
|
2015-08-06 10:39:02 -07:00
|
|
|
if (isBlank(value)) return value;
|
|
|
|
if (!isString(value)) {
|
|
|
|
throw new InvalidPipeArgumentException(LowerCasePipe, value);
|
|
|
|
}
|
2015-07-22 02:19:16 -07:00
|
|
|
return StringWrapper.toLowerCase(value);
|
2015-05-14 10:14:26 -07:00
|
|
|
}
|
|
|
|
}
|