21 lines
807 B
TypeScript
21 lines
807 B
TypeScript
/**
|
||
* Backend uid is int64 from 1_000_000 (7–8 numeric digits).
|
||
* Display always pad to 8 characters: 01000000, 01000001, …
|
||
*/
|
||
export function formatMemberUid(uid: string | number | null | undefined): string {
|
||
if (uid === null || uid === undefined || uid === "") return "";
|
||
const n = typeof uid === "number" ? uid : Number(uid);
|
||
if (!Number.isFinite(n) || n < 0) return String(uid);
|
||
return String(Math.trunc(n)).padStart(8, "0");
|
||
}
|
||
|
||
/** Parse display or raw uid string back to API path/body form (no leading zeros required). */
|
||
export function parseMemberUid(raw: string): string {
|
||
const s = raw.trim();
|
||
if (!s) return "";
|
||
// keep as decimal string without leading zeros for JSON number path
|
||
const n = Number(s);
|
||
if (!Number.isFinite(n)) return s;
|
||
return String(Math.trunc(n));
|
||
}
|