Ngx-mask: Presenting data

Created on 9 Feb 2018  路  3Comments  路  Source: JsDaddy/ngx-mask

Hello.

Does this package include some sort of helpers to present data? I intend to store data in a raw format and present it with masks to the user, so that would require something like a masks pipe maybe... Is there anything built in? I couldn't find documentation on that.

Thank you!

enhancement help wanted

Most helpful comment

@renanBritz Thank you for question. In my opinion it is good idea to make some pipe . We will add this in next releases

All 3 comments

@renanBritz Thank you for question. In my opinion it is good idea to make some pipe . We will add this in next releases

@NepipenkoIgor @renanBritz
I also wanted this and search around, it was quite easy to do a Mask Pipe. There's not much to do, we only need to replace, there's no validation or anything needed.

Here's my Mask Pipe which will replace any 0, 9, or A (which are the only number or character that I know can be replaced). I'm not sure if you are using S or any other char, you can modify the RegEx pattern if need be

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

@Pipe({
  name: 'mask'
})
export class MaskPipe implements PipeTransform {
  transform(value: string, mask?: string) {
    if (!value || !mask) {
      return value;
    }

    let i = 0;
    const v = value.toString();
    return mask.replace(/[A09]/g, () => v[i++] || '');
  }
}

@NepipenkoIgor
Feel free to use it within your lib, I don't think it has to be any complicate than that.
I took the replace from this SO Question and was amazed how easy that was

@renanBritz @ghiscoding You could try new 6.0.0 version

Was this page helpful?
0 / 5 - 0 ratings