surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import type { Fields } from './fields' |
| 2 | import { isMarkKind } from './is-mark-kind' |
| 3 | import { isRecord } from './is-record' |
| 4 | import { markFieldsOf } from './mark-fields-of' |
| 5 | import { refusal } from './refusal' |
| 6 | import { TOKEN } from './token' |
| 7 | |
| 8 | /** |
| 9 | * The row's fields from one mark, or a refusal naming the first thing |
| 10 | * wrong: the entry's shape, the feature, the kind, then the reason. |
| 11 | * |
| 12 | * @param entry the feature, kind and reason as the caller passed them |
| 13 | * @returns the mark's row fields once the entry passes every check |
| 14 | */ |
| 15 | export function checkedMark(entry: unknown): Fields { |
| 16 | if (!isRecord(entry)) { |
| 17 | throw refusal('takes one entry, { feature, kind, reason? }', 'mark') |
| 18 | } |
| 19 | |
| 20 | const { feature, kind, reason } = entry |
| 21 | |
| 22 | if (typeof feature !== 'string' || !TOKEN.test(feature)) { |
| 23 | throw refusal('takes a feature name, a snake_case token', 'mark') |
| 24 | } |
| 25 | |
| 26 | if (!isMarkKind(kind)) { |
| 27 | throw refusal("kind: 'ok', 'sad' or 'bad'", 'mark') |
| 28 | } |
| 29 | |
| 30 | if (kind === 'ok') { |
| 31 | if (reason !== undefined) { |
| 32 | throw refusal('reason: an ok mark carries none', 'mark') |
| 33 | } |
| 34 | |
| 35 | return markFieldsOf(kind, feature) |
| 36 | } |
| 37 | |
| 38 | if (typeof reason !== 'string' || !TOKEN.test(reason)) { |
| 39 | throw refusal( |
| 40 | `reason: a ${kind} mark names why, a snake_case token`, |
| 41 | 'mark', |
| 42 | ) |
| 43 | } |
| 44 | |
| 45 | return markFieldsOf(kind, feature, reason) |
| 46 | } |