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 { checkedValue } from '../checked-value' |
| 2 | import { isRecord } from '../is-record' |
| 3 | import type { Method } from '../method' |
| 4 | import { PROP_LIMIT } from '../prop-limit' |
| 5 | import { refusal } from '../refusal' |
| 6 | import { TOKEN } from '../token' |
| 7 | |
| 8 | /** |
| 9 | * An entry's properties as they go into the row, or a refusal naming the |
| 10 | * first thing wrong: the shape, the count, then each key and value in turn. |
| 11 | * |
| 12 | * @param props what the caller passed as `props` |
| 13 | * @param method the method the properties were passed to, named in a refusal |
| 14 | * @returns the properties by key, each value checked |
| 15 | */ |
| 16 | export function checkedProps( |
| 17 | props: unknown, |
| 18 | method: Method, |
| 19 | ): Record<string, string | number | boolean> { |
| 20 | if (!isRecord(props)) { |
| 21 | throw refusal('props: an object of properties by key', method) |
| 22 | } |
| 23 | |
| 24 | const entries = Object.entries(props) |
| 25 | |
| 26 | if (entries.length > PROP_LIMIT) { |
| 27 | throw refusal(`props: at most ${PROP_LIMIT} properties`, method) |
| 28 | } |
| 29 | |
| 30 | const checked: Record<string, string | number | boolean> = {} |
| 31 | |
| 32 | for (const [key, value] of entries) { |
| 33 | if (!TOKEN.test(key)) { |
| 34 | throw refusal('props: every key is a snake_case token', method) |
| 35 | } |
| 36 | |
| 37 | checked[key] = checkedValue(key, value, method) |
| 38 | } |
| 39 | |
| 40 | return checked |
| 41 | } |