Borrow
DocVal

Quick Start

Get started with DocVal and validate your documentation codeblocks.

Quick Start

Installation

Install Borrow DocVal using your preferred package manager:

npm install @borrowdev/docval

Usage

DocVal ships as a remark plugin, so it works with any tool that supports remark (most documentation tools).

We've really enjoyed using Fumadocs so we put together an integration guide.

Opt-in with the docval keyword

The recommended way to get started is to add the docval keyword to individual codeblocks you want to validate. This lets you gradually adopt DocVal without having to fix every codeblock at once.

Add the remark plugin to your configuration:

import { remarkDocVal } from "@borrowdev/docval";

// In your remark plugin configuration:
// (Optionally, you may pass some configuration options here, keep reading for details)
remarkDocVal();

Then, add the docval keyword to any codeblock you want to validate:

```ts docval
import { somePackage } from "some-package";

console.log(somePackage());
```

DocVal will create an environment, install some-package, and execute the code. If the code fails, your build fails with a descriptive error.

Validate all codeblocks with include

If you want to ensure all your codeblocks are always validated by default, you can enable the include option to validate every codeblock automatically:

import { remarkDocVal } from "@borrowdev/docval";

remarkDocVal({ include: true });

With include enabled, you can still opt out individual codeblocks using the no-docval keyword:

```ts no-docval
// This codeblock is intentionally incomplete
const result = someIllustration();
```

Gradual migration

We recommend starting with the docval keyword approach and progressively marking more codeblocks until you're confident enough to enable include for all codeblocks. See the Options reference for more details.

Supported Languages

DocVal supports the following codeblock languages:

LanguageIdentifiers
JavaScriptjs, javascript
TypeScriptts, typescript
JSXjsx
TSXtsx
Rustrs, rust

Codeblocks with unsupported languages are silently skipped.

Next Steps

On this page