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

data-cruncher

v0.1.0

Published

blazingly fast views and transformations of your data

Downloads

7

Readme

data-cruncher

Blazingly fast views and transformations of your data.

npm install data-cruncher

Add your data and create a view

const cruncher = new Cruncher();
cruncher.addCollection("orders", "id", orders);

const ordersByCustomerAndStatus = cruncher
  .view("orders")
  .by("customer", "status")
  .get();

const fullFilled = ordersByCustomerAndStatus("customer1", "FullFilled");

Add a collection first, then you can create views on that collection. A view is just a function that will return an array of the data you searched for. docs on collections and updates docs on views

Update your data

const cruncher = new Cruncher();
cruncher.addCollection("orders", "id", orders);

const ordersByCustomerAndStatus = cruncher
  .view("orders")
  .by("customer", "status")
  .get();

const fullFilled = ordersByCustomerAndStatus("customer1", "FullFilled");

cruncher.update([{ collection: "orders", data: ordersV2 }]);

const fullFilledV2 = ordersByCustomerAndStatus("customer1", "FullFilled");

Use the update method and pass it the updated collection data. The view will return a reference equal array if the returned data has not changed. It's perfect for use with React, since the reference equality helps avoid unnecessary rerenders. docs on collections and updates

Use nested properties and custom functions to create views

const cruncher = new Cruncher();
cruncher.addCollection("students", "id", students);

const studentsBySchoolAndGroup = cruncher
  .view("students")
  .by("school", (student) => (student.age > 21 ? "senior" : "junior"))
  .get();

const seniors = studentsBySchoolAndGroup("school1", "senior");

const studentsByCityAndAge = cruncher
  .view("students")
  .by("address.city", "age")
  .get();

const newYorkers = studentsByCityAndAge("New York City", 20);

docs on nested properties and custom functions

Add joins

const cruncher = new Cruncher();
cruncher.addCollection("orders", "id", orders);
cruncher.addCollection("customers", "id", customers);

const ordersByCustomerAndStatus = cruncher
  .view("orders")
  .by("customer", "status")
  .join("customers", "customer")
  .get();

const fullFilled = ordersByCustomerAndStatus("customer1", "FullFilled");

The returned Objects will contain the full referenced object instead of just its id. docs on joins

Add transformations

const cruncher = new Cruncher();
cruncher.addCollection("orders", "id", orders);
cruncher.addCollection("customers", "id", customers);

const ordersByCustomerAndStatus = cruncher
  .view("orders")
  .by("customer", "status")
  .join("customers", "customer")
  .transform((order) => ({ ...order, customer: order.customer?.name }))
  .get();

const fullFilled = ordersByCustomerAndStatus("customer1", "FullFilled");

Your returned objects will be transformed. You can use full objects from your joins for your transformation. docs on transformations

Query Objects by Id

You can query objects by id and use joins and transformations just like with views. docs on byId

Supported data types

data-cruncher can be used for JavaScript objects (including deeply nested objects) with properties of primitives and arrays out of the box. These are the kind of objects you usually get after deserializing objects from a database or from network calls.

example:

const serializableObject = {
  id: "qe2bmylvcmc",
  name: "Mario",
  address: {
    street: "magic street 42",
    zipCode: "12345T",
    city: "magic island"
  }
  score: 26.7,
  isFunny: true,
  hobbies: [
    { title: "playing guitar", category: "music" },
    { title: "playing guitar", category: "music" },
  ],
};

data-cruncher will detect these objects equality by value equality. This means that two objects with different references but identical values will be treated as equal. Feeding data-cruncher with objects that contain es6 + newer data structures (like Maps, Sets) can result in objects equality not being detected correctly.

License

MIT