Skip to content

generateMermaid

function generateMermaid(params): MermaidOutput;

Defined in: src/index.ts:167

Generate Mermaid diagram syntax from an AWS Step Functions ASL definition

This function converts an ASL definition into Mermaid state diagram syntax, which can be rendered using the Mermaid library or included in Markdown documentation. The output includes CSS classes for styling different state types.

GenerateMermaidParams

Configuration object

MermaidOutput

Mermaid output containing the diagram code and metadata

If params.aslDefinition is a string with invalid JSON (also an instanceof SyntaxError and AslValidationError)

If the ASL definition structure is invalid

import { generateMermaid } from 'sfn-diagram';
const asl = {
StartAt: 'Process',
States: {
Process: { Type: 'Task', Resource: 'arn:aws:...', Next: 'Done' },
Done: { Type: 'Succeed' }
}
};
const { code, metadata } = generateMermaid({ aslDefinition });
console.log(code);
// Output:
// stateDiagram-v2
// [*] --> Process
// Process --> Done
// Done --> [*]
// ...
console.log(`Generated diagram with ${metadata.stateCount} states`);
// Use in Markdown
const { code } = generateMermaid({ aslDefinition: myStateMachine });
const markdown = `\`\`\`mermaid\n${code}\n\`\`\``;
fs.writeFileSync('diagram.md', markdown);