( args: Record<string, unknown>, key: string, )
| 50 | * missing or fails validation. |
| 51 | */ |
| 52 | export const requireSlugArg = ( |
| 53 | args: Record<string, unknown>, |
| 54 | key: string, |
| 55 | ): string => { |
| 56 | const value = args[key]; |
| 57 | if (!isValidSlug(value)) { |
| 58 | throw new AnalysisArgError( |
| 59 | `Argument "${key}" must be a slug matching ${SLUG_PATTERN.source}`, |
| 60 | ); |
| 61 | } |
| 62 | return value; |
| 63 | }; |
| 64 | |
| 65 | /** Read an optional slug argument; returns `undefined` if absent. */ |
| 66 | export const optionalSlugArg = ( |
no test coverage detected