JSPM

@bernierllc/validators-content

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q62552F
  • License UNLICENSED

Content quality validation - composite validator combining link integrity, image optimization, editorial style, and markdown structure validation

Package Exports

  • @bernierllc/validators-content
  • @bernierllc/validators-content/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@bernierllc/validators-content) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@bernierllc/validators-content

Content quality validation - composite validator combining link integrity, image optimization, editorial style, and markdown structure validation.

Overview

The validators-content package is a domain validator that orchestrates multiple primitive validators to provide comprehensive content quality assurance. It validates links, images, editorial style, and markdown structure in a single operation.

Installation

npm install @bernierllc/validators-content

Features

  • Link Integrity: Validates broken links, anchor targets, redirect chains, and protocol consistency
  • Image Assets: Checks alt text, image format, file size, dimensions, and srcset
  • Editorial Style: Validates inclusive language, brand terms, tone, and readability
  • Markdown Structure: Verifies heading hierarchy, link references, list formatting, and code blocks
  • Flexible Configuration: Enable/disable individual validators as needed
  • Multiple Content Types: Supports markdown, HTML, and plain text

Usage

Basic Example

import { validateContent } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';

const utils = createSharedUtils();

const content = {
  markdown: `
# Welcome

Check out [our site](https://example.com)!

![Logo](logo.png "Company Logo")
  `.trim(),
};

const result = await validateContent(content, {}, utils);

if (result.problems.length === 0) {
  console.log('Content is valid!');
} else {
  result.problems.forEach(problem => {
    console.log(`${problem.severity}: ${problem.message}`);
  });
}

With Custom Options

import { validateContent } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';

const utils = createSharedUtils();

const content = {
  html: '<h1>Title</h1><p>Some content with <a href="/docs">link</a></p>',
  baseUrl: 'https://mysite.com',
};

const result = await validateContent(content, {
  validateLinks: true,
  validateImages: true,
  validateEditorialStyle: false, // Skip editorial validation
  validateMarkdownStructure: false, // Skip markdown validation
  maxContentLength: 10000, // Warn if content exceeds 10KB
  skipExternalLinks: true, // Don't check external links
}, utils);

Using the Validator Factory

import { createContentValidator } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';

const utils = createSharedUtils();

// Create a configured validator
const validator = createContentValidator({
  validateLinks: true,
  validateImages: true,
  validateEditorialStyle: true,
  validateMarkdownStructure: true,
});

// Get metadata
const meta = validator.getMeta();
console.log('Validator:', meta.name);
console.log('Enabled rules:', meta.enabledRules);

// Validate content
const content = {
  text: 'Check out this link: https://example.com',
};

const result = await validator.validate(content, utils);
console.log('Problems found:', result.problems.length);

API

validateContent(content, options?, utils)

Validates content using configured validators.

Parameters:

  • content (ContentInput): Content to validate
    • text?: string - Plain text content
    • html?: string - HTML content
    • markdown?: string - Markdown content
    • baseUrl?: string - Base URL for resolving relative links
    • filePath?: string - Source file path (for context)
  • options? (ContentValidationOptions): Validation options
    • validateLinks?: boolean - Validate link integrity (default: true)
    • validateImages?: boolean - Validate image assets (default: true)
    • validateEditorialStyle?: boolean - Validate editorial style (default: true)
    • validateMarkdownStructure?: boolean - Validate markdown structure (default: true)
    • severity?: Severity - Severity level for problems (default: 'warn')
    • linkOptions?: Partial<LinkIntegrityOptions> - Options for link validation
    • skipExternalLinks?: boolean - Skip external link checking (default: false)
    • maxContentLength?: number - Maximum content length (default: unlimited)
  • utils (SharedUtils): Shared utilities from @bernierllc/validators-utils

Returns: Promise<ValidationResult>

createContentValidator(options?)

Creates a configured content validator instance.

Parameters:

  • options? (ContentValidationOptions): Validation configuration

Returns: Object with:

  • validate(content, utils) - Validation function
  • getMeta() - Metadata function

Content Types

The validator supports three content types:

Markdown Content

const content = {
  markdown: '# Title\n\n[Link](https://example.com)\n\n![Image](image.png)',
};

For markdown content:

  • Links are extracted from [text](url) syntax
  • Images are extracted from ![alt](src) syntax
  • Markdown structure is validated if enabled

HTML Content

const content = {
  html: '<h1>Title</h1><p><a href="https://example.com">Link</a></p>',
};

For HTML content:

  • Links are extracted from <a href="..."> tags
  • Images are extracted from <img src="..."> tags
  • HTML structure is validated through editorial rules

Plain Text Content

const content = {
  text: 'Plain text content with no markup.',
};

For plain text content:

  • Editorial style validation is performed
  • Links and images are not extracted

Composed Validators

This domain validator composes four primitive validators:

Validates:

  • Broken links
  • Anchor targets
  • Redirect chains
  • Protocol consistency

2. Image Asset (@bernierllc/validators-image-asset)

Validates:

  • Missing alt text
  • Inefficient image format
  • Excessive file size
  • Excessive dimensions
  • Missing srcset

3. Editorial Style (@bernierllc/validators-editorial-style)

Validates:

  • Inclusive language
  • Brand terms
  • Prohibited terms
  • Tone validation
  • Readability score

4. Markdown Structure (@bernierllc/validators-markdown-structure)

Validates:

  • Heading hierarchy
  • Link references
  • List formatting
  • Code block syntax

Configuration Examples

const result = await validateContent(content, {
  validateLinks: true,
  linkOptions: {
    checkBrokenLinks: true,
    checkAnchorTargets: true,
    checkRedirectChains: true,
    checkProtocolConsistency: true,
  },
}, utils);

Content Length Limits

const result = await validateContent(content, {
  maxContentLength: 5000, // Warn if content exceeds 5KB
  severity: 'error', // Treat warnings as errors
}, utils);

Selective Validation

// Only validate links and images
const result = await validateContent(content, {
  validateLinks: true,
  validateImages: true,
  validateEditorialStyle: false,
  validateMarkdownStructure: false,
}, utils);

Integration Status

  • Logger Integration: Not applicable - Pure validation function with no runtime logging requirements
  • Docs-Suite: Ready - Exports markdown documentation
  • NeverHub Integration: Not applicable - Stateless validator with no service discovery or event bus requirements

Dependencies

BernierLLC Packages:

  • @bernierllc/validators-core - Core validation framework
  • @bernierllc/validators-runner - Validation runner
  • @bernierllc/validators-utils - Shared utilities
  • @bernierllc/validators-link-integrity - Link integrity validation
  • @bernierllc/validators-image-asset - Image asset validation
  • @bernierllc/validators-editorial-style - Editorial style validation
  • @bernierllc/validators-markdown-structure - Markdown structure validation
  • @bernierllc/validators-email - Email content validation
  • @bernierllc/validators-web - Web page validation
  • @bernierllc/validators-api - API specification validation

License

Copyright (c) 2025 Bernier LLC. All rights reserved.