Utilities
Small, stable helpers under devframe/utils/* — bundled in, no npm install.
Reference
devframe/utils/colors
Terminal ANSI colors.
import { colors as c } from 'devframe/utils/colors'
console.log(c.green('Server ready'))
console.log(c.cyan`listening on port ${port}`)
console.log(`${c.bold(c.red('fatal:'))} something went wrong`)Exports colors (blue, cyan, gray, green, red, yellow, bold, dim, reset, underline).
devframe/utils/open
Open a URL, file, or target in the OS handler.
import { open } from 'devframe/utils/open'
await open('https://localhost:7777')
await open('./report.html', { wait: true })devframe/utils/launch-editor
Open a file in the editor. Target accepts file, file:line, or file:line:column; an editor command (e.g. 'code') overrides auto-detection.
import { launchEditor } from 'devframe/utils/launch-editor'
launchEditor('src/main.ts:42:7')
launchEditor('src/main.ts:42:7', 'code')Auto-detection reads LAUNCH_EDITOR, else defaults; most use the openInEditor recipe (Common RPC Functions).
devframe/utils/hash
Deterministic hash of any structured-cloneable value.
import { hash } from 'devframe/utils/hash'
const key = hash({ functionName, args })devframe/utils/structured-clone
JSON-safe structured-clone serialization; round-trips Map, Set, Date, BigInt, cycles, class instances.
import {
structuredCloneDeserialize,
structuredCloneParse,
structuredCloneSerialize,
structuredCloneStringify,
} from 'devframe/utils/structured-clone'
const wire = structuredCloneStringify(new Map([['a', 1]]))
const value = structuredCloneParse<Map<string, number>>(wire)devframe/utils/nanoid
URL-safe random ID generator (vendored, zero-dep).
import { nanoid } from 'devframe/utils/nanoid'
nanoid() // 21 chars
nanoid(10) // 10 charsdevframe/utils/crypto-token
Cryptographically-secure token helpers on WebCrypto (browser + Node).
import { randomDigits, randomToken, timingSafeEqual } from 'devframe/utils/crypto-token'
randomToken() // 32-char hex, 128 bits of entropy — use as a bearer token
randomDigits(6) // '047204' — uniform, leading zeros preserved
timingSafeEqual(input, secret) // constant-time string comparisondevframe/utils/events
Typed event emitter.
import { createEventEmitter } from 'devframe/utils/events'
const events = createEventEmitter<{ change: (n: number) => void }>()
const off = events.on('change', n => console.log(n))
events.emit('change', 42)
off()devframe/utils/shared-state
The immutable state container behind ctx.rpc.sharedState (Shared State); usable outside the host.
import { createSharedState } from 'devframe/utils/shared-state'
const state = createSharedState({ initialValue: { count: 0 } })
state.mutate((draft) => {
draft.count += 1
})
state.value() // { count: 1 }devframe/utils/streaming-channel
Sink/reader primitives for streamed RPC payloads, via ctx.rpc.streaming — see Streaming.
devframe/utils/when
Statically-validated when-clause expressions for conditional visibility; runtime + types ship here, consumer when fields are kit-side (see When Clauses).
Why a utils/* subpath
The utilities are stable wrappers, not bare re-exports, so devframe can swap implementations freely.