Utility helpers are split across select/utils.js, select/utils/*.js,
select/interaction.js, and select/routing.js. select/utils.js is the
compatibility barrel that re-exports the split utility modules. Search helpers
live in select/utils/search.js as a direct import.
import { add, clsx, next, toggle } from "@./utils.js"
import { Keyboard, bind, drag } from "@./interaction.js"
import { browser } from "@./browser.js"
import { router } from "@./routing.js"
const input = document.querySelector("input")
bind(input, {
keydown: (event) => {
if (Keyboard.Code(event) === Keyboard.Codes.ENTER) {
input.className = clsx("field", { submitted: true })
}
},
})
const routes = router({
"/": () => console.log("home"),
"/users/{id:number}": (_path, { id }) => console.log("user", Number(id)),
})
const state = browser()
state.path.sub((path) => {
routes.run(path)
})
let selection = [{ id: 1 }, { id: 2 }]
selection = toggle(selection, { id: 2 })
selection = add(selection, { id: 3 })
console.log(selection[next(selection, 0, -1)])Compatibility barrel for the split utility modules.
Exports:
itemkey,items,index,find,has,add,remove,toggle,next,wrapindexasText,clsx,iclsx,hi,microtaskcmp,eqasTrue,def,idem,extractor,predicate,memo,pipe,swallowikeys,iitems,iremap,iwalk,ileavesloggersanitize,sanitizer,Sanitizer- text helpers such as
shortdict,shortword,unshortword,re,rescape,sprintf,uid - the remaining split modules (
math,transform,traverse,update,values) sel
Returns item.id ?? item.key ?? item.name ?? item.
Normalizes values into { label, value } entries when needed.
Returns the matching index, or -1.
If key === null, strict identity matching is used.
Alias for index.
Returns true when item is present.
Returns a new array with item appended when absent.
Returns a new array without item when found.
Removes item when present, adds it when absent.
Returns a wrapped index in [0, n).
Low-level circular index helper used by next.
Convenience bundle containing the selection helpers.
Generator that yields normalized class tokens.
Accepted values:
- strings
- arrays, flattened recursively
- objects, where truthy values emit their keys
- numbers
Falsy values are ignored.
[...iclsx("btn", ["primary", null], { active: true, hidden: false })]
// ["btn", "primary", "active"]Returns a space-joined class string from iclsx(...args).
Returns true when value satisfies criteria.
- falsy criteria match everything
- regular expressions test the string form of
value - arrays require all criteria to match
- objects require all enumerable keys to match recursively
- functions are called as predicates
- everything else is matched by strict identity
Returns a matcher that requires all criteria to pass.
Builds a case-insensitive regular expression from text.
ORsplits alternatives- quoted phrases are treated as exact phrases
?expands to an optional whitespace-delimited capture
select/utils/search.js is imported directly instead of through the
compatibility barrel.
Registers { eventName: handler } on a single node or an array of nodes.
Returns the original node.
Removes handlers registered with bind.
Returns the original node.
Starts a drag interaction from a mouse event and returns a cancel function.
move(event, delta)runs onmousemoveend(event, delta)runs onmouseupormouseleave
delta includes dx, dy, ox, oy, isFirst, isLast, step, and context.
drag.target is an alias for dragtarget.
Walks ancestors until it finds data-drag.
- without
name, anydata-dragmatches - with
name, onlydata-drag="name"matches
Returns the first ancestor matching predicate, or undefined.
Auto-resizes a textarea by setting height = auto first, then expanding to
border + scrollHeight.
Keyboard provides event-name constants, key-code constants, and helper methods.
Keyboard.Down:"keydown"Keyboard.Up:"keyup"Keyboard.Press:"press"Keyboard.Codes: Enter, Esc, Tab, arrows, modifiers, and related codesKeyboard.Key(event): returns the key labelKeyboard.Code(event): returns the numeric key codeKeyboard.Char(event): returns a printable character or newline for EnterKeyboard.IsControl(event): true when the key is non-character/control inputKeyboard.HasModifier(event): true when Alt or Ctrl is pressed
Normalizes a string or array into path chunks.
Parses a route expression into strings and RoutePatternSlot values.
Supported slot forms:
{name}: any non-empty chunk{name:number}: numeric chunk{name:alpha}: alphabetic chunk{name:string}: alphanumeric plus_and-{name:<regexp>}: custom regexp source
Wrapper around a regular expression used by dynamic path segments.
Route segment wrapper storing the pattern, parameter name, and position.
Associates a route with a handler, priority, and captured slots.
Tree-based router that stores static and dynamic route handlers.
Methods:
on(expr, handler, priority?, offset?): registers a handleroff(expr, handler?, offset?): unregisters one handler or all handlers for the routematch(path, offset?): returns the handlers at the matched leaf, ornullrun(path, ...args): runs the best matching handler
Selection order for run:
- highest
priority - latest registered when priorities are equal
Handler signature:
(path, captured, ...args) => any
captured maps slot names to matched path chunks.
Creates a Router and registers entries from { "/path": handler, ... }.
Returns a callable dispatcher with .router and .match(path) attached.
browser(options?) returns the shared Browser singleton.
The Browser instance exposes path, query, hash, local, internal,
parse, fetch, and fetched.
Exported browser module symbols are Browser, browser, hash, query, and record.
See browser.md and ref-browser.md for the
browser guide and serializer reference.