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

typed-data-table

v1.2.4

Published

A strongly typed data structure for tabular data

Downloads

4

Readme

Typed Data Table

GitHub license PRs Welcome Build

Typed data table is a typescript node project aiming to provide a type-safe way to interact with tabular data and a basic set of useful primitives.

Live example

Documentation

GitHub

Installation

npm install typed-data-table

Usage

// Let's set up some tables to work with
let inventory = new Table([
  { item: "Cheese", price: 4.25, inventory: 10, category: "Dairy" },
  { item: "Milk", price: 2.25, inventory: 10, category: "Dairy" },
  { item: "Tomato", price: 2.0, inventory: 20, category: "Produce" },
  { item: "Cucumber", price: 1.0, inventory: 15, category: "Produce" },
  { item: "Apple", price: 1.5, inventory: 40, category: "Produce" }
]);

let purchases = new Table([
  { item: "Cheese", customer: 1, amount: 2 },
  { item: "Tomato", customer: 1, amount: 1 },
  { item: "Apple", customer: 2, amount: 3 },
  { item: "Milk", customer: 3, amount: 1 }
]);

Add/Remove Column

you can define new columns and rename or remove columns with chaining the value functions are typesafe, knowing about previous transformations and preserving the type information of the objects in each row

const updatedInventory = inventory
  .withColumn("totalValue", (r) => r.price * r.inventory)
  .renameColumn("inventory", "amountInStock");

Joining

You can join tables together in memory, again preserving type-assist for the resulting data structure

// you can do type-safe joins
const joinedPurchases = purchases
  .innerJoin(
    inventory,
    (r) => r.item,
    (r) => r.item,
    (left, right) => ({
      ...left,
      ...right
    })
  )
  .withColumn("cost", (r) => r.amount * r.price);

Grouping

you can group the data as well, specifying the columns and how they're calculated over the groups of rows

const groupedByCustomer = joinedPurchases
  .groupBy((r) => r.customer)
  .aggregateByColumn({
    // makes a column 'total' that is the sum of the cost column for each group  
    total: (rows) => sum(rows.map((r) => r.cost)),
    // makes a column 'items' that is the sum of the amount column for each group
    items: (rows) => sum(rows.map((r) => r.amount))
  })
  // even the strings in this func will auto-complete, aggregating a group returns a table with the group key
  // as the 'id' column, you can rename this back to customer if desired.
  .renameColumn("id", "customer");

Rolling

you can compute rolling windows over the data

purchases
  .sortValues(['timestamp'], true)
  .rolling(3)
  .aggregate(window => ({
      timestamp: window.last().timestamp,
      purchases: window.size(),
      amountPurchased: window.sum('amount')
  }))