Skip to the content.

Complete reference for chalk library methods.

Core Methods

chalk.createLibrary(documentDefinition: DocumentDefinition): Library

Creates a new Chalk library with the specified document definition.

Parameters:

Returns: Library instance with .add() method for chaining

Example:

const library = chalk.createLibrary({
  class: 'blog-post',
  bodyPolicy: ['paragraph', 'image'],
  headerAttributes: [
    { identifier: 'title', type: 'string', required: true }
  ]
});

chalk.compile(source: string, library: Library): Result<Document, string>

Compiles Chalk source code into a structured document.

Parameters:

Returns: Result object with ok, data, and error properties

Example:

const result = chalk.compile(chalkSource, library);
if (result.ok) {
  console.log(result.data);
} else {
  console.error(result.error);
}

chalk.compileFile(filePath: string, library: Library): Result<Document, string>

Compiles a Chalk file into a structured document.

Parameters:

Returns: Result object with ok, data, and error properties

Example:

const result = chalk.compileFile('./document.chalk', library);

Library Methods

Library.add(...definitions): Library

Adds element definitions, attribute types, and enums to a library. Supports method chaining.

Parameters:

Returns: The library instance for chaining

Example:

const library = chalk.createLibrary(docDef)
  .add(element1, element2, customType, enumType);

Result Type

All methods return a Result<T, E> object:

interface Result<T, E> {
  ok: boolean;
  data?: T;    // Present when ok: true
  error?: E;   // Present when ok: false
}

Usage:

const result = chalk.compile(source, library);
if (result.ok) {
  // Success - use result.data
  processDocument(result.data);
} else {
  // Error - handle result.error
  console.error('Compilation failed:', result.error);
}

Next Steps