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

cozyobserve

v0.2.2

Published

Super Fast, Lightweight, Simple Observer

Readme

CozyObserve

CozyObserve — Super Fast, Lightweight, Simple Observer

npm Build Size Coverage License Downloads PRs withlove styled with prettier

Currently in preview version

CozyObserve is a lightweight and efficient library for observing changes in objects and primitive values. It provides a simple API to listen to changes and execute callbacks accordingly. It supports both Vanilla JavaScript and React with built-in hooks for seamless integration.

What COZY Stands For

COZY stands for Compact, On-point, Zero-overhead, Yet-powerful.

A fine-tailored ecosystem of TypeScript libraries designed for your everyday needs—lightweight, efficient, and built to get the job done. No bloat, just pure performance. 🚀

Installation

You can install CozyObserve using npm:

npm install cozyobserve

Or using yarn:

yarn add cozyobserve

Vanilla JavaScript / TypeScript Usage

Importing the Library

import {
  Observer,
  ComputeObserver,
  AsyncObserver,
  deepObserver,
} from 'cozyobserve';

Observing a Primitive Value

const observer = new Observer(10);
const unsubscribe = observer.subscribe((newValue, oldValue) => {
  console.log(`Value changed from ${oldValue} to ${newValue}`);
});
observer.set(20); // Triggers the callback

// Unsubscribe when no longer needed
unsubscribe();

Observing Computed Values

const computeObserver = new ComputeObserver(() => Math.random());
const unsubscribeCompute = computeObserver.subscribe((newValue, oldValue) => {
  console.log(`Computed value changed from ${oldValue} to ${newValue}`);
});
computeObserver.update(); // Triggers the callback if value changed
unsubscribeCompute();

Observing an Async Value

const asyncObserver = new AsyncObserver(
  fetch('/api/data').then((res) => res.json())
);
asyncObserver
  .promise()
  .then((value) => console.log('Async value resolved:', value));

Deep Observing an Object

const person = { name: 'Alice', age: 25 };
const { observer, unsubscribe } = deepObserver(person, (newValue, oldValue) => {
  console.log('Object changed:', newValue, oldValue);
});

observer.age = 26; // Triggers the callback
unsubscribe(); // Stop observing

React Usage

CozyObserve provides built-in React hooks to make state management seamless.

Importing React Hooks

import {
  useObserver,
  useComputeObserver,
  useAsyncObserver,
  useDeepObserver,
  Observe,
} from 'cozyobserve';

Using the Component

import { Observe, Observer } from 'cozyobserve';

const count = new Observer(0);

function Counter() {
  return (
    <Observe observer={count}>
      {(value) => (
        <div>
          <p>Count: {value}</p>
          <button onClick={() => count.set(value + 1)}>Increment</button>
        </div>
      )}
    </Observe>
  );
}

Observe is a React component that listens to an Observer and re-renders its child function when the value changes.

It makes it easy to work with observers declaratively inside React components.

Observing a Value with useObserver

import { Observer, useObserver } from 'cozyobserve';

const counter = new Observer(0);

function Counter() {
  const count = useObserver(counter);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => counter.set(count + 1)}>Increment</button>
    </div>
  );
}

Observing Computed Values with useComputeObserver

import { ComputeObserver, useComputeObserver } from 'cozyobserve';

const randomValue = new ComputeObserver(() => Math.random());

function RandomDisplay() {
  const value = useComputeObserver(randomValue);
  return (
    <div>
      <p>Random Value: {value}</p>
      <button onClick={() => randomValue.update()}>Recalculate</button>
    </div>
  );
}

Observing Async Data with useAsyncObserver

import { AsyncObserver, useAsyncObserver } from 'cozyobserve';

const asyncData = new AsyncObserver(
  fetch('/api/data').then((res) => res.json())
);

function AsyncComponent() {
  const data = useAsyncObserver(asyncData);
  return <div>{data ? JSON.stringify(data) : 'Loading...'}</div>;
}

Observing Deep Objects with useDeepObserver

import { deepObserver, useDeepObserver } from 'cozyobserve';

const person = { name: 'Alice', age: 25 };
const deepObservedPerson = deepObserver(person, (newValue) => {
  console.log('Person updated:', newValue);
});

function PersonComponent() {
  const observedPerson = useDeepObserver(deepObservedPerson);
  return (
    <div>
      <p>Name: {observedPerson.name}</p>
      <p>Age: {observedPerson.age}</p>
      <button onClick={() => (observedPerson.age += 1)}>Increase Age</button>
    </div>
  );
}

API Reference

Refer to the API reference in the Vanilla section for method details.

License

MIT License. See the LICENSE file for details.

(Twitter/X: @papa_alpha_papa), (Mastodon: @papa_alpha_papa) (Bluesky: @erginturk.bsky.social)

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.


Developed with ❤️ by M. Ergin Turk

Happy coding with CozyObserve! 🚀