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

js-aggregate

v0.0.4

Published

A lightweight JavaScript library for aggregating JSON objects directly in the browser. Inspired by MongoDB’s aggregation framework, this library allows you to perform aggregation operations like filtering, grouping, and projecting on large JSON data store

Downloads

258

Readme

JS Aggregate

A lightweight JavaScript library for aggregating JSON objects directly in the browser. Inspired by MongoDB’s aggregation framework, this library allows you to perform aggregation operations like filtering, grouping, and projecting on large JSON data stored in places like IndexedDB, LocalStorage, or in-memory.

Features

  • Flexible aggregation operations: Includes operations like Match, Unwind, Project, Sort, Group, Average, Sum, First, Last, and AddToSet for manipulating and transforming your data.
  • Document transformations: Perform advanced operations such as DateToString, ToDate, Multiply, and MergeObject for more powerful data transformations.
  • Optimized for front-end: Designed to work with large JSON objects directly in the browser, ideal for use with IndexedDB, LocalStorage, or in-memory data.
  • Intuitive API: Simple and clear API for defining aggregation pipelines and performing complex data manipulations.
  • Aggregation pipeline: Chain operations in a pipeline for easy and efficient data processing.

Note: Not all MongoDB-like features are available; only basic operations are supported.

Installation

Install via npm:

npm install js-aggregate

Example Here’s a simple example showing how to aggregate a dataset with operations like unwind, project, group, and sort:

Example of USE

import { AggregateOperation, Unwind, Project, DateToString, ToDate, Multiply, Group, Average, ReplaceRoot, MergeObject, Sort, AddToSet, aggregate } from "js-aggregate";

const data = [
    { name: "Alice", date: "2024-01-01", evaluations: [{ note: 50, coefficient: 10 }, { note: 55, coefficient: 12 }] },
    { name: "Bob", date: "2024-01-01", evaluations: [{ note: 60, coefficient: 8 }, { note: 65, coefficient: 10 }] },
    { name: "Alice", date: "2024-01-02", evaluations: [{ note: 52, coefficient: 11 }, { note: 56, coefficient: 13 }] },
];

const aggregation = [
  new AggregateOperation(Unwind, "evaluations"),
  new AggregateOperation(Unwind, "evaluations.note"),
  new AggregateOperation(Project, {
    name: true,
    date: new AggregateOperation(
      DateToString,
      "%Y-%m-%d",
      new AggregateOperation(ToDate, "evaluations.date"),
    ),
    note: "evaluations.note",
    coefficient: "evaluations.coefficient",
    performance: new AggregateOperation(Multiply, [
      "evaluations.note",
      "evaluations.coefficient",
    ]),
  }),

  new AggregateOperation(Group, {
    _id: {
      name: "name",
      date: "date",
    },
    moyenneNote: new AggregateOperation(Average, "note"),
    moyenneCoefficient: new AggregateOperation(Average, "coefficient"),
    performanceMoyenne: new AggregateOperation(Average, "performance"),
  }),

  new AggregateOperation(
    ReplaceRoot,
    new AggregateOperation(MergeObject, ["ROOT", "_id"]),
  ),

  new AggregateOperation(Project, {
    name: true,
    date: true,
    moyenneNote: true,
    moyenneCoefficient: true,
    performanceMoyenne: true,
  }),

  new AggregateOperation(Sort, {
    date: 1,
    name: 1,
  }),
];


const collection = aggregate(new Collection(data),aggregation);

Contributing

Feel free to open issues or submit pull requests if you'd like to contribute to the project.

License

This project is licensed under the MIT License.