How kushalcodes/konvert-table-to-card works
Project type and purpose
• This is a small front-end JavaScript library (an open-source tool) whose sole purpose is to convert HTML tables into card layouts on narrow (≤425px) viewports. Users include it via CDN or local script, call TABLE_KONVERTER.init(), and pass optional style/type options.
File structure
• Top-level files
• index.html – example/demo page that pulls in Bootstrap, the conversion script, and one of the CSS themes
• konvert-table-to-card.js – core JS library implementing the conversion logic
• README.md – usage documentation
• styling/
• simple.css, buddha.css, casual.css – prebuilt theme styles for the generated cards
• type.auto-align.css – CSS rules to auto-align generated cards
• imgs/ – screenshot assets for the README
README for architecture cues
• Dependencies: Bootstrap
• Initialization pattern: TABLE_KONVERTER.init(selector, { style, type, stickyHeader })
• Runtime behavior: scans the DOM for matching <table> elements, generates card markup, injects IDs, applies CSS and sticky headers as configured
Main components & relationships
a. Client Browser (User Agent)
• Loads index.html
• Fetches Bootstrap CSS, one or more styling/*.css files, and konvert-table-to-card.js
b. TABLE_KONVERTER Module
• Initialization API: init(selector, options)
• DOM scanner & converter:
– Locates <table> elements by selector
– Reads <thead> and <tbody> contents
– Generates a
structure per row
– Adds generated IDs to cards for future reference
– Attaches sticky header behavior if options.stickyHeader provided
• Responsive listener: watches window resize events and re-converts tables/cards when viewport crosses the 425px threshold
c. Styling/CSS Themes
• simple.css, casual.css, buddha.css – theme rules applied to .card elements
• type.auto-align.css – additional layout rules for the “autoAlign” type
d. External Dependency
• Bootstrap – provides base layout/grid/utilities used by the generated cards
Architectural patterns & principles
• Separation of concerns:
• HTML (index.html) provides static structure
• JS (konvert-table-to-card.js) handles behavior/responsiveness
• CSS (styling/) handles presentation/themes
• Responsive design: single code path adapts output based on viewport width
• Plugin-style initialization: global TABLE_KONVERTER object with pluggable options