@bernierllc/content-transformer
v1.0.5
Published
Content format transformation utilities for markdown, HTML, and text processing
Readme
@bernierllc/content-transformer
Content format transformation utilities for markdown, HTML, and text processing with sanitization and metadata extraction.
Installation
npm install @bernierllc/content-transformerFeatures
- Multi-Format Support: Transform between markdown, HTML, and plain text
- Format Detection: Automatically detect content format
- HTML Sanitization: Built-in XSS protection with configurable allowed tags/attributes
- Metadata Extraction: Extract word count, character count, and other metadata
- Presets: Pre-configured transformation presets for common use cases
- TypeScript Support: Full type safety with strict mode
Quick Start
Basic Usage
import { ContentTransformer, contentUtils } from '@bernierllc/content-transformer';
// Quick markdown to HTML
const html = await contentUtils.markdownToHtml('# Hello World');
// Quick HTML to markdown
const markdown = await contentUtils.htmlToMarkdown('<h1>Hello World</h1>');
// Extract plain text
const text = await contentUtils.toText('# Hello World', 'markdown');
// Sanitize HTML
const safe = await contentUtils.sanitizeHtml('<script>alert("xss")</script><p>Safe</p>');Advanced Usage
import { ContentTransformer, transformationPresets } from '@bernierllc/content-transformer';
const transformer = new ContentTransformer();
// Transform with options
const result = await transformer.transform(markdown, {
sourceFormat: 'markdown',
targetFormat: 'html',
sanitize: true,
minify: false
});
// Use presets
const blogResult = await transformer.transform(
markdown,
transformationPresets.blogMarkdownToHtml()
);
// Detect format
const format = transformer.detectFormat(content);
// Extract metadata
const metadata = transformer.extractMetadata(content, 'markdown');API Reference
ContentTransformer Class
class ContentTransformer {
constructor(config?: ContentTransformerConfig);
async transform(content: string, options: TransformationOptions): Promise<TransformationResult>;
detectFormat(content: string): ContentFormat;
extractMetadata(content: string, format: ContentFormat): Record<string, unknown>;
getWordCount(content: string): number;
}Utility Functions
// Quick transformations
contentUtils.markdownToHtml(markdown: string): Promise<string>;
contentUtils.htmlToMarkdown(html: string): Promise<string>;
contentUtils.toText(content: string, sourceFormat?: 'markdown' | 'html'): Promise<string>;
contentUtils.sanitizeHtml(html: string): Promise<string>;
contentUtils.detectFormat(content: string): ContentFormat;
contentUtils.getMetadata(content: string, format?: ContentFormat): Record<string, unknown>;Presets
transformationPresets.blogMarkdownToHtml(): TransformationOptions;
transformationPresets.emailHtmlSanitize(): TransformationOptions;
transformationPresets.docsMarkdownToHtml(): TransformationOptions;
transformationPresets.commentTextToHtml(): TransformationOptions;
transformationPresets.anyToText(sourceFormat?: 'markdown' | 'html'): TransformationOptions;Common Configs
commonConfigs.strict(): ContentTransformerConfig; // Strict sanitization
commonConfigs.blog(): ContentTransformerConfig; // Blog content processing
commonConfigs.permissive(): ContentTransformerConfig; // Permissive for trusted contentIntegration Status
Logger Integration
Status: Not applicable
Justification: This is a pure utility package with no runtime state, side effects, or error conditions that require logging. The ContentTransformer class is stateless and deterministic - it simply transforms content between formats. All errors are thrown as exceptions that calling code can handle, and there are no background operations, network calls, or state changes that would benefit from structured logging.
Pattern: Pure functional utility - no logger integration needed.
NeverHub Integration
Status: Not applicable
Justification: This is a core utility package that performs content format transformations. It does not participate in service discovery, event publishing, or service mesh operations. Content transformation is a stateless utility operation that doesn't require service registration or discovery.
Pattern: Core utility - no service mesh integration needed.
Docs-Suite Integration
Status: Ready
Format: TypeDoc-compatible JSDoc comments are included throughout the source code. All public APIs are documented with examples and type information.
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
