angular-cn/public/docs/_examples/pipes/ts/app/exponential-strength.pipe.ts
2015-12-28 11:54:51 -08:00

19 lines
493 B
TypeScript

// #docregion
import {Pipe, PipeTransform} from 'angular2/core';
/*
* Raise the value exponentially
* Takes an exponent argument that defaults to 1.
* Usage:
* value | exponentialStrength:exponent
* Example:
* {{ 2 | exponentialStrength:10}}
* formats to: 1024
*/
@Pipe({name: 'exponentialStrength'})
export class ExponentialStrengthPipe implements PipeTransform {
transform(value:number, args:string[]) : any {
return Math.pow(value, parseInt(args[0] || '1', 10));
}
}