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

@iyulab/json-collection

v0.1.3

Published

A json collection pipeline library that mimics the MongoDB pipeline syntax.

Downloads

7

Readme

json-collection

This library provides a simplified simulation of MongoDB's aggregation and query framework in TypeScript. It enables filtering, grouping, sorting, and limiting of in-memory data collections, mimicking the behavior of MongoDB database operations but in a lightweight, local context.

Installation

To use the Json Collection library in your project, install it via npm. Execute the following command in your project directory:

npm install @iyulab/json-collection

Make sure you have Node.js and npm installed on your system. You can download and install Node.js (npm included) from https://nodejs.org/.

Features

The Json Collecgtion library provides the following features:

  • Filtering ($match): Filter your data based on specified criteria.
  • Grouping and Aggregation ($group): Group your data by specific fields and perform various aggregation operations like counting, summing, averaging, etc.
  • Sorting ($sort): Sort your data based on one or more fields.
  • Limiting ($limit): Limit the number of documents to return.
  • Finding ($find): Retrieve documents from your data based on filtering, sorting, and limiting criteria, simulating the MongoDB find operation.

Usage

Below is a simple example demonstrating how to use the Json Collection library to perform data operations:

import {
  JsonCollection,
  AggregationOptions,
  FindOptions,
} from "@iyulab/json-collection";

// Sample data
const data = [
  { id: 1, name: "Alice", age: 30 },
  { id: 2, name: "Bob", age: 25 },
  { id: 3, name: "Charlie", age: 35 },
  { id: 4, name: "David", age: 40 },
];

// Aggregation example
const aggOptions: AggregationOptions = {
  $match: { age: { $gt: 30 } }, // Filtering: age greater than 30
  $group: { _id: "$age" }, // Grouping by age
  $sort: { age: 1 }, // Sorting by age in ascending order
  $limit: 2, // Limiting to 2 documents
};

const collection = new JsonCollection(data);
const aggResult = collection.aggregate(aggOptions);
console.log(aggResult);

// Find example
const findOptions: FindOptions = {
  $match: { name: { $eq: "Alice" } }, // Filtering: name equals Alice
  $sort: { age: -1 }, // Sorting by age in descending order
  $limit: 1, // Limiting to 1 document
};

const findResult = collection.find(findOptions).toArray();
console.log(findResult);

This will output the processed data based on the provided aggregation options.

Contribution

Contributions are welcome! Please feel free to submit pull requests or open issues to improve the library or add new features.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.