feat(code): add parseCodeNumber helper to lib/code.ts
Pure helper that extracts the trailing numeric sequence from a code string (ST-007 → 7, T-42 → 42). Non-conforming codes fall back to Number.MAX_SAFE_INTEGER so they sort to the end. Includes 5 unit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7bb252c528
commit
9d3235bcd8
2 changed files with 35 additions and 0 deletions
10
lib/code.ts
10
lib/code.ts
|
|
@ -14,3 +14,13 @@ export function normalizeCode(input: string | null | undefined): string | null {
|
|||
const trimmed = input.trim()
|
||||
return trimmed === '' ? null : trimmed
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the trailing numeric sequence from a code (e.g. "ST-007" → 7, "T-42" → 42).
|
||||
* Non-conforming codes (no trailing digits, empty string) return Number.MAX_SAFE_INTEGER
|
||||
* so they sort to the end.
|
||||
*/
|
||||
export function parseCodeNumber(code: string): number {
|
||||
const m = code.match(/(\d+)$/)
|
||||
return m ? Number.parseInt(m[1], 10) : Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue