1.0.5 β€’ Published 4 months ago

heading-order-checker v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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.

npm version License


πŸš€ 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

OptionTypeDescription
callbackFunctionCustom function to handle warnings or errors.
delayNumberDelay (in ms) for the second check after mount (default: 100ms). (React/Vue)

❗ Example Warning Message

TypeMessage
⚠️ WarningHeading 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
1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago