npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@randajan/js-object-view

v3.1.0

Published

Iterate through object and organize key-value pairs

Downloads

6

Readme

@randajan/js-object-view

NPM JavaScript Style Guide

JavaScript library for rendering structured data in HTML format. It supports automatic detection of tabular structures and visualization of deeply nested objects. It is ideal for debugging, admin interfaces, or displaying API responses.

Installation

You can use the library as an ES module:

import { ObjectViewHTML, toHTML } from "./ObjectViewHTML";

Usage

Basic Example

const data = {
    name: "John Doe",
    age: 30,
    hobbies: ["Reading", "Gaming", "Hiking"],
};

const html = toHTML(data);
console.log(html);

Configuration Options

When creating an instance, you can specify options:

const options = {
    maxImgHeight: 150, // Maximum height for images in pixels
    maxImgWidth: 250, // Maximum width for images in pixels
    formatDate: d => d.toLocaleString(), // Function to format dates
    formatNumber: n => n.toLocaleString(), // Function to format numbers
    longTextSize: 50, // Maximum length of text before truncation with ellipsis

    // Ratio of rows required for a column to be considered valid within a table
    validColRatio: 0.6,

    // Ratio of valid columns required for an array of objects to be recognized as a table
    validColsRatio: 0.6, 
};

const view = ObjectViewHTML.create(options);
const html = view.generate(data);

Extending / customization

Or if available extension via option is somehow not enough you can create your own generator by extending provided class ObjectViewHTML Important function is toValue that converts any input into an appropriate representation based on its type. It applies formatting for numbers, booleans, dates, images, URLs, and text while handling unknown types gracefully.

API

  • toHTML(data, options): Returns an HTML representation of the data.
  • ObjectViewHTML.create(options): Creates an instance with custom configuration.

JSX Support

For React and JSX environments, a dedicated module is available: @randajan/js-object-view/jsx. It follows the same API structure but provides JSX-compatible components. Instead of ObjectViewHTML, use ObjectViewJSX, and replace toHTML with toJSX for rendering inside React components.


export class ObjectViewJSX extends ObjectViewHTML {

    toView(content) { return <div className="View">{content}</div>; }
    toList(items) { return <table className="List"><tbody>{items}</tbody></table>; }
    toListRow(key, item, rowKey) { return <tr key={rowKey} className="ListRow">{key}{item}</tr>; }
    toListKey(key) { return <td className="ListKey" style={{"fontWeight":"bold", "verticalAlign":"top", "padding":"1px 10px"}}>{key}</td>; }
    toListItem(item) { return <td className="ListItem" style={{"verticalAlign":"top", "padding":"1px 10px"}}>{item}</td>; }

    toTable(cols, rows) { return <table className="Table">{cols}{rows}</table>; }
    toTableCols(cols) { return <thead className="TableCols"><tr>{cols}</tr></thead>; }
    toTableCol(col, colKey) { return <th key={colKey} className="TableCol">{col}</th>; }
    toTableRows(rows) { return <tbody className="TableRows">{rows}</tbody>; }
    toTableRow(values, rowKey) { return <tr key={rowKey} className="TableRow">{values}</tr>; }
    toTableCell(value, col) { return <td key={col} className="TableCell" style={{"verticalAlign":"top", "padding":"1px 10px"}}>{value}</td>; }

    toBlank() { return null; }

    toBoolean(value) { return <input type="checkbox" checked={value ? true : false} style={{pointerEvents:"none"}}/>; }
    toImg(url, value, maxHeight, maxWidth) {
        return <img alt={url.ref} src={url.href} title={value} style={{"max-height":maxHeight+"px", "max-width":maxWidth+"px"}}/>
    }
    toHref(url, content) { return <a href={url.href} target="_blank">{content}</a>;}

    toText(str) { return <span>{str}</span>; }
    toLongText(str, limit) { return <span title={str}>{str.substring(0, limit)}</span>; }
    toOther(value) { return value; }

}

Support

If you have any questions or suggestions for improvements, feel free to open an issue in the repository.

License

MIT © randajan