generateSvg
function generateSvg(params): SvgOutput;Defined in: src/index.ts:109
Generate an SVG diagram from an AWS Step Functions ASL definition
This function parses an ASL definition, lays it out with Dagre, and builds the SVG as a string with no DOM. The output is a complete SVG string that can be saved to a file or embedded in HTML.
Parameters
Section titled “Parameters”params
Section titled “params”Configuration object
Returns
Section titled “Returns”SVG output containing the diagram string, dimensions, and metadata
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
Examples
Section titled “Examples”import { generateSvg } from 'sfn-diagram';import { writeFileSync } from 'fs';
const asl = { StartAt: 'HelloWorld', States: { HelloWorld: { Type: 'Pass', Result: 'Hello!', End: true } }};
const { svg, width, height } = generateSvg({ aslDefinition: asl, theme: 'dark', layout: 'LR' });writeFileSync('diagram.svg', svg);console.log(`Generated ${width}x${height} diagram`);// From JSON stringconst aslJson = fs.readFileSync('state-machine.json', 'utf-8');const result = generateSvg({ aslDefinition: aslJson, theme: 'light' });// With AWS service iconsconst { svg } = generateSvg({ aslDefinition: asl, showIcons: true, iconPosition: 'left', nodeWidth: 150});