Home/Tools/@tpmjs/tools-yaml-stringify

yamlStringifyTool

@tpmjs/tools-yaml-stringify

Convert JavaScript objects to YAML strings. Supports objects, arrays, and primitive values with configurable indentation. Perfect for generating configuration files or serializing data.

Official
data
v0.2.0
MIT

Interactive Playground

Test @tpmjs/tools-yaml-stringify (yamlStringifyTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-yaml-stringify
pnpm add @tpmjs/tools-yaml-stringify
yarn add @tpmjs/tools-yaml-stringify
bun add @tpmjs/tools-yaml-stringify
deno add npm:@tpmjs/tools-yaml-stringify

2. Import the tool

import { yamlStringifyTool } from '@tpmjs/tools-yaml-stringify';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { yamlStringifyTool } from '@tpmjs/tools-yaml-stringify';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { yamlStringifyTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
data
Required
Type: objectarraystringnumberbooleannull

The JavaScript data to convert to YAML

indent
Optional
Type: number

Number of spaces for indentation (default: 2, range: 1-8)

Schema extracted: 1/1/2026, 8:18:05 AM

README

@tpmjs/tools-yaml-stringify

Convert JavaScript objects to YAML strings with formatting options.

Installation

npm install @tpmjs/tools-yaml-stringify

Usage

import { yamlStringifyTool } from '@tpmjs/tools-yaml-stringify';

// Use with AI SDK
const result = await yamlStringifyTool.execute({
  data: {
    name: 'John Doe',
    age: 30,
    hobbies: ['reading', 'coding', 'hiking']
  },
  indent: 2
});

console.log(result.yaml);
// name: John Doe
// age: 30
// hobbies:
//   - reading
//   - coding
//   - hiking

Features

  • Configurable Indentation: Control spacing with indent parameter (1-8 spaces)
  • Metadata: Returns line count, character count, and indent level
  • Type Support: Handles objects, arrays, strings, numbers, booleans, and null
  • Standards Compliant: Uses js-yaml library for YAML 1.2 output
  • Clean Output: No anchors/references, preserves key order

Input Schema

ParameterTypeRequiredDescription
dataanyYesThe JavaScript data to convert to YAML
indentnumberNoSpaces for indentation (default: 2, range: 1-8)

Output Schema

interface YamlStringifyResult {
  yaml: string;           // The YAML string output
  metadata: {
    lines: number;        // Number of lines in the output
    characters: number;   // Total character count
    indent: number;       // Indentation level used
  };
}

Examples

Stringify Object with Default Indent

const result = await yamlStringifyTool.execute({
  data: { name: 'Alice', role: 'Developer' }
});
console.log(result.yaml);
// name: Alice
// role: Developer

Stringify Array with Custom Indent

const result = await yamlStringifyTool.execute({
  data: ['apple', 'banana', 'cherry'],
  indent: 4
});
console.log(result.yaml);
// -    apple
// -    banana
// -    cherry

Stringify Nested Object

const result = await yamlStringifyTool.execute({
  data: {
    server: {
      host: 'localhost',
      port: 8080,
      options: {
        ssl: true,
        timeout: 3000
      }
    }
  }
});
console.log(result.yaml);
// server:
//   host: localhost
//   port: 8080
//   options:
//     ssl: true
//     timeout: 3000

Get Metadata

const result = await yamlStringifyTool.execute({
  data: { config: { debug: true } }
});
console.log(result.metadata);
// { lines: 2, characters: 25, indent: 2 }

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
yaml
data
stringify

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
yamlStringifyTool | TPMJS | TPMJS