Skip to content

Commit

Permalink
fix: make masker return same type
Browse files Browse the repository at this point in the history
  • Loading branch information
pismenskiy authored Jul 7, 2022
1 parent 6c9a0fc commit 879faca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/main/ts/pipes/masker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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)
4 changes: 2 additions & 2 deletions src/test/ts/createFrontLogProxyTransmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 879faca

Please sign in to comment.