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

ts-refs

v0.0.11

Published

Create a reference object that can be monitored.

Readme

Ref

Create a reference object that can be monitored.

npm

Browser support

| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on iOS | Samsung Internet | WebView Android | Deno | Node.js | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 1 | 12 | 1.5 | 9.5 | 3 | 18 | 4 | 10.1 | 1 | 1.0 | 37 | 1.0 | 0.10.0

Install

npm i ts-refs

Usage

Refs

  • Create

    • typescript

      import Refs from "ts-refs";
      
      const refs = new Refs();
      
      // Set cache storage.
      refs.setLocalStorage(localStorage);
      refs.setSessionStorage(sessionStorage);
    • javascript

      ref.min.js

      <script type="application/javascript" src="ref.min.js"></script>
      <script type="application/javascript">
      
          var refs = new RefModule.default();
      
          // Set cache storage.
          refs.setLocalStorage(localStorage);
          refs.setSessionStorage(sessionStorage);
      </script>

Value Ref

  • Create

    const valueRef = refs.of(0); // RefValue<number>
  • get

    valueRef.get(); // 0
  • set

    valueRef.set(1);
  • listen

    valueRef.listen((value)=>{
        // TODO
    },this);
  • interrupt Interrupt Ref listen by target.

    valueRef.interrupt(this);
  • clear

    Reset to default value.

    valueRef.clear();

Computed Ref

Save the computed results. Recompute when Ref changes.

  • Create

    const valueRef = refs.of(0); 
    const computedRef = refs.ofComputed(()=>{
        return valueRef.get()+1;
    }); // RefComputed<number>
  • get

    Changed by dependent on other Ref.

    computedRef.get(); // 0+1
  • listen

    Change by o

    computedRef.listen((value)=>{
        // TODO
    },this);
  • interrupt Interrupt ref listen by target.

    computedRef.interrupt(this);
  • clear

    Clear computed results.

    computedRef.clear();

Cache Ref

Cache the last value in storage.

  • Create

    const valueRef = refs.ofCache({
        name:'string'
        , local:false // switch storage type
        , value: 0
    }); // RefCache<number>
  • get

    valueRef.get(); // 0
  • set

    valueRef.set(1);
  • listen

    valueRef.listen((value)=>{
        // TODO
    },this);
  • interrupt Interrupt Ref listen by target.

    valueRef.interrupt(this);
  • clear

    Reset to default value.

    valueRef.clear();

Advanced

Refs

  • off

    Remove all dependencies and listener by scope.

    refs.off(this);
  • runInScope

    let a = {};
    refs.runInScope(()=>{
        // The default scope for all operations is `a`.
        ref1.listen(()=>{});
        ref2.listen(()=>{});
        ref3.listen(()=>{});
    },a);
  • tx

    Post notifications after processing all Ref updates.

    refs.tx(()=>{
        ref1.set(...)
        ref2.set(...)
        ref3.set(...)
    });