@bunary/core
Foundation module for the Bunary framework: configuration, environment helpers, and shared utilities.
Installation
bun add @bunary/core
Usage
Environment Variables
import { env, isDev, isProd, isTest } from "@bunary/core";
const port = env("PORT", 3000); // number
const debug = env("DEBUG", false); // boolean
const name = env("APP_NAME", "myapp"); // string
if (isDev()) {
console.log("Running in development mode");
}
Configuration
createConfig() returns an instance-scoped store, not the resolved config object. Use configStore.get() in app code to read the resolved config.
import { createConfig, defineConfig } from "@bunary/core";
export const configStore = createConfig(
defineConfig({
app: {
name: "MyApp",
env: "development",
debug: true,
},
}),
);
export default configStore.get();
API
env<T>(key: string, defaultValue?: T): T
Get an environment variable with optional default and automatic type coercion.
isDev(): boolean
Returns true if NODE_ENV is "development" or not set.
isProd(): boolean
Returns true if NODE_ENV is "production".
isTest(): boolean
Returns true if NODE_ENV is "test".
defineConfig(config: BunaryConfig): BunaryConfig
Type-safe configuration helper with defaults. Validates app.name is a non-empty string (throws for non-string values, empty strings, and whitespace-only strings). Passes through any augmented properties (e.g. orm from @bunary/orm).
createConfig(config?: BunaryConfig): BunaryConfigStore
Create an instance-scoped configuration store with get(), set(), has(), and clear().
get()returns a deep-frozenReadonly<BunaryConfig>— both the top-level object and all nested objects are immutable.has()returnstrueif config has been set and not cleared.
Requirements
Bun ≥ 1.4.0
License
MIT