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

@streetui/context

v2.7.0

Published

StreetUI context — build-time provider/consumer scoping with nearest-provider resolution

Downloads

2,551

Readme

@streetui/context

Minimal build-time provider/consumer scoping for the StreetUI DSL. This is not a re-implementation of React Context and it is not a second reactive system — it is a tiny synchronous value stack that mirrors how StreetUI builds its semantic tree.

# part of the StreetUI monorepo — no separate install

Why it exists

StreetUI builds its semantic tree synchronously, top-down, when the DSL builders run. A Context mirrors that shape exactly: provide(value, run) pushes a value for the duration of the synchronous run() — during which the child DSL builders execute and may consume() — then pops it again. This lets deeply nested field helpers reach a shared form, an i18n instance, a theme, or any other ambient value without prop drilling, while staying entirely inside the existing build pass.

Because provide() pops its value as soon as run() returns (even if it throws), the context holds no subscriptions and leaves no references behind. If you need reactivity, put a signal into the context — reactivity then belongs to that signal and is torn down by the normal node lifecycle when the consuming subtree unmounts.


API

import { createContext, type Context } from '@streetui/context';

const context = createContext<T>(defaultValue, 'optional.debug.description');

| Member | Description | |---|---| | context.provide(value, run) | Provide value to any consume() made synchronously inside run; returns run's result. | | context.consume() | Read the nearest active provider's value, or defaultValue when none is active. | | context.hasProvider() | True while at least one provider is active. | | context.defaultValue | The value consume() returns with no active provider. | | context.id | A unique symbol identity (handy for debugging/inspection). |

The default value is required, so consume() always returns a T — never undefined unless T itself permits it.


Example — sharing a form down to field helpers

import { createContext } from '@streetui/context';

interface FormScope { form: Form<SignupValues>; i18n: AccountI18n; }
const FormContext = createContext<FormScope | null>(null, 'streetui.account.form');

function textField(scope: ContainerDSL, name: keyof SignupValues & string) {
  const scoped = FormContext.consume();
  if (scoped === null) throw new Error('textField must run inside a FormContext provider');
  const { form, i18n } = scoped;
  const field = form.field(name);
  scope.input({ bind: field.value });
}

// Provider wraps the synchronous builder run:
page.form('signup', (fb) => {
  FormContext.provide({ form, i18n }, () => {
    textField(fb, 'name');
    textField(fb, 'email');
    textField(fb, 'password');
  });
});

Nested providers resolve nearest

const Theme = createContext('light');

Theme.provide('dark', () => {
  Theme.consume();                       // 'dark'
  Theme.provide('high-contrast', () => {
    Theme.consume();                     // 'high-contrast' (nearest wins)
  });
  Theme.consume();                       // 'dark' again — inner value popped
});
Theme.consume();                          // 'light' (the default)

Reactive context

The value can be a signal (or an object holding signals). The context stores the reference; the signal owns the reactivity:

const Locale = createContext(signal('en'));

Locale.provide(signal('fr'), () => {
  const locale = Locale.consume();       // Signal<string>
  page.text(locale);                     // reactive — re-renders when the signal changes
});

Consume only inside a provider's synchronous run(). Consuming later (e.g. from an async callback that runs after provide() has returned) resolves to the default, by design — the value has already been popped.