1.0.5 β’ Published 4 months ago
heading-order-checker v1.0.5
Heading Order Checker
An accessibility tool to detect incorrect heading structure in your React or Vue apps.
Ensures your headings follow a proper hierarchy (H1 β H2 β H3, etc.), improving SEO and accessibility.
π Features
β
Detect heading hierarchy issues (h1
to h6
)
β
Framework support: React & Vue 3
β
Easy to integrate
β
Custom callback support
β
Zero dependencies (core)
π¦ Installation
npm install heading-order-checker
# or
yarn add heading-order-checker
βοΈ Options
Option | Type | Description |
---|---|---|
callback | Function | Custom function to handle warnings or errors. |
delay | Number | Delay (in ms) for the second check after mount (default: 100ms ). (React/Vue) |
β Example Warning Message
Type | Message |
---|---|
β οΈ Warning | Heading order issue: Found a H4 ("Subheading" ) after a heading of lower level (H1). |
π¨ Usage
React (with useHeadingOrder)
import { useHeadingOrder } from 'heading-order-checker/react';
export default function App() {
useHeadingOrder();
return (
<div>
<h1>Main Heading</h1>
<h3>This will trigger a warning!</h3>
</div>
);
}
Optional: Custom callback
useHeadingOrder({
callback: (message, context) => {
console.log('Custom handler:', message, context);
}
});
Vue 3
Use the useHeadingOrder composable to check heading levels in your Vue components.
<template>
<h1>Main Heading</h1>
<h4>This will trigger a warning!</h4>
</template>
<script setup>
import { useHeadingOrder } from 'heading-order-checker/vue';
useHeadingOrder();
</script>
Optional: Custom callback
<script setup>
import { useHeadingOrder } from 'heading-order-checker/vue';
useHeadingOrder({
callback: (message, context) => {
console.log('Custom handler:', message, context);
}
});
</script>
Core Function (Vanilla JS)
If you want to run the checker manually in any environment:
import { checkHeadingOrder } from 'heading-order-checker/core';
checkHeadingOrder(); // logs warnings in the console
Optional: Custom callback
import { checkHeadingOrder } from 'heading-order-checker/core';
checkHeadingOrder({
callback: (message, context) => {
console.log('Custom handler:', message, context);
}
});
π License
MIT Β©Giulio Simone Floresta