Lightweight library that works with vanilla DOM elements and provides fine-grained reactivity + utils for building websites.
A signature for a subscriber function.
Represents a Node-style callback function that receives either an error or a result.
Represents a function that accepts a callback as its first argument, followed by any other arguments.
Converts a function that returns a Promise into a function that accepts a Node-style callback.
CfDom provides a configurable interface for core DOM operations.
Arg for insert()
.
Empties a DOM element of its content.
a simple HTML sanitizer. Escapes &
, <
, >
, '
, and "
by
replacing them with their corresponding HTML escapes
(&
,>
, <
, '
, and "
).
A signature for a subscriber of a specific event.
Takes an existing element and modifies its properties. Refer ElementProperties documentation for details on what can be changed.
Creates an HTML string with automatic escaping of interpolated values. Use r() to prevent escaping specific values.
Returns a function that generates random alphanumeric IDs with an optional prefix. Each generated ID is unique within the scope of the returned function.
Inserts an element into the DOM given a reference element and the relative position of the new element.
Renders a mustache template with the provided context data.
Element creation/build helper. Creates a new DOM element (optionally with tag, id, and classes) and returns a chainable NuBuilder for ergonomic Campfire props and child/slot/reactivity management.
Fires a callback when the DOMContentLoaded event fires.
Repeatedly executes a function at specified intervals.
Prevent values from being escaped by html``.
Removes elt
from the DOM.
Queries the DOM for a particular selector, and returns the first element matching it.
Generates a range of numbers as an array, similar to Python's range()
.
The primitive observable container. Store is the base class for all reactive state in Campfire.
Flexible reactive store creator.
The function signature for a function returned by template()
.
Creates a reusable template function from a mustache template string.
Track an element by an arbitrary string id. This is essentially a global key-value store of elements you'd like to keep around.
Retrieve a tracked element by its id. Will return null if an element corresponding to a given id is not found.
Unescapes the output of escape() by replacing &
, >
, <
,
'
, and "
with &
, <
, >
, '
, and "
respectively.
Stop tracking an element that was previously tracked by track()
. If you're
calling track for thousands of elements it's probably a good idea to untrack
them when you're done.
Like nu()
, but for existing elements—make any element reactive and
ergonomic.