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 🙏

© 2025 – Pkg Stats / Ryan Hefner

shiz

v3.0.0

Published

Lazily calculated values

Readme

shiz

values as functions and shit

It's like an observable stream, except instead of a stream of values, it's a stream of changes that you can lazily reify into values.

Originally inspired by observables-as-functions libraries like w0w or PureState or set-state, except that this one is aggressively lazy.

Functions are only re-run when someone asks for the value, as opposed to when a dependency's value changes.

shiz can be used as a Svelte store.

Observable example


const { value, computed } = shiz

const itsAValue = value(5)
const anotherValue = value(3)

const dependentValue = computed(
	{ itsAValue, anotherValue },
	({ itsAValue, anotherValue }) => itsAValue + anotherValue
)

dependentValue.get() // => 8

anotherValue.set(6)
// ^ This marks dependentValue as dirty but doesn't cause it to be re-run

dependentValue.get() // => 11
// ^ This call actually causes dependentValue to be re-run

This aggressively lazy behavior is useful if you have values that depend on large numbers of other values, with many values being changed in a tick.

Like, say, if you're watching the viewport position of hundreds of elements while the user is scrolling around.

To listen for changes:

const someValue = value(4)

someValue.set(3)
someValue.set(2)
someValue.set(1)

someValue.on('change', () => {
	someValue.get() // => 1
})

API

Exports two functions, value and computed.

observableish = value([ value ])

Takes any value and returns an observableish object with a set function that takes a single argument. Call set to change the value.

observableish = computed(dependencies, computeFunction)

Takes two arguments: an object of observableish dependencies, and a function that takes an object of values calculated from those dependencies.

Even if a bunch of upstream dependencies change, the computeFunction won't be called until something calls the get method.


const a = value(1)
function computeFunction({ a }) {
	return a * 2
}
const doubled = computed({ a }, computeFunction)

observableish

An object with these properties:

  • observableish.get(): a function that returns the current value, recalculating it if necessary
  • observableish.map(fn): sugar for computed({ observableish }, ({ observableish: value }) => fn(value))
  • unsubscribe = observableish.subscribe(callback): Calls the callback function whenever the observable value changes. Also calls the callback function with the current value right away when subscribe is called.

It is also a better-emitter emitter that emits these events:

  • change: this is the event you should subscribe to. It will fire in a microtask after any changes happen, allowing you to recalculate values lazily.
  • dirty: this fires every time an upstream value changes. Don't call get every time this event fires, or else you'll cause a lot of extra recalculation.

License

WTFPL