From 879faca31a22004e5636813fed8dc7f4df5144f4 Mon Sep 17 00:00:00 2001 From: Maxim Pismenskiy Date: Thu, 7 Jul 2022 17:45:44 +0300 Subject: [PATCH] fix: make masker return same type --- src/main/ts/pipes/masker.ts | 12 +++++++----- src/test/ts/createFrontLogProxyTransmitter.ts | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/ts/pipes/masker.ts b/src/main/ts/pipes/masker.ts index f986d86..cf4d593 100644 --- a/src/main/ts/pipes/masker.ts +++ b/src/main/ts/pipes/masker.ts @@ -5,7 +5,7 @@ import { deepMap } from '../utils/index' const type = 'masker' export const createMaskerPipe = ( - fn: (el: any, key?: string) => string, + fn: (el: any, key?: string) => string | number, ): IPipe => ({ type, async execute({ data }) { @@ -18,10 +18,12 @@ export const createMaskerPipe = ( }, }) -export const panMaskerFn = (input: string | number): string => { - return (input + '').replace(/\d{13,19}/g, (v) => - luhn(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : '' + input, - ) +export const panMaskerFn = (input: string | number): string | number => { + return typeof input === 'number' && input < 9999_9999_9999 + ? input + : (input + '').replace(/\d{13,19}/g, (v) => + luhn(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : '' + input, + ) } export const panMaskerPipe = createMaskerPipe(panMaskerFn) diff --git a/src/test/ts/createFrontLogProxyTransmitter.ts b/src/test/ts/createFrontLogProxyTransmitter.ts index 8de8a4f..4a12a38 100644 --- a/src/test/ts/createFrontLogProxyTransmitter.ts +++ b/src/test/ts/createFrontLogProxyTransmitter.ts @@ -46,7 +46,7 @@ test('createFrontLogProxyTransmitter correctly call fetch with data', async () = appContextId: '', clientId: '', }, - ttl: '14', + ttl: 14, meta: { appVersion: '1.0.0', appName: 'testApp' }, code: '211', tags: ['frontend', 'qiwi'], @@ -87,7 +87,7 @@ test('createFrontLogProxyTransmitter correctly call fetch with Error', async () appContextId: '', clientId: '', }, - ttl: '14', + ttl: 14, meta: { appVersion: '1.0.0', appName: 'testApp' }, code: '211', tags: ['frontend', 'qiwi'],