# API Reference

macroforge v0.5.0 43 exported items

Macroforge provides a programmatic API for expanding macros in TypeScript code.

## Overview

TypeScript

```
import {
  expandSync,
  checkSyntax,
  parseImportSources,
  loadConfig,
  clearConfigCache,
  scanProjectSync,
  Derive,
  NativePlugin,
  PositionMapper
} from "@macroforge/core";
```

## Core Functions

| Function                                  | Description                             |
| ----------------------------------------- | --------------------------------------- |
| [`expandSync()`](../docs/api/expand-sync) | Expand macros synchronously             |
| `checkSyntax()`                           | Validate TypeScript syntax              |
| `parseImportSources()`                    | Extract import information              |
| `loadConfig()`                            | Load and parse a Macroforge config file |
| `clearConfigCache()`                      | Clear the cached config                 |
| `scanProjectSync()`                       | Scan a project directory for types      |
| `Derive()`                                | TC39 decorator for macro expansion      |

## Classes

| Class                                           | Description                                       |
| ----------------------------------------------- | ------------------------------------------------- |
| [`NativePlugin`](../docs/api/native-plugin)     | Stateful plugin with caching                      |
| [`PositionMapper`](../docs/api/position-mapper) | Maps positions between original and expanded code |

## Quick Example

TypeScript

```
import { expandSync } from "@macroforge/core";

const sourceCode = \`
/** @derive(Debug) */
class User {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
}
\`;

const result = expandSync(sourceCode, "user.ts", {
  keepDecorators: false
});

console.log(result.code);
// Output: class with toString() method generated

if (result.diagnostics.length > 0) {
  console.error("Errors:", result.diagnostics);
}
```

## Detailed Reference

- [`expandSync()`](../docs/api/expand-sync) - Full options and return types
- [`NativePlugin`](../docs/api/native-plugin) - Caching for language servers
- [`PositionMapper`](../docs/api/position-mapper) - Position mapping utilities
