# Helpers for station code

```js
import { renderLocal, pooled, countWords, stripFrontmatter } from '@assemblyline/lib-factory';
```

## `renderLocal(importMetaUrl, relativePath, data)`

Reads an [EJS](https://ejs.co) template relative to the calling file and renders it with `data`. Returns the rendered string.

| Argument | What it is |
|---|---|
| `importMetaUrl` | The caller's `import.meta.url` |
| `relativePath` | The template's path from the caller's folder, such as `'./report.md'` |
| `data` | The template's variables |

```js
await ctx.attachReport(renderLocal(import.meta.url, './report.md', { results, counts }));
```

It reads the file on every call and throws when it is missing. How to write a template: [Write reports from templates](/docs/guides/report-templates).

## `pooled(items, concurrency, fn)`

Runs `async fn(item, index)` on every item, with at most `concurrency` running at once. Returns the results in the order of `items`. A throw in `fn` rejects the whole call.

```js
const pages = await pooled(page_numbers, 4, (n) => renderPage(pdf, n));
```

## `countWords(text)`

The number of whitespace-separated words in `text`.

## `stripFrontmatter(markdown)`

Removes a leading YAML frontmatter block (`---` … `---`) and the whitespace after it. Returns the text unchanged when it has none.
