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 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-transformer-funcs-two-dimensions

v1.8.2

Published

Two-dimensional matrix grid mapper for json-transformer-funcs

Readme

json-transformer-funcs-two-dimensions

Columns x data rows = a grid of rows, each with their cells.

npm


Install

npm install json-transformer-funcs-two-dimensions

What it does

Takes a column schema, a data array, and a spec object. For every data row it builds one <tr> element, then fills it with <td> cells — one per column.

Two steps happen per data row:

  1. Build the row container — applyTemplate(rowTemplate, rowElement) creates the <tr>
  2. Build the cells — each column's template key is looked up in spec, applied with applyTemplate, and the results become the <tr>'s children

The column schema drives both steps: template.body.tr names the row template, template.body.cell names the cell template.


Signature

import twoDimensional from "json-transformer-funcs-two-dimensions";

twoDimensional(inColumns, inData, inSpec)

| Argument | Type | Description | | :--- | :--- | :--- | | inColumns | non-empty array of column objects | Each must have columnName and optionally template.body.tr / template.body.cell | | inData | array of row objects | One object per row; keys match columnName values | | inSpec | plain object | The template library — keyed by template name |

Returns: an array of <tr> row nodes, each with children filled with <td> cell nodes.

Guards (throw on violation):

  • inColumns must be a non-empty array; every item must have a non-empty columnName
  • inData must be an array of objects
  • inSpec must be a plain object
  • The row template key must exist in inSpec
  • Every cell template key must exist in inSpec — missing keys throw with the exact key name

Example

import twoDimensional from "json-transformer-funcs-two-dimensions";

const columns = [
    { columnName: "itemName", width: "300px", template: { body: { tr: "buildBodyTr", cell: "buildBodyCell" } } },
    { columnName: "baseUnit", width: "200px", template: { body: { tr: "buildBodyTr", cell: "buildBodyCell" } } },
    { columnName: "batches",  width: "100px", template: { body: { tr: "buildBodyTr", cell: "buttonCell"   } } }
];

const data = [
    { itemName: "0.09/30mm", baseUnit: "kgs", batches: [{ ... }] }
];

const spec = {
    buildBodyTr:   { tagName: "tr", attributes: { class: "align-middle" }, children: [] },
    buildBodyCell: { tagName: "td", textContent: "${rowValue}", attributes: { class: "py-3 px-3 text-secondary" } },
    buttonCell:    { tagName: "td", attributes: { class: "py-2 px-3 text-center" },
                     children: [{ tagName: "button", textContent: "${agg:count}", attributes: { class: "btn btn-primary btn-sm" } }] }
};

const rows = twoDimensional(columns, data, spec);
// [
//   {
//     tagName: "tr",
//     attributes: { class: "align-middle" },
//     children: [
//       { tagName: "td", textContent: "0.09/30mm", ... },
//       { tagName: "td", textContent: "kgs",       ... },
//       { tagName: "td", attributes: { class: "..." }, children: [{ tagName: "button", textContent: 1 }] }
//     ]
//   }
// ]

When to use

Use twoDimensional when you have a column schema and a data array and want a grid of row nodes — each row filled with the correct cell per column.

For a flat list of elements from a flat source array, use json-transformer-funcs-one-dimension.

For a single element from a single object, use json-transformer-funcs-primitive.

For the complete story — all three engines working together with a registry, instructions, and writePath — see json-transformer-funcs.


License

MIT (c) KeshavSoft