DotLottieBuilder Class

API reference for the DotLottieBuilder class in dotlottie-io — a stateful builder for constructing .lottie packages.

DotLottieBuilder Class

A stateful builder for constructing .lottie packages. Configure it with the methods below, then call build() to produce a DotLottie.

Import:

const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");

Constructor

new DotLottieBuilder()

  • Returns: DotLottieBuilder

Configuration

version(v)

Set the manifest version string.

  • Parameters: v: string

  • Returns: void

generator(g)

Set the generator field in the manifest (e.g. your tool name and version).

  • Parameters: g: string

  • Returns: void

mergeStrategy(strategy)

Collision strategy applied when a LottieFile source contains clashing IDs. Defaults to MergeStrategy.Rename.

initialAnimation(id) / initialStateMachine(id)

Set which animation or state machine the player loads first.

  • Parameters: id: string

  • Returns: void

Adding content

builder.addAnimation(id: string, jsonData: Buffer | string, options?: AnimationOptions): void
builder.addTheme(id: string, name: string | null, jsonData: Buffer | string): void
builder.addStateMachine(id: string, name: string | null, jsonData: Buffer | string): void
builder.addImage(filename: string, data: Buffer): void
builder.addFont(filename: string, data: Buffer): void
builder.addAudio(filename: string, data: Buffer): void

Each method queues the content for the next build() call. Filename collisions across queued assets are resolved at build() time using the same deduplication logic as DotLottie's direct API.

Building

build()

Consumes the builder's configuration and returns a DotLottie instance.

  • Returns: DotLottie

  • Throws: if any queued content is invalid (for example, an audio file that isn't .mp3).

Example

const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");

const builder = new DotLottieBuilder();
builder.generator("my-tool v1.0");
builder.initialAnimation("intro");
builder.addAnimation("intro", JSON.stringify(introJson));
builder.addAnimation("hero", JSON.stringify(heroJson));
builder.addAudio("click.mp3", clickMp3Buffer);

const dl = builder.build();
console.log(dl.animationIds()); // ['intro', 'hero']
console.log(dl.audioFilenames()); // ['click.mp3']

See How to Create a .lottie File for a full walkthrough.

Next up: DotLottieReader Class

Last updated: August 5, 2026 at 11:47 AMEdit this page