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

@blac/core

v2.0.5

Published

> ⚠️ **Warning:** This project is currently under active development. The API may change in future releases. Use with caution in production environments.

Readme

@blac/core

⚠️ Warning: This project is currently under active development. The API may change in future releases. Use with caution in production environments.

Core state management library implementing the BloC pattern for TypeScript applications.

Installation

npm install @blac/core
# or
pnpm add @blac/core
# or
yarn add @blac/core

Core Concepts

Cubit

Simple state container with direct state emission. Use when you need straightforward state updates.

import { Cubit } from '@blac/core';

class CounterCubit extends Cubit<{ count: number }> {
  constructor() {
    super({ count: 0 });
  }

  increment() {
    this.emit({ count: this.state.count + 1 });
  }

  decrement() {
    this.update((state) => ({ count: state.count - 1 }));
  }

  reset() {
    this.patch({ count: 0 });
  }
}

Registry API

Manage state container instances with the registry functions:

import { acquire, release, borrow, hasInstance, clear } from '@blac/core';

// Acquire an instance (creates if needed, increments ref count)
const counter = acquire(CounterCubit);

// Release when done (decrements ref count, disposes when 0)
release(CounterCubit);

// Borrow without affecting ref count
const instance = borrow(CounterCubit);

// Check if instance exists
if (hasInstance(CounterCubit)) {
  // ...
}

// Clear a specific class
clear(CounterCubit);

// Clear all instances
clearAll();

Decorators

Use the @blac decorator to configure container behavior:

import { Cubit, blac } from '@blac/core';

@blac({ isolated: true }) // Each consumer gets its own instance
class FormCubit extends Cubit<FormState> {}

@blac({ keepAlive: true }) // Never auto-dispose
class AuthCubit extends Cubit<AuthState> {}

@blac({ excludeFromDevTools: true }) // Hide from DevTools
class InternalCubit extends Cubit<State> {}

Utilities

waitUntil

Wait for a specific state condition:

import { waitUntil } from '@blac/core';

const counter = acquire(CounterCubit);

// Wait until count reaches 10
await waitUntil(counter, (state) => state.count >= 10);

// With timeout
await waitUntil(counter, (state) => state.count >= 10, {
  timeout: 5000,
});

watch

Create computed values that react to state changes:

import { watch, instance } from '@blac/core';

class DashboardCubit extends Cubit<DashboardState> {
  constructor() {
    super({ items: [] });

    // Watch another bloc's state
    watch(
      instance(UserCubit),
      (userState) => userState.preferences,
      (preferences) => this.onPreferencesChanged(preferences),
    );
  }
}

Plugins

Extend functionality with plugins:

import { getPluginManager, type BlacPlugin } from '@blac/core';

const loggingPlugin: BlacPlugin = {
  name: 'logging',
  onStateChange: (container, prevState, newState) => {
    console.log(`[${container.constructor.name}]`, prevState, '->', newState);
  },
};

getPluginManager().register(loggingPlugin);

Configuration

Configure global behavior:

import { configureBlac } from '@blac/core';

configureBlac({
  devMode: import.meta.env.DEV,
});

API Reference

State Containers

| Class | Description | | ------------- | ----------------------------------------------------------- | | Cubit<S, P> | Simple state container with emit(), update(), patch() |

Registry Functions

| Function | Description | | -------------------------------- | ------------------------------------------- | | acquire(Class, key?, options?) | Get or create instance, increment ref count | | release(Class, key?) | Decrement ref count, dispose when 0 | | borrow(Class, key?) | Get instance without affecting ref count | | borrowSafe(Class, key?) | Borrow or return undefined | | ensure(Class, key?, options?) | Acquire without incrementing ref count | | hasInstance(Class, key?) | Check if instance exists | | getRefCount(Class, key?) | Get current reference count | | clear(Class) | Remove all instances of a class | | clearAll() | Remove all instances |

Exports

// Core classes
export { Cubit } from '@blac/core';

// Registry
export {
  acquire,
  release,
  borrow,
  ensure,
  hasInstance,
  clear,
  clearAll,
} from '@blac/core';

// Utilities
export { waitUntil, watch, instance } from '@blac/core';

// Decorators
export { blac } from '@blac/core';

// Plugin system
export { getPluginManager, type BlacPlugin } from '@blac/core';

// Configuration
export { configureBlac, getBlacConfig, isDevMode } from '@blac/core';

License

MIT