ng2-pipes
Version:
Useful angular2 pipes
17 lines (14 loc) • 442 B
text/typescript
import { PipeTransform, Pipe } from '@angular/core';
import GeneralHelper from '../helpers/helpers';
export class LeftPadPipe implements PipeTransform {
transform(str: string, length: number, padCharacter: string = ' '): string {
if (!GeneralHelper.isString(str) || str.length >= length) {
return str;
}
while (str.length < length) {
str = padCharacter + str;
}
return str;
}
}