Create function-level reference documentation from code, including parameters, errors and examples.
Document the supplied public code interface. Focus on callable behavior and code-level contracts; do not produce a full product onboarding guide. ## Inputs Source code: [CODE] Language and documentation style (for example TSDoc, JSDoc, Google-style docstrings, rustdoc): [STYLE] Intended callers: [AUDIENCE] Known constraints or behaviour not visible in the code: [CONSTRAINTS] ## Instructions 1. List the public functions, classes and types. Skip private helpers unless they affect callers. 2. For each public item, document purpose, parameters, return value, side effects, errors or exceptions, and one minimal usage example. 3. Derive types, defaults and nullability from the signatures. Where the code does not establish a behaviour, say so instead of guessing. 4. Write configuration options as a table only when the code defines options. 5. Suggest docstrings or comments in [STYLE] that can be pasted into the source. ## Return 1. Overview: what the module does and when to use it, in two or three sentences. 2. API reference, for each public item: - **Name** - **Description** - **Parameters** table: Name | Type | Required | Default | Description - **Returns** - **Throws / errors** - **Example** 3. Configuration options table, if any. 4. Docstrings in [STYLE] ready to paste. 5. Behaviour that cannot be established from the source and should be confirmed by the author. ## Acceptance checks Match signatures and nullability. Do not invent an API or undocumented exception. Label examples as illustrative when not executed.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
TypeScript:
export function parseDuration(input: string, opts?: { allowNegative?: boolean }): number {
const m = /^(-)?(\d+)(ms|s|m|h)$/.exec(input.trim());
if (!m) throw new RangeError(`Invalid duration: ${input}`);
if (m[1] && !opts?.allowNegative) throw new RangeError("Negative durations are not allowed");
const n = Number(m[2]) * { ms: 1, s: 1000, m: 60000, h: 3600000 }[m[3] as "ms" | "s" | "m" | "h"];
return m[1] ? -n : n;
}
Style: TSDoc
Audience: developers configuring timeouts in our SDKA reference entry for parseDuration with parameters input (string, required) and opts.allowNegative (boolean, optional, default false because undefined is treated as false), returns milliseconds as a number, throws RangeError for unrecognized formats and for negative values without allowNegative, examples such as parseDuration("2s") returning 2000 and parseDuration("-5m", { allowNegative: true }) returning -300000, a TSDoc block, and an open question about whether decimal values like "1.5h" should be supported since the regex rejects them. Illustrative expectation, not a recorded model run.Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models