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

report-builder

v1.2.2

Published

Complex JSON reports made easy

Downloads

58

Readme

Report Builder

A simple tool for helping your programs generate complex JSON documents. It provides a nice developer experience providing simple but powerful chainable methods.

Create complex JSON reports easily

NPM David Travis Coverage Status

Installation

Install via yarn

yarn add report-builder (--dev)

or npm

npm install report-builder (--save-dev)

If you don't use a package manager, you can access report-builder via unpkg (CDN), download the source, or point your package manager to the url.

report-builder is compiled as a collection of CommonJS modules & ES2015 modules for bundlers that support the jsnext:main or module field in package.json (Rollup, Webpack 2)

The report-builder package includes precompiled production and development UMD builds in the dist folder. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a <script> tag on your page. The UMD builds make report-builder available as a window.reportBuilder global variable.

Usage

setup


import reportBuilder from 'report-builder';

Examples

See example folder or the runkit example.

Basic usage example

You have to require the report constructor, then you instantiate a report, and then you can start using it:

const Report = require('report-builder');
const report = new Report('Super report','counting api calls');

report.section('results').section('APICalls').increment(10);
report.setTotal(100);

Each call to .section('name') will return a section object pointing to that area of the report. You can save this reference and use it later, for example:

const mySection = report.section('results').section('APICalls');
/* do some fancy stuff*/
mySection.increment('Failed',10);

After running all that example code, we can generate a JSON representation of our report using JSON.stringify. Let's output it to the console:

console.log(JSON.stringify(report, null, 2));
/** And here is our report on the console:
{
  "summary": {
    "total": {
      "count": 100,
      "label": "counting api calls"
    },
    "timestamp": 1482604936983,
    "notes": "Super report"
  },
  "results": {
    "APICalls": {
      "count": 10,
        "count": 10
      "Failed": {
      }
    }
  }
}
*/

Report structure

A report in it's simpler has a summary and a results sections. Check the format below:

{
    summary: {
        total: {
            count: 0,
            label: "What does the total mean, what we are counting"
        },
        timestamp: 1482604172152,
        notes: "Why we are generating a report"
    },

    results: { /* This section is empty when the report is first created*/
        APICalls: {
            count: 10
        }
     }
}

License

The code is available under the MIT license.

Contributing

We are open to contributions, see CONTRIBUTING.md for more info.

API

For a more complete description of the api please check the documentation

Misc

This module was created using generator-module-boilerplate.

Disclaimer

This is a work in progress, and may be a bit oppinionated. It was build to suit my needs, so it makes sense.