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

mapa-mental-core

v0.1.0

Published

Constrói árvore hierárquica a partir de rows do banco (cliente → pedido → material+espessura). Gera estrutura JSON pronta para qualquer visualização.

Readme

mapa-mental-core

Constrói árvore hierárquica a partir de array plano de objetos (rows). Genérico: aceita qualquer schema — você define os níveis da árvore via levels.

Zero dependências. JS puro. Node 12+.

Install

npm install mapa-mental-core
# ou local:
npm install file:../mapa-mental-core

Uso básico

const { buildTree } = require('mapa-mental-core');

const rows = [
  { cliente: 'Alpha Ltda', pedido: '00123', material: 'Aço', espessura: 6.35, status: 'pendente' },
  { cliente: 'Beta S.A.',  pedido: '00456', material: 'Inox', espessura: 3.00, status: 'finalizado' },
];

const result = buildTree(rows, {
  levels: [
    { text: r => r.cliente,                   dedup: { words: 3 } },
    { text: r => r.pedido || 'Sem pedido',    trimZero: true },
    { text: r => `${r.material} ${r.espessura.toFixed(2)}` }
  ],
  color: leafRows => piorStatus(leafRows.map(r => r.status), colorMap)
});
// → { treeData, contagem }

API

buildTree(rows, opts)

rows (obrigatório)

Array de objetos. Qualquer schema — você mapeia via levels.

opts.levels (obrigatório)

Array de nível, um por profundidade (raiz → folha).

| Propriedade | Tipo | Descrição | |---|---|---| | text(row) | fn | Obrigatório. Extrai label do nó | | dedup | object | { words: N } abrevia pra N palavras + contador se duplicar | | trimZero | boolean | Remove zeros à esquerda do texto |

Exemplo:

levels: [
  { text: r => r.cliente_nome,  dedup: { words: 3 } },  // profundidade 0
  { text: r => r.pedido_codigo, trimZero: true },        // profundidade 1
  { text: r => `${r.material} ${r.espessura_mm}` }       // profundidade 2 (folha)
]

opts.color (opcional)

color(leafRows) → string (hex)

Função chamada para cada grupo de rows que caiu na mesma folha. Retorna cor hex para colorir o nó. Se omitido, nós folha não têm _cor.

color: leafRows => {
  const map = { pendente: '#cbd5e1', finalizado: '#bbf7d0' };
  return map[leafRows[0].status] || '#ccc';
}

Output

{
  treeData: {
    text: "root",
    children: [{
      text: "Alpha Ltda",           // profundidade 0
      children: [{
        text: "123",                // profundidade 1 (trimZero)
        children: [{
          text: "Aço 6.35",         // profundidade 2 (folha)
          _cor: "#cbd5e1"           // só se opts.color foi fornecido
        }]
      }]
    }]
  },
  contagem: {                       // cor → qtd de folhas com essa cor
    "#cbd5e1": 1,
    "#bbf7d0": 1
  }
}

piorStatus(statuses, colorMap)

Retorna cor hex do pior status (menor idx no colorMap).

const { piorStatus } = require('mapa-mental-core');

const colorMap = {
  pendente:   { idx: 0, cor: '#cbd5e1' },
  em_corte:   { idx: 3, cor: '#fde047' },
  finalizado: { idx: 5, cor: '#bbf7d0' }
};

piorStatus(['finalizado', 'em_corte', 'pendente'], colorMap);
// → '#cbd5e1'  (pendente é o pior)

Licença MIT