Skip to content

Commit

Permalink
Export static utils for path generation
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Apr 27, 2024
1 parent 503307e commit 5dc528f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/index.ts
Expand Up @@ -180,6 +180,37 @@ function otherwise(tags: string[]) {
return (fn: any) => Object.fromEntries(tags.map((tag) => [tag, fn]));
}

type AnyRoute = { type: string, tag: string, value: Record<string, any>, context: RouteContext }

function toPathSafeExternal(route: AnyRoute): Either<Error, string>{
return toPathInternalSafe(route, route.context.parentPatterns, route.context.patterns)
}

export { toPathSafeExternal as toPathSafe }

function toPathOrExternal(otherwise: string, route: AnyRoute): string {
const answer = toPathInternalSafe(route, route.context.parentPatterns, route.context.patterns)
if (answer.tag === 'Left') {
return otherwise
} else {
return answer.value
}
}

export { toPathOrExternal as toPathOr }

function toPathExternal(route: AnyRoute): string {
const answer = toPathInternalSafe(route, route.context.parentPatterns, route.context.patterns)
if (answer.tag === 'Left') {
throw answer.value
} else {
return answer.value
}
}

export { toPathExternal as toPath }


function toPathInternalSafe(
route: any,
parentPatterns: string[],
Expand Down

0 comments on commit 5dc528f

Please sign in to comment.