Skip to main content

Shnippet

Let your tests write your docs

Easy to Use

Test-Driven Documentation

Extract code snippets directly from your tests. Your documentation stays in sync with your code, ensuring examples are always accurate and working.

Focus on What Matters

Type Safety

Automatically generated TypeScript types for your snippet names. Get autocomplete and type checking to prevent typos and errors.

Powered by React

Multi-Language Support

Support for multiple programming languages with language-specific formatting. Show the same snippet in different languages with proper syntax highlighting.

How It Works

1. Create Snippet

// math.test.ts
describe('Math functions', () => {
it('should add numbers', () => {
// :snippet-start: add
const result = add(2, 3);
// result is 5
// :snippet-end:
expect(result).toBe(5);
});
});

2. Generated Output

// snippets/gen-types/index.d.ts
export type SnippetName = 'add';

// snippets/typescript/add.snippet.txt
const result = add(2, 3);
// result is 5

3. Use Snippet

import { snippetManager } from 'shnippet';
import type { SnippetName } from '../snippets/gen-types';

// Get the snippet
const result = await snippetManager.getSnippet('add' as SnippetName);
// result = {
// name: 'add',
// languages: ['typescript'],
// defaultLanguage: 'typescript',
// content: { typescript: 'const result = add(2, 3);' }
// }