File size: 446 Bytes
7d94330
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""Shared utilities for ResearchBee backend."""
from typing import Optional


def norm_issn(raw: str | None) -> Optional[str]:
    """
    Normalise any ISSN-like string to XXXX-XXXX format.
    Returns None if input is absent or not 8 digits after stripping.
    """
    if not raw:
        return None
    digits = str(raw).strip().upper().replace(" ", "").replace("-", "")
    return f"{digits[:4]}-{digits[4:]}" if len(digits) == 8 else None