Files
Angular-Docs-Cn/modules/@angular/common/src/pipes/uppercase_pipe.ts
T

37 lines
998 B
TypeScript
Raw Normal View History

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
2016-06-08 16:38:52 -07:00
import {Pipe, PipeTransform} from '@angular/core';
2016-09-11 00:27:56 -07:00
import {isBlank} from '../facade/lang';
import {InvalidPipeArgumentError} from './invalid_pipe_argument_error';
/**
2016-09-08 21:41:09 -07:00
* @ngModule CommonModule
* @whatItDoes Transforms string to uppercase.
* @howToUse `expression | uppercase`
* @description
*
2016-10-31 12:39:21 +01:00
* Converts value into an uppercase string using `String.prototype.toUpperCase()`.
*
* ### Example
*
2016-09-08 21:41:09 -07:00
* {@example common/pipes/ts/lowerupper_pipe.ts region='LowerUpperPipe'}
*
* @stable
*/
@Pipe({name: 'uppercase'})
2015-08-12 12:04:54 -07:00
export class UpperCasePipe implements PipeTransform {
transform(value: string): string {
if (isBlank(value)) return value;
2016-09-11 00:27:56 -07:00
if (typeof value !== 'string') {
throw new InvalidPipeArgumentError(UpperCasePipe, value);
}
return value.toUpperCase();
}
}