hawaii-bill-diff
v1.0.1
Published
A specialized package for comparing Hawaii bill texts with advanced HTML parsing and content-based diffing capabilities
Maintainers
Readme
🏝️ Hawaii Bill Diff
A specialized npm package for comparing Hawaii bill texts with advanced HTML parsing and content-based diffing capabilities. This package is designed specifically for analyzing legislative changes in Hawaii bills, providing both line-by-line and content-based comparison views.
✨ Features
🔍 Advanced Bill Comparison
- Content-Based Analysis: Compare bills by sections and subsections, not just lines
- HTML Parsing: Extract and parse bill content from raw HTML sources
- Formatting Detection: Identify changes in strikethrough, underline, and bold text
- Section Mapping: Automatically detect and map bill sections (Section 1, Section 2, etc.)
📊 Multiple Comparison Views
- Traditional Line-by-Line: Standard diff output showing added, removed, and modified lines
- Content-Based Comparison: Section-by-section analysis with change categorization
- Flowing Narrative: Continuous bill text with inline highlighting for changes
- Detailed Analysis: Comprehensive breakdown of each section's changes
🎨 Visual Change Highlighting
- Added Content: Green highlighting for new text
- Removed Content: Red highlighting with strikethrough for deleted text
- Modified Content: Yellow highlighting for changed text
- Unchanged Content: Normal text display for consistent sections
🛠️ Technical Capabilities
- LCS Algorithm: Longest Common Subsequence algorithm for intelligent text alignment
- Word-Level Diffing: Precise identification of text changes at the word level
- HTML Tag Preservation: Maintains formatting while extracting readable content
- Section Parsing: Intelligent detection of bill structure and organization
🚀 Installation
npm install hawaii-bill-diff📖 Usage
Basic HTML Comparison
import { compareBillContent, compareBillsFromHtml } from 'hawaii-bill-diff';
// Compare two HTML strings containing bill content
const html1 = '<body>Section 1. Purpose...</body>';
const html2 = '<body>Section 1. Purpose...</body>';
// Get content-based comparison
const contentDiff = compareBillContent(html1, html2);
// Get traditional line-by-line comparison
const lineDiff = await compareBillsFromHtml(html1, html2);Content-Based Comparison Result
const result = compareBillContent(html1, html2);
console.log(result.summary);
// Output: { totalChanges: 3, addedSections: 1, removedSections: 1, modifiedSections: 1, unchangedSections: 2 }
console.log(result.sections);
// Output: Array of sections with change types: 'added', 'removed', 'modified', 'unchanged'Parsing Bill Content
import { parseBillContent } from 'hawaii-bill-diff';
const parsedBill = parseBillContent(html);
console.log(parsedBill.sections);
// Output: Array of parsed sections with content and subsections🔧 Example Application
The package includes a complete example application demonstrating all features:
# Clone the repository
git clone <repository-url>
cd hawaii-bill-diff
# Install dependencies
npm install
# Run the example app
npm run dev:exampleVisit http://localhost:3000 to see the example application in action.
📋 API Reference
compareBillContent(html1: string, html2: string): ContentDiffResult
Performs content-based comparison between two HTML strings.
Returns:
interface ContentDiffResult {
summary: {
totalChanges: number;
addedSections: number;
removedSections: number;
modifiedSections: number;
unchangedSections: number;
};
sections: BillSection[];
}compareBillsFromHtml(html1: string, html2: string): Promise<DiffResult>
Performs traditional line-by-line comparison between two HTML strings.
Returns:
interface DiffResult {
added: string[];
removed: string[];
modified: string[];
unchanged: string[];
htmlChanges?: HtmlChange[];
}parseBillContent(html: string): ParsedBillContent
Parses HTML content to extract bill structure and content.
Returns:
interface ParsedBillContent {
title: string;
content: string;
sections: BillSection[];
htmlElements: {
strikethrough: string[];
underline: string[];
bold: string[];
};
}🎯 Use Cases
- Legislative Analysis: Compare different versions of Hawaii bills
- Policy Research: Track changes in proposed legislation
- Legal Review: Identify modifications in bill text
- Academic Research: Analyze legislative evolution
- Public Transparency: Make bill changes easily understandable
🔍 How It Works
- HTML Parsing: Extracts bill content from raw HTML sources
- Section Detection: Identifies bill sections using pattern matching
- Content Extraction: Removes HTML tags while preserving formatting markers
- Text Alignment: Uses LCS algorithm to align similar content
- Change Detection: Identifies additions, deletions, and modifications
- Result Generation: Creates comprehensive comparison reports
🏗️ Architecture
The package is built with modern JavaScript/TypeScript and uses:
- Vite: For fast builds and development
- TypeScript: For type safety and better developer experience
- LCS Algorithm: For intelligent text alignment
- Regex Patterns: For HTML parsing and section detection
📝 License
ISC License
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📞 Support
For questions or issues, please open an issue on the GitHub repository.
Built specifically for Hawaii legislative analysis 🏛️
