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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mllull/json-table-print

v1.0.2

Published

Renders a HTML Table from JSON data to a new browser tab and prints the table.

Downloads

7

Readme

JSON Print Table

Renders a HTML Table from JSON data to a new browser tab and prints the table.

Features

  • Print JSON as a Table - Parse JSON data and transform it to HTML Table.
  • Customizable - Style the table with any CSS lib like Bootstrap, Material, etc.
  • Zero-deps, small size (2.50 kB │ gzip: 0.85 kB).
  • Fully typed.

Usage

Install package:

npm i @mllull/json-table-print
// ESM
import {
  printTable,
  printTableHeadersType,
  printTableOptionsType,
} from "@mllull/json-table-print";

// CommonJS
const {
  printTable,
  printTableHeadersType,
  printTableOptionsType,
} = require("@mllull/json-table-print");
printTable = async (
  options: printTableOptionsType,
  data: any
): Promise<boolean>

Types

export interface printTableHeadersType {
  [key: string]: string;
}

export interface printTableElementsType {
  pageTitle?: string;
  table?: string;
  thead?: string;
  th?: string;
  tbody?: string;
  tr?: string;
  td?: string;
}

export interface printTableOptionsType {
  pageTitle?: string;
  headers: printTableHeadersType;
  classes?: printTableElementsType;
  style?: string;
  linkCSSLib?: string;
}

Usage

printTable(options, jsonData);

Explanation of printTableOptionsType types:

pageTitle:

(Optional) The title of the page, it will be shown over the table.

headers:

Keys of the JSON object that will be shown in the table, the second value is the text of the Table header that will be displayed.

classes:

(Optional) A printTableElementsType object that has all CSS classes to be applied.

style:

(Optional) A CSS string of styles to be injected to the final html code.

In the Quasar demo of this project, the style option is generated by UnoCSS.

linkCSSLib

(Optional) URL to any CSS library that will be injected to the final html code. Styles from the CSS lib will be applied to the table and all of the above elements.

Explanation of printTableElementsType types:

All of above types are optional.

pageTitle

Styles to be applied to pageTitle element.

table ,thead ,th ,tbody ,tr ,td

Styles to be applied to all of this elements.

Example of a generated table from JSON data:

<table>
  <thead>
    <tr>
      <th>Dessert (100g serving)</th>
      <th>Calories</th>
      <th>Protein (g)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Frozen Yogurt</td>
      <td>159</td>
      <td>4</td>
    </tr>
    <tr>
      <td>Ice cream sandwich</td>
      <td>237</td>
      <td>4.3</td>
    </tr>
    <tr>
      <td>Eclair</td>
      <td>262</td>
      <td>6</td>
    </tr>
    <tr>
      <td>Cupcake</td>
      <td>305</td>
      <td>4.3</td>
    </tr>
    <tr>
      <td>Gingerbread</td>
      <td>356</td>
      <td>3.9</td>
    </tr>
    <tr>
      <td>Jelly bean</td>
      <td>375</td>
      <td>0</td>
    </tr>
    <tr>
      <td>Lollipop</td>
      <td>392</td>
      <td>0</td>
    </tr>
    <tr>
      <td>Honeycomb</td>
      <td>408</td>
      <td>6.5</td>
    </tr>
    <tr>
      <td>Donut</td>
      <td>452</td>
      <td>4.9</td>
    </tr>
    <tr>
      <td>KitKat</td>
      <td>518</td>
      <td>7</td>
    </tr>
  </tbody>
</table>

Example

A Quasar demo app is available in examples folder.

F.A.Q.

Q: How can I style a certain td element?

Well, this can't be done for the moment. My frist intention when developing this plugin was to keep as simple as possible, I tried to style a certaing element, but it increase the complexity of this plugin (You could not only style a td, but a certain tr). In short, it's not a trivial issue.

License

MIT License © 2023 Mateu Llull.