Fast.Utils runtime contract
Runtime and package contract
- Runtime platforms: ES2022 modern browsers, WebViews, Vue 3 applications, and uni-app.
- Package format: one public named-export ESM entry for package managers and one separately minified IIFE entry for CDN use; CommonJS and UMD are not shipped.
- CryptoJS-backed compatibility hashes and AES are bundled into both JavaScript artifacts; consumers do not resolve
crypto-jsCommonJS subpaths, and the independent crypto module remains tree-shakeable. - Framework boundary: Vue remains external to the package-manager build and is a required peer in
^3.5.11. - Vue browser composables: event and observer helpers use native platform APIs, return manual stop handles where exposed, and clean up automatically with the current Vue scope. Window size and breakpoints use
0/falseoutside browsers;useNowreturns a non-updating initial Date during SSR. - uni-app boundary: platform APIs resolve the runtime-injected
uniand App-Plusplusidentifiers at call time, withglobalThisproperty fallbacks. The first Storage operation, or an earlierconfigureStorage({ prefix })call, uses the detected synchronous Storage API. - Browser storage: applications import
LocalandSessiondirectly;configureStorage()is needed only to override defaults before the first operation. - Storage operation overrides:
set/get({ crypto })select JSON or Base64 for one operation without mutating global configuration. The v3 envelope does not identify its codec, so callers must use matching options for the same entry. - Storage read typing:
get<Value = string>()defaults tostring | undefinedwhen no generic is supplied; codecs still restore the original runtime JSON value. - Stateful browser defaults: Storage, Identity, and default Logger configuration are page-global by design. Storage and Identity reject conflicting reconfiguration;
configureLoggerreplaces the default Logger configuration while preserving the exported facade reference. - Randomness: every random generation entry prefers Web Crypto and falls back to
Math.random()when unavailable. - Publishing: the repository root is the only package,
dist/is the only build output, andpackage.json#exportsis the complete public path whitelist.
Importing a module does not itself read window, browser Storage, or uni, so unsupported platform capabilities fail only when the corresponding API is called.
Public API policy
- Stateless Array, Date, String, Number, Object, Base64, Color, DOM, Env, Async, and Crypto capabilities use named exports.
- The public API uses named functions instead of mutable aggregate utility objects.
- Base64 and Crypto text decoders return primitive strings typed as
DecodedText. They can be used directly as strings; an explicit.parseJson<T = any>()call attempts JSON parsing and falls back to the original string for invalid JSON. The first text decode lazily installs a non-enumerableString.prototype.parseJsonand rejects a foreign same-name property instead of overwriting it. Storage codecs continue to parse JSON automatically and strictly. - Stateful browser capabilities use cohesive package-owned objects:
Local,Session,installationIdentity, and Logger instances. Logger exposes the matchingdebug,log,warn, anderrorlevels, defaults to thedebugminimum, and receives scope on each method rather than storing it in child instances.createLoggerreturns isolated instances, whileconfigureLoggeronly changes the defaultloggerfacade. - Internal adapters and client factories are implementation details and are not public export paths.
