aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/numberedFixLen.pipe.ts
blob: 9d26b16fa12445fdb2728ef4c4ee908243a10120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
 * numberFixedLen.pipe
 */

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'numberFixedLen'
})
export class NumberFixedLenPipe implements PipeTransform {
    transform(num: number, len: number): any {
        let numberInt = Math.floor(num);
        let length = Math.floor(len);

        if (num === null || isNaN(numberInt) || isNaN(length)) {
            return num;
        }

        let numString = numberInt.toString();

        while (numString.length < length) {
            numString = '0' + numString;
        }

        return numString;
    }
}