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 🙏

© 2026 – Pkg Stats / Ryan Hefner

flat-pair

v1.3.0

Published

Using array to save pairs. Serializable and easier to find, locate by value. Provide static methods, use it at 0 cost!

Downloads

6

Readme

flat-pair

npm version npm downloads License: MIT Codacy Badge

A lightweight TypeScript library for storing key-value pairs using arrays. Provides serializable storage with efficient value-based lookups and zero-cost static methods.

For more awesome packages, check out my homepage💛

Features

  • 🔍 Bidirectional Search: Find keys by values and values by keys
  • 📦 Serializable: Easy JSON serialization/deserialization
  • 🛡️ Type Safe: Full TypeScript support with generic types
  • 🎯 Zero Cost: Static methods available for minimal overhead
  • Lightweight: No dependencies, minimal bundle size
  • 🌲 Native Behavior: forEach, find acts like they are in Array. Equality check uses SameValueZero

Installation / Import

npm install flat-pair
# or
pnpm install flat-pair
import { FlatPair, FlatPairOperator, add, get, find ...others } from 'flat-pair';

Quick Start

FlatPair Class

FlatPair is a container class has an items array, it has methods that wrap the static functions for easier usage.

// userId - detail pair
const pairs = new FlatPair<number, Detail>();
pairs.add(1, { name: 'Alice', age: 30 }); // won't change value when key exists
pairs.set(2, { name: 'Bob', age: 25 });
pairs.remove(1);
pairs.find((value, key) => value.age > 20);

Using Static Functions (Zero Cost)

const items: any[] = [];

// Add items
add<string, string>(items, 'name', 'John');
add<string, number>(items, 'age', 12);

// Remove and other operations
remove(items, 'age'); // returns true
console.log(size(items)); // 1
clear(items); // empties the array

Using FlatPairOperator Class (For fixed type hint)

If you don't want to specify the generic types every time you call a static function, you can use FlatPairOperator which wraps the static functions with fixed generic types.

import { FlatPairOperator } from 'flat-pair';

const operator = new FlatPairOperator<string, number>();
const items: any[] = [];

operator.add(items, 'score', 100); // operator's add method is always typed
operator.add(items, 'level', 5);

console.log(operator.get(items, 'score')); // 100
console.log(operator.getByValue(items, 5)); // 'level'

Performance

FlatPair uses a simple array structure [key1, value1, key2, value2, ...] which provides:

  • Memory Efficiency: No object overhead per pair
  • Serialization: Direct JSON support
  • Cache Friendly: Contiguous memory layout
  • Predictable: O(n) operations with low constant factors

Note: For large datasets, consider using a Map or Object for O(1) lookups instead of this package.

License

MIT © Kasukabe Tsumugi