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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pandata

v1.1.0

Published

A universal data substrate that can be declaratively specialized.

Readme

pandata

Canonical URL: https://alexstevovich.com/a/pandata-nodejs
Software URL: https://midnightcitylights.com/software/pandata-nodejs

A Node.js package for managing and manipulating JSON data in memory. This package allows you to easily load, filter, remove, and sort JSON data, providing a simple in-memory data manager for small datasets.


Installation

npm install pandata

Example

import PanData from 'pandata';

const data = new PanData();

// Load data from a JSON file
await data.loadJson('./data.json');

// Get all items
console.log(data.getAll());

// Get items by key-value pair
console.log(data.getByKeyValue('status', 'active'));

// Get the first item by key-value pair
console.log(data.getFirstByKeyValue('id', 1));

// Remove items by key-value pair
data.removeByKeyValue('status', 'inactive');

// Bubble through all items and apply a function
data.bubble((item) => {
    console.log(item);
});

// Use delegate methods for more flexible filtering
const getByStatus = data.delegateGetAllByKey('status');
console.log(getByStatus('active'));

const getFirstById = data.delegateGetFirstByKey('id');
console.log(getFirstById(1));

const getSortedByDate = data.delegateAllByKeySorted('date');
console.log(getSortedByDate(true)); // Sorted in ascending order

API

parse(text)

Parses JSON data from a string and returns an object containing the parsed data and the content.

| Parameter | Type | Description | | --------- | ------ | --------------------------------------- | | text | string | The full text containing the JSON data. |

Returns: { data: object, content: string }

Throws an error if the input is not a string or if the JSON format is invalid.


serialize(data, content)

Serializes the data and content into a formatted JSON string.

| Parameter | Type | Description | | --------- | ------ | --------------------- | | data | object | The JSON data. | | content | string | The document content. |

Returns: string - The formatted JSON string.

Throws an error if data is not an object or content is not a string.


clear()

Clears the current items in the data store.

Returns: this - The instance itself for chaining.


getAll()

Gets all items in the data store.

Returns: array - All items.


getByKeyValue(key, value)

Gets items by key-value pair.

| Parameter | Type | Description | | --------- | ------ | ------------------------------- | | key | string | The key to filter by. | | value | string | The value to match for the key. |

Returns: array - Items matching the key-value pair.


getFirstByKeyValue(key, value)

Gets the first item by key-value pair.

Returns: object - The first matching item.


removeByKeyValue(key, value)

Removes items by key-value pair.

Returns: this - The instance itself for chaining.


bubble(fn)

Applies a function to each item in the data store.

Returns: this - The instance itself for chaining.


delegateGetAllByKey(key)

Delegates filtering items by a specific key.

Returns: function - A function to call with a value for filtering by key.


delegateGetFirstByKey(key)

Delegates finding the first item by a specific key.

Returns: function - A function to call with a value for finding the first matching item.


delegateAllByKeySorted(key)

Delegates sorting items by a specific key.

Returns: function - A function to call with an optional boolean to sort in ascending or descending order.


Notes

  • This package is useful for managing and manipulating small sets of JSON data.
  • Minimal and dependency-free.
  • Can be used for various in-memory data handling tasks, including filtering, sorting, and delegating operations.

License

Licensed under the Apache License 2.0.