Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@steelbreeze/pivot

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@steelbreeze/pivot

Minimal TypeScript / JavaScript pivot table library

  • 2.9.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by140%
Maintainers
1
Weekly downloads
 
Created
Source

pivot

Maintainability

A minimalist pivot table library for TypeScript/JavaScript. While small (just 697 bytes when minified), this library is large in capability, supporting derived and custom dimensions, derived fields for dimensions and calculations, composite dimensions, filtering.

The library also provides a modest set of numerical selectors. Suggestions for additions, or better still contributions, are welcome.

Why create another pivot table library?

There are plenty of pivot table libraries in existence, so why create another one? Well, this is a spin-off from the steelbreeze/landscape project, where instead of aggregating numerical data from the pivot cube, non-numerical data is needed.

Installation

NPM

For installation via the node package manager:

npm i @steelbreeze/pivot

Web

For web via a CDN:

import * as pivot from 'https://cdn.skypack.dev/@steelbreeze/pivot';

Documentation

The documentation can be found here, and more discussion in the Wiki.

Example

The following is the result of pivoting publicly available information about the Fulham Football Club men's squad at the end of the 2020/21 season, calculating the average age of players by position and country.

import * as pivot from '@steelbreeze/pivot';

// create dimensions derived from the squad data
const axes = {
	x: pivot.dimension(pivot.distinct(squad, 'position').sort(), 'position'),
	y: pivot.dimension(pivot.distinct(squad, 'country').sort(), 'country')
};

// create the pivot cube from the squad data using position and country for x and y axes
const cube = pivot.cube(squad, axes);

// find the average age of players by position by country
const result = pivot.map(cube, pivot.average(age));

The selection is the average age of the players grouped by position and country:

        Defend… Forward Goalke… Midfie…
Belgium 32
Camero…                         25
Denmark 24
England 25      23              23.25
France  27              28
Gabon                           27
Jamaica 28      28
Nether… 25
Nigeria 24      22
Portug…         27
Scotla…                         31
Serbia          26
Slovak…                 24
Spain                   33
USA     28

The full example code can be found here.

Alternatively, as can be seen in the web example, non-numerical content can also be queried, mapping the source data to an arbitrary selection:

const result = pivot.map(cube, pivot.select(player => `${player.givenName} ${player.familyName}`));

Resulting in this sort of output:

DefenderForwardGoalkeeperMidfielder
BelgiumDenis Odoi
CameroonAndre-Frank Zambo Anguissa
DenmarkJoachim Anderson
EnglandTosin Abarabioyo, Joe BryanAdemola LookmanRuben Loftus-Cheek, Harrison Reed, Josh Onomah, Fabio Carvalho
FranceTerence KongoloAlphonse Areola
GabonMario Lemina
JamaicaMichael HectorBobby De Cordova-Reid
NetherlandsKenny Tete
NigeriaOla AinaJosh Maja
PortugalIvan Cavaleiro
ScotlandKevin McDonald, Tom Cairney
SerbiaAleksander Mitrovic
SlovakiaMarek Rodak
SpainFabrico Agosto Ramirez
USATim Ream, Antonee Robinson

Data and calculations correct as of: 2021-05-23.

Keywords

FAQs

Package last updated on 03 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc