tpmjs/packages/tools/official/yaml-parse
Ajax Davis 5926373be6 chore: update ai package to 6.0.49 across all packages
- Updated all packages from ai@6.0.23 to ai@6.0.49
- Added pnpm override to ensure consistent version
- Created changeset for publishing affected packages
2026-01-25 11:33:03 +10:00
..
src feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
CHANGELOG.md chore: version packages 2025-12-31 23:54:47 +10:00
package.json chore: update ai package to 6.0.49 across all packages 2026-01-25 11:33:03 +10:00
README.md feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsconfig.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsup.config.ts feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00

@tpmjs/tools-yaml-parse

Parse YAML text into JavaScript objects with validation and error handling.

Installation

npm install @tpmjs/tools-yaml-parse

Usage

import { yamlParseTool } from '@tpmjs/tools-yaml-parse';

// Use with AI SDK
const result = await yamlParseTool.execute({
  yaml: `
name: John Doe
age: 30
hobbies:
  - reading
  - coding
  - hiking
  `
});

console.log(result);
// {
//   data: { name: 'John Doe', age: 30, hobbies: ['reading', 'coding', 'hiking'] },
//   isValid: true,
//   metadata: { type: 'object', size: 3 }
// }

Features

  • Validation: Returns both parsed data and validation status
  • Error Handling: Graceful error messages for invalid YAML
  • Metadata: Provides type information and size of parsed data
  • Standards Compliant: Uses js-yaml library for full YAML 1.2 support

Input Schema

Parameter Type Required Description
yaml string Yes The YAML string to parse

Output Schema

interface YamlParseResult {
  data: unknown;           // The parsed JavaScript object/value
  isValid: boolean;        // Whether parsing was successful
  error?: string;          // Error message if parsing failed
  metadata?: {
    type: string;          // Type of parsed data (object, array, string, etc.)
    size: number;          // Number of keys (objects) or items (arrays)
  };
}

Examples

Parse YAML Object

const result = await yamlParseTool.execute({
  yaml: 'name: Alice\nage: 25'
});
// { data: { name: 'Alice', age: 25 }, isValid: true, ... }

Parse YAML Array

const result = await yamlParseTool.execute({
  yaml: '- apple\n- banana\n- cherry'
});
// { data: ['apple', 'banana', 'cherry'], isValid: true, metadata: { type: 'array', size: 3 } }

Handle Invalid YAML

const result = await yamlParseTool.execute({
  yaml: 'invalid: yaml: syntax:'
});
// { data: null, isValid: false, error: 'bad indentation...' }

License

MIT