generateDiagram
Call Signature
Section titled “Call Signature”function generateDiagram(params): SvgOutput;Defined in: src/index.ts:225
Generate a diagram from an ASL definition (auto-detects format from options)
This is a convenience function that generates an SVG or Mermaid diagram based on the
format option. If no format is specified, defaults to SVG.
Pass format as a literal ('svg' or 'mermaid') to get the matching output type.
With format omitted the output is SVG at runtime, but the return type stays the
union; pass format: 'svg' to get SvgOutput. A non-literal format also returns
the union. 'html' and 'png' are not narrowed: both throw. Use generateHtml from
sfn-diagram/html or exportPng from sfn-diagram/png, which keeps the viewer and
the rasterizer out of bundles that never use them.
Parameters
Section titled “Parameters”params
Section titled “params”GenerateDiagramParams & object
Configuration object
Returns
Section titled “Returns”SVG output if format is ‘svg’, Mermaid output if format is ‘mermaid’
Throws
Section titled “Throws”If params.aslDefinition is a string with invalid JSON (also an instanceof SyntaxError and AslValidationError)
Throws
Section titled “Throws”If the ASL definition structure is invalid, or if format is ‘html’ or ‘png’
Example
Section titled “Example”import { generateDiagram } from 'sfn-diagram';
// Generate SVGconst { svg } = generateDiagram({ aslDefinition: myAsl, format: 'svg' });
// Generate Mermaidconst mermaidResult = generateDiagram({ aslDefinition: myAsl, format: 'mermaid' });Call Signature
Section titled “Call Signature”function generateDiagram(params): MermaidOutput;Defined in: src/index.ts:238
Generate a Mermaid diagram from an ASL definition.
Parameters
Section titled “Parameters”params
Section titled “params”GenerateDiagramParams & object
Configuration object with format: 'mermaid'
Returns
Section titled “Returns”Mermaid output
Throws
Section titled “Throws”If params.aslDefinition is a string with invalid JSON (also an instanceof SyntaxError and AslValidationError)
Throws
Section titled “Throws”If the ASL definition structure is invalid
Example
Section titled “Example”const { code } = generateDiagram({ aslDefinition, format: 'mermaid' });Call Signature
Section titled “Call Signature”function generateDiagram(params): | SvgOutput | MermaidOutput;Defined in: src/index.ts:252
Generate a diagram whose format is omitted or not known at compile time.
Parameters
Section titled “Parameters”params
Section titled “params”Configuration object
Returns
Section titled “Returns”The union; SVG at runtime when format is omitted
Throws
Section titled “Throws”If params.aslDefinition is a string with invalid JSON (also an instanceof SyntaxError and AslValidationError)
Throws
Section titled “Throws”If the ASL definition structure is invalid, or if format is ‘html’ or ‘png’
Example
Section titled “Example”const result = generateDiagram({ aslDefinition });if ('svg' in result) { console.log(result.svg); }