Skip to content

Commit

Permalink
support omitted prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenClontz committed Nov 25, 2023
1 parent ccdd566 commit 7bc538d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/src/Id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export type Tagged =
| PropertyId
| TheoremId
| { kind: 'trait'; space: number; property: number }
| { kind: 'unknown'; id: number }

export type SpaceId = { kind: 'space'; id: number }
export type PropertyId = { kind: 'property'; id: number }
export type TheoremId = { kind: 'theorem'; id: number }

const pattern = /^(?<prefix>[spti])0*(?<id>\d+)/i
const pattern = /^(?<prefix>[spti])?0*(?<id>\d+)/i

export function traitId({ space, property }: TraitId): string {
return `${space}|${property}`
Expand All @@ -33,6 +34,9 @@ export function tag(input: string): Tagged | null {
}

const id = parseInt(match.groups.id)
if (!match.groups.prefix) {
return { kind: 'unknown', id }
}
switch (match.groups.prefix.toUpperCase()) {
case 'S':
return { kind: 'space', id }
Expand Down

0 comments on commit 7bc538d

Please sign in to comment.