Angular 5 : Left fill function like PHP str_pad in Angular 5 : Is there a way to replicate PHP str_pad in Angular 5 ?
Not in the template file or via pipe, but from the TS file.

Ex PHP

    <?php
    $str = "Hello World";
    echo str_pad($str,20,".",STR_PAD_LEFT);
    ?>


I created a fn quicky

    my_pad(stringval,length) {
        // Force to fill with zero
        const fill = '0000000000000000000000000';
        return String(fill + stringval).slice(-length);
    }
    this.someservice.newvalue = this.my_pad('234',6);
    // expected this.my_pad('234',6) to return 000234


Is there a smarter way or better way to create this type of function? Or if there is a generic version in Angular ( did not find any so far )

