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

@dikolab/private-parts

v0.7.1

Published

WeakMap storage for private data accessible by object instance and key string

Readme

Private Parts

npm version license

A simplified alternative to #private fields and WeakMap patterns for storing private instance data.

Why

JavaScript offers two built-in ways to keep data private on class instances:

  • #private fields — work well for simple cases but don't support dynamic keys, don't interoperate with decorators or mixins, and are difficult to inspect in tests.
  • WeakMap per property — flexible and garbage-collection-friendly but requires boilerplate to set up, track keys, and clean up.

@dikolab/private-parts wraps the WeakMap approach behind a minimal API — get, set, clear, clearAll, and createStore — so you get the benefits of WeakMap-based privacy without the plumbing.

Platform Support

Platform agnostic. Runs in Node.js and browsers. Ships four output formats:

| Format | File | Use case | |--------|------|----------| | CJS | lib/index.cjs | Node.js require() | | ESM | lib/index.mjs | Bundlers, Node.js import | | UMD | lib/index.umd.js | Browsers, <script> tags | | TypeScript | src/index.ts | Deno |

Installation

npm install @dikolab/private-parts

Usage

Basic key-value storage

import { set, get } from '@dikolab/private-parts';

const instance = {};
const value = 'My value';

set(instance, 'my-key', value);

console.log(get(instance, 'my-key') === value);
// true

Class private properties

import { get, set } from '@dikolab/private-parts';

class MyProfile {
   get name(): string {
      return get(this, 'name');
   }

   constructor(name: string) {
      set(this, 'name', name);
   }
}

Clearing instance data

import { clear, get } from '@dikolab/private-parts';

const myProfile = new MyProfile('test');

clear(myProfile);

console.log(get(myProfile, 'name'));
// undefined

Resetting all data (testing)

import { describe, beforeEach } from 'vitest';
import { clearAll } from '@dikolab/private-parts';

describe('Reset something!', () => {
   beforeEach(() => {
      clearAll();
   });
});

Global Store vs Isolated Store

By default, get, set, clear, and clearAll operate on a single global store shared across the entire application. This is convenient but means unrelated modules can collide if they use the same property names on the same instance.

createStore() returns a ContextualPrivatePartManager — an isolated store with the same .get(), .set(), .clear(), and .clearAll() methods but backed by its own independent storage. Data in one store is invisible to every other store.

When to use each

| Approach | Best for | |----------|----------| | Global (get, set) | Simple cases — a single class or module managing its own private data | | Isolated (createStore()) | Libraries, plugins, or multi-module systems where storage must not leak between concerns |

Isolation in practice

import {
   get,
   set,
   createStore,
} from '@dikolab/private-parts';

const storeA = createStore();
const storeB = createStore();
const obj = {};

// Each store is independent
set(obj, 'key', 'global');
storeA.set(obj, 'key', 'store-A');
storeB.set(obj, 'key', 'store-B');

console.log(get(obj, 'key'));
// 'global'
console.log(storeA.get(obj, 'key'));
// 'store-A'
console.log(storeB.get(obj, 'key'));
// 'store-B'

Scoped class using an isolated store

import { createStore } from '@dikolab/private-parts';

const store = createStore();

class Wallet {
   get balance(): number {
      return store.get(this, 'balance') ?? 0;
   }

   deposit(amount: number) {
      store.set(
         this,
         'balance',
         this.balance + amount,
      );
   }

   withdraw(amount: number) {
      store.set(
         this,
         'balance',
         this.balance - amount,
      );
   }
}

Because store is module-scoped, no external code can read or modify Wallet's private data — even if it imports get from @dikolab/private-parts and tries the same property name on the same instance.

API

| Function | Description | |----------|-------------| | get(instance, propertyName) | Retrieve a private value | | set(instance, propertyName, value) | Store a private value | | clear(instance) | Remove all private data for an instance | | clearAll() | Remove all private data from the global store | | createStore() | Create an isolated private data store |

Release Notes

License

ISC