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

dbf-core

v1.0.1

Published

DBF Core: component engine (Web Components) + render + events + props

Readme

DBF Core

DBF Core is a tiny Web Components “engine” that gives you:

  • A DBFComponent base class (state, props, lifecycle)
  • A defineComponent helper for ergonomic component definitions
  • A minimal html + render layer (template strings → shadow DOM)
  • Typed, schema-based props and small utilities

It’s designed to be HTML‑first, framework‑agnostic, and easy to integrate into any stack.


Installation

npm install dbf-core

DBF Core is framework‑agnostic and works anywhere you can register Custom Elements (plain HTML, React, Vue, etc.).


Quick start: define a component

import { defineComponent } from "dbf-core";

interface HelloProps {
  name: string;
}

defineComponent<never, HelloProps>("hello-name", {
  props: { name: "string" } as const,
  render({ props, html }) {
    return html`<p>Hello, ${props.name}!</p>`;
  },
});

// HTML:
// <hello-name name="DBF"></hello-name>

This registers a standard Custom Element <hello-name> that reads its props from the element’s attributes.


State and events

DBF Core lets you combine props + internal state + events in a small, React‑like way.

import { defineComponent, defineProps, type PropsFromSchema } from "dbf-core";

const counterProps = defineProps({
  initial: "number",
} as const);

type CounterProps = PropsFromSchema<typeof counterProps>;

interface CounterState {
  count: number;
}

defineComponent<CounterState, CounterProps>("dbf-counter", {
  props: counterProps,
  state: () => ({ count: 0 }),

  render({ state, props, html }) {
    const value = state.count + (props.initial ?? 0);

    return html`
      <button data-action="inc">Count: ${value}</button>
    `;
  },

  mount({ root, on, setState, host }) {
    on(root, "click", "[data-action='inc']", () => {
      setState({ count: host.state.count + 1 });
    });
  },
});

Key ideas:

  • state is initialized once per instance via state: () => ({ ... }).
  • render is called whenever state/props change.
  • mount runs once after the component is attached; you typically use it for event delegation via on(root, "click", "[data-action='inc']", handler).
  • setState accepts a partial object or a function: setState(prev => ({ count: prev.count + 1 })).

Per-component styles

DBF Core supports a styles field so you can inject styles into each component’s shadow root. With Vite (or similar bundlers) you can use ?inline to import CSS as a string.

import { defineComponent, defineProps, type PropsFromSchema } from "dbf-core";
import cardStyles from "./card.css?inline";

const cardProps = defineProps({
  title: "string",
  description: "string",
  imageUrl: "string",
} as const);

type CardProps = PropsFromSchema<typeof cardProps>;

defineComponent<never, CardProps>("dbf-card", {
  props: cardProps,
  styles: cardStyles,
  render({ props, html }) {
    return html`
      <div class="card">
        <img src="${props.imageUrl}" alt="${props.title}" />
        <h2>${props.title}</h2>
        <p>${props.description}</p>
      </div>
    `;
  },
});

This keeps your styles scoped to the component via shadow DOM, and avoids leaking global CSS.


Typed props with defineProps + PropsFromSchema

To avoid duplicating prop definitions in both runtime and TypeScript types, DBF Core exposes a small props helper:

import { defineProps, type PropsFromSchema } from "dbf-core";

const inputProps = defineProps({
  placeholder: "string",
  type: "string",
} as const);

type InputProps = PropsFromSchema<typeof inputProps>;
  • defineProps defines the runtime schema.
  • PropsFromSchema infers the TypeScript type (placeholder: string; type: string;).

You can then plug inputProps directly into defineComponent’s options.


Relationship with the demo app

The apps/demo application in this repository:

  • Registers several DBF Core components (cards, inputs, stats, etc.).
  • Demonstrates page composition (a landing page built from custom elements).
  • Integrates with dbf-router to show client‑side navigation.

It’s a good reference if you want to see how DBF Core is intended to be used in practice.