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

humbledata

v1.1.3

Published

In-memory wrangling of humble-sized data sets

Downloads

3

Readme

Goal

Humble Data strives to be an in-memory data wrangler with a small and intuitive API. It's useful if you have a small to medium (thousands or tens of thousands) records returned from a database, and you'd like to massage and wrangle and hustle with the data in memory.

Concepts

You use Humble Data to build a Frame object from any data source of tidy data; typically from a CSV file or a database query result. The Frame object can then be manipulated and queried further using aggregate, selection, sorting, and filtering operations. Aggregate functions return one value. All other operations return a new Frame object. This allows operations to be chained.

Humble Data works best with tidy data sets. Tidy data is data that is arranged such that each row represents one sample, and each column represents one variable. In Humble Data, we call a column a field.

Install

npm install humbledata

Usage

Note that the examples below are in TypeScript.

Building the Frame object

The Frame object, once built, is immutable. You build a Frame object with a Builder.

// build by adding one object at a time
import { Builder } from "humbledata"
const frame = new Builder()
  .addRow({ name: 'foo', size: 10 })
  .addRow({ name: 'bar', size: 30 })
  .build()  

// ...or build from a given array of objects
const data = [
    { name: 'alice', age: 20, height: 170 },
    { name: 'bob', age: 30, height: 180 },
    { name: 'charlie', age: 40, height: 175 }    
]
const frame = new Builder(data).build()

Debugging

Frames can be printed to the console with the print() function:

frame.print()
┌─────────┬───────────┬─────┬────────┐
│ (index) │   name    │ age │ height │
├─────────┼───────────┼─────┼────────┤
│    0    │  'alice'  │ 20  │  170   │
│    1    │   'bob'   │ 30  │  180   │
│    2    │ 'charlie' │ 40  │  175   │
└─────────┴───────────┴─────┴────────┘

Aggregate functions

Aggregate functions return a single value calculated from applying an aggregate function to all rows that have a numeric value for the given field.

const sum = f.sum('age') // sum = 90
const max = f.max('height') // max = 180
const min = f.min('height') // min = 170
const avg = f.avg('age') // avg = 30
const median = f.median('height') // median = 175

Counting functions

The count function counts only rows where the given field value is anything else than undefined.

const sparse = [
    { x: 1, y: undefined },
    { x: 2, y: 30 },
    { x: 3, y: 30 }    
]
const frame = new Builder(sparse).build()
const count = frame.count('y') // count = 2 (not 3)

The distinct function returns the number of distinct (unique), non-undefined, values for a given field.

const distinctX = frame.distinct('x') // distinctX = 3
const distinctY = frame.distinct('y') // distinctY = 1

Grouping

The group function combines grouping and aggregation. It groups data by given field, and then it applies an aggregate function to every item in each group. The resulting Frame has one Row per group.

const gameData = [
    { player: 'eva', points: 80 },
    { player: 'eva', points: 10 },
    { player: 'eva', points: 50 },
    { player: 'bob', points: 90 },
    { player: 'joe', points: 20 },
] 
new Builder(gameData)
            .build()
            .print('Player stats')
            .group('player', 'sum', 'points')
            .print('Total points per player')
     
Player stats
┌─────────┬────────┬────────┐
│ (index) │ player │ points │
├─────────┼────────┼────────┤
│    0    │ 'eva'  │   80   │
│    1    │ 'eva'  │   10   │
│    2    │ 'eva'  │   50   │
│    3    │ 'bob'  │   90   │
│    4    │ 'joe'  │   20   │
└─────────┴────────┴────────┘

Total points per player
┌─────────┬────────┬────────────┐
│ (index) │ player │ sum_points │
├─────────┼────────┼────────────┤
│    0    │ 'eva'  │    140     │
│    1    │ 'bob'  │     90     │
│    2    │ 'joe'  │     20     │
└─────────┴────────┴────────────┘

Filtering

The where function is used to filter out rows based on a condition. The where function returns a new Frame object.

f.where('age', '>=', 30).print()
┌─────────┬───────────┬─────┬────────┐
│ (index) │   name    │ age │ height │
├─────────┼───────────┼─────┼────────┤
│    0    │   'bob'   │ 30  │  180   │
│    1    │ 'charlie' │ 40  │  175   │
└─────────┴───────────┴─────┴────────┘

Splitting

The split function splits one Frame into several new Frames, by grouping on a given field.

const f = new Builder().addRows(peopleData).build().print()        
┌─────────┬───────────┬─────┬─────┬────────┐
│ (index) │   name    │ age │ sex │ height │
├─────────┼───────────┼─────┼─────┼────────┤
│    0    │  'alice'  │ 20  │ 'f' │  170   │
│    1    │ 'charlie' │ 40  │ 'm' │  175   │
│    2    │   'per'   │  2  │ 'm' │   95   │
│    3    │  'lise'   │  3  │ 'f' │  125   │
│    4    │ 'august'  │ 48  │ 'm' │  180   │
└─────────┴───────────┴─────┴─────┴────────┘

const res = f.split('sex')
res.map(r => r.print())
┌─────────┬─────────┬─────┬─────┬────────┐
│ (index) │  name   │ age │ sex │ height │
├─────────┼─────────┼─────┼─────┼────────┤
│    0    │ 'alice' │ 20  │ 'f' │  170   │
│    1    │ 'lise'  │  3  │ 'f' │  125   │
└─────────┴─────────┴─────┴─────┴────────┘
┌─────────┬───────────┬─────┬─────┬────────┐
│ (index) │   name    │ age │ sex │ height │
├─────────┼───────────┼─────┼─────┼────────┤
│    0    │ 'charlie' │ 40  │ 'm' │  175   │
│    1    │   'per'   │  2  │ 'm' │   95   │
│    2    │ 'august'  │ 48  │ 'm' │  180   │
└─────────┴───────────┴─────┴─────┴────────┘

Running tests

npm run test

Author

August Flatby

Show your support

Give this project a ⭐️ if you like this kind of stuff!