parse (index)

prompts.chat · ai, format-detection, yaml-parser, json-parser, markdown-parser, prompt-normalization, files

Entry-point parser that auto-detects prompt format (yaml, json, markdown, text), dispatches to the appropriate parser, and normalizes the result into ParsedPrompt.

// Source: https://github.com/f/prompts.chat | License: CC0-1.0
// Provided via justclaw.it.com; keep this notice with the code.
export function parse(content: string, format?: 'yaml' | 'json' | 'markdown' | 'text'): ParsedPrompt {
  const trimmed = content.trim();
  
  // Auto-detect format if not specified
  if (!format) {
    if (trimmed.startsWith('{')) {
      format = 'json';
    } else if (trimmed.startsWith('---')) {
      format = 'markdown';
    } else if (trimmed.includes(':') && (trimmed.includes('\n  ') || trimmed.includes('\n-'))) {
      format = 'yaml';
    } else {
      format = 'text';
    }
  }
  
  let data: Record<string, unknown>;
  
  switch (format) {
    case 'json':
      data = parseJson(trimmed);
      break;
    case 'yaml':
      data = parseSimpleYaml(trimme

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key