TypeScript utility library - foundational utilities with no UI dependencies
fuz_util (@fuzdev/fuz_util) provides core TypeScript utilities used across the
@fuzdev ecosystem. It has no UI framework dependencies (no Svelte) and
focuses on pure TypeScript helpers.
For coding conventions, see the fuz-stack skill.
gro check # typecheck, test, lint, format check (run before committing)
gro typecheck # typecheck only (faster iteration)
gro test # run tests with vitest
gro gen # regenerate .gen files
gro build # build the package for productionIMPORTANT for AI agents: Do NOT run gro dev - the developer will manage the
dev server.
fuz_util is a foundational utility library:
- Pure TypeScript utilities (string, array, object, async, etc.)
- Zod schemas for common data structures (
PackageJson) - Svelte preprocessor helpers (type-only Svelte dependency, no runtime dep)
- No UI components
- Used by gro (build tools) and fuz (UI/stack)
array.ts- array manipulation helpersobject.ts- object utilitiesstring.ts- string manipulationjson.ts- JSON helpersmap.ts- Map utilitiesiterator.ts- iterator helpersbytes.ts- binary data conversion (to_bytes)hex.ts- hex encoding (to_hex)hash_blake3.ts- BLAKE3 hashing (hash_blake3, sync, 64-char hex, via@fuzdev/blake3_wasm)hash.ts-hash_sha256(Web Crypto SHA-256, async),hash_insecure(DJB2 for non-security uses)
async.ts- async utilities (wait, concurrent operations, Deferred pattern)time.ts- high-resolution timing, measurement, and formattingthrottle.ts- throttle/debounce with configurable edge behaviortimings.ts- performance timing
Key exports: map_concurrent, each_concurrent (concurrency-limited async),
create_deferred (Deferred pattern), throttle with when option
('leading' | 'trailing' | 'both').
Benchmarking library with nanosecond precision timing, comprehensive statistics
(mean, median, percentiles, outlier detection, confidence intervals), and
multiple output formats (table(), markdown(), summary(), json()).
Workflow:
npm run benchmark # Run and compare against baseline
npm run benchmark:save # Save new baseline (after intentional changes)
npm run benchmark_slugify # Run individual benchmark
npm run benchmark_deep_equal # Run individual benchmarkBaseline stored in src/benchmarks/baseline.json (committed to repo).
See docs/benchmark.md for full documentation.
-
types.ts- TypeScript utility types (Flavored, Branded, union helpers) -
package_json.ts-PackageJsonZod schema with gro extensions (glyph, logo, tagline, etc.) -
source_json.ts-SourceJson,ModuleJson,DeclarationJsonZod schemas for.well-known/src.jsonmetadata -
library_json.ts-LibraryJsoncombining package.json + source metadata -
result.ts- Result type pattern -
error.ts- error utilities (UnreachableError,unreachableassertion) -
args.ts- CLI argument parsing with Zod validation -
types.ts-Flavored(loose nominal typing, no cast needed) andBranded(strict, requires cast) for type-safe IDs -
result.ts-Result<T, E>discriminated union withunwrap()helper -
args.ts-args_parse()for CLI arguments with Zod schemas, supports aliases,--no-flagnegation, boolean coercion
zod.ts- Zod schema introspection for CLI help generation (extracting descriptions, defaults, aliases, type strings, properties from Zod schemas)
-
process.ts- process/spawn helpers with typed results -
fetch.ts- fetch utilities with caching, rate limit detection, ETag support -
fs.ts- file system utilities (fs_exists,fs_empty_dir,fs_search) -
path.ts- path utilities -
git.ts- git operations -
log.ts- hierarchical logging system -
process.ts-spawn()withkind-discriminated results (SpawnResultExited,SpawnResultSignaled,SpawnResultError); narrow withresult.kind === ... -
log.ts-Loggerclass with hierarchical children, auto-detects level fromPUBLIC_LOG_LEVELenv var
stats.ts- statistical functions (mean, median, std_dev, percentiles, outlier detection)
testing.ts- shared vitest assertions (assert_propertyfor narrowing discriminated unions by a literal property value,assert_rejectsfor async rejection matching,create_mock_loggerfor aLogger-compatiblevi.fn()mock with per-level call tracking). Only depends on vitest.
svelte_preprocess_helpers.ts- shared helpers for Svelte preprocessors (AST utilities, import management, string escaping). Usesimport typefromsvelte/compilerfor types only — no runtime Svelte dependency. Used bysvelte_preprocess_mdz(fuz_ui) andsvelte_preprocess_fuz_code(fuz_code).
-
random.ts,random_alea.ts- random number generation -
colors.ts- color utilities -
maths.ts- math helpers -
id.ts- ID generation -
counter.ts- counter utilities -
dom.ts- DOM utilities (isomorphic) -
deep_equal.ts- deep equality with security features (constructor comparison, prototype pollution protection) -
function.ts- function utilities (noop,identity, Thunk pattern) -
regexp.ts- regex helpers -
url.ts- URL utilities -
print.ts- formatted output with colors -
function.ts-Thunk<T>type andunthunk()for lazy evaluation
snake_casefor most identifiers (files, variables, functions) instead of camelCasePascalCasefor types, classes, and Svelte components- explicit file extensions in imports
- tab indentation, 100 character width
- no re-exports - import directly from the source module (e.g., import baseline
functions from
benchmark_baseline.js, not frombenchmark.js) - no backwards compatibility preservation - breaking changes are acceptable
Logger level: Set PUBLIC_LOG_LEVEL environment variable to control logging:
PUBLIC_LOG_LEVEL=debug gro devLevels: off, error, warn, info, debug. Defaults to info in
production, debug in development.
Timer auto-detection: timer_default from time.ts automatically selects:
timer_node(nanosecond precision viaprocess.hrtime.bigint()) in Node.jstimer_browser(millisecond precision viaperformance.now()) in browsers
Note: Browser timing is coarsened due to Spectre/Meltdown mitigations.
- UI components (use fuz_ui)
- Svelte-specific UI code (use fuz_ui; preprocessor helpers are here)
- Build tooling (use gro)
- CSS utilities (use fuz_css)
- UI helper functions for source_json (use fuz_ui's helpers)
- TypeScript strict mode
- Prettier with tabs, 100 char width
- Node >= 22.15
- Tests in
src/test/(not co-located) - No runtime Svelte dependency (
svelte_preprocess_helpers.tsuses type-only imports)