13 lines
487 B
TypeScript
13 lines
487 B
TypeScript
export function formatCardNumber(raw: string): string {
|
|||
|
|
const digits = raw.replace(/\D/g, '')
|
||
|
|
return digits.replace(/(\d{4})(?=\d)/g, '$1 ').trim()
|
||
|
|
}
|
||
|
|
|
||
|
|
export function formatSheba(raw: string): string {
|
||
|
|
const compact = raw.replace(/[\s-]/g, '').toUpperCase()
|
||
|
|
const body = compact.startsWith('IR') ? compact.slice(2) : compact
|
||
|
|
if (body.length < 2) return compact
|
||
|
|
const groups = body.slice(2).replace(/(.{4})/g, '$1 ').trim()
|
||
|
|
return `IR${body.slice(0, 2)} ${groups}`.trim()
|
||
|
|
}
|