@bunary/core 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @bunary/core
2
+
3
+ Foundation module for the Bunary framework — configuration, environment helpers, and shared utilities.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @bunary/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Environment Variables
14
+
15
+ ```typescript
16
+ import { env, isDev, isProd, isTest } from '@bunary/core';
17
+
18
+ // Get environment variable with automatic type coercion
19
+ const port = env('PORT', 3000); // Returns number
20
+ const debug = env('DEBUG', false); // Returns boolean
21
+ const name = env('APP_NAME', 'myapp'); // Returns string
22
+
23
+ // Environment detection
24
+ if (isDev()) {
25
+ console.log('Running in development mode');
26
+ }
27
+ ```
28
+
29
+ ### Configuration
30
+
31
+ ```typescript
32
+ import { defineConfig } from '@bunary/core';
33
+
34
+ export default defineConfig({
35
+ app: {
36
+ name: 'MyApp',
37
+ env: 'development',
38
+ debug: true,
39
+ },
40
+ });
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### `env<T>(key: string, defaultValue?: T): T`
46
+
47
+ Get an environment variable with optional default and automatic type coercion.
48
+
49
+ ### `isDev(): boolean`
50
+
51
+ Returns `true` if `NODE_ENV` is `"development"` or not set.
52
+
53
+ ### `isProd(): boolean`
54
+
55
+ Returns `true` if `NODE_ENV` is `"production"`.
56
+
57
+ ### `isTest(): boolean`
58
+
59
+ Returns `true` if `NODE_ENV` is `"test"`.
60
+
61
+ ### `defineConfig(config: BunaryConfig): BunaryConfig`
62
+
63
+ Type-safe configuration helper with defaults.
64
+
65
+ ## Requirements
66
+
67
+ - Bun ≥1.0.0
68
+
69
+ ## License
70
+
71
+ MIT
@@ -0,0 +1,18 @@
1
+ import type { BunaryConfig } from "./types";
2
+ /**
3
+ * Define Bunary configuration with type safety
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { defineConfig } from "@bunary/core";
8
+ *
9
+ * export default defineConfig({
10
+ * app: {
11
+ * name: "MyApp",
12
+ * env: "development",
13
+ * },
14
+ * });
15
+ * ```
16
+ */
17
+ export declare function defineConfig(config: BunaryConfig): BunaryConfig;
18
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAW/D"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Environment helpers using Bun.env
3
+ */
4
+ /**
5
+ * Get an environment variable with optional default and automatic type coercion
6
+ * @param key - Environment variable name
7
+ * @param defaultValue - Default value if not set (also determines return type)
8
+ * @returns The environment variable value, coerced to match defaultValue type
9
+ * @example
10
+ * ```ts
11
+ * const port = env('PORT', 3000); // Returns number
12
+ * const debug = env('DEBUG', false); // Returns boolean
13
+ * const name = env('APP_NAME', 'app'); // Returns string
14
+ * const secret = env('SECRET'); // Returns string | undefined
15
+ * ```
16
+ */
17
+ export declare function env<T extends string | number | boolean | undefined>(key: string, defaultValue?: T): T extends undefined ? string | undefined : T;
18
+ /**
19
+ * Check if running in development mode
20
+ */
21
+ export declare function isDev(): boolean;
22
+ /**
23
+ * Check if running in production mode
24
+ */
25
+ export declare function isProd(): boolean;
26
+ /**
27
+ * Check if running in test mode
28
+ */
29
+ export declare function isTest(): boolean;
30
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,EACjE,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,CAAC,GACf,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,CAAC,CAqB9C;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @bunary/core
3
+ * Foundation module for Bunary - config, environment, and app helpers
4
+ */
5
+ export { defineConfig } from "./config";
6
+ export { env, isDev, isProd, isTest } from "./environment";
7
+ export type { BunaryConfig, AppConfig } from "./types";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // @bun
2
+ // src/config.ts
3
+ function defineConfig(config) {
4
+ return {
5
+ app: {
6
+ name: config.app.name,
7
+ env: config.app.env ?? Bun.env.NODE_ENV ?? "development",
8
+ debug: config.app.debug ?? Bun.env.DEBUG === "true"
9
+ }
10
+ };
11
+ }
12
+ // src/environment.ts
13
+ function env(key, defaultValue) {
14
+ const value = Bun.env[key];
15
+ if (value === undefined) {
16
+ return defaultValue;
17
+ }
18
+ if (typeof defaultValue === "boolean") {
19
+ return value === "true";
20
+ }
21
+ if (typeof defaultValue === "number") {
22
+ const num = Number(value);
23
+ return Number.isNaN(num) ? defaultValue : num;
24
+ }
25
+ return value;
26
+ }
27
+ function isDev() {
28
+ return Bun.env.NODE_ENV === "development" || !Bun.env.NODE_ENV;
29
+ }
30
+ function isProd() {
31
+ return Bun.env.NODE_ENV === "production";
32
+ }
33
+ function isTest() {
34
+ return Bun.env.NODE_ENV === "test";
35
+ }
36
+ export {
37
+ isTest,
38
+ isProd,
39
+ isDev,
40
+ env,
41
+ defineConfig
42
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * App configuration
3
+ */
4
+ export interface AppConfig {
5
+ /** Application name */
6
+ name: string;
7
+ /** Environment: development, production, test */
8
+ env?: "development" | "production" | "test";
9
+ /** Debug mode */
10
+ debug?: boolean;
11
+ }
12
+ /**
13
+ * Root Bunary configuration
14
+ */
15
+ export interface BunaryConfig {
16
+ app: AppConfig;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,MAAM,CAAC;IAC5C,iBAAiB;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;CAChB"}
package/package.json CHANGED
@@ -1,10 +1,40 @@
1
1
  {
2
2
  "name": "@bunary/core",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
6
- "keywords": ["bunary", "core"],
7
- "author": "paul@mylocahost.com",
3
+ "version": "0.0.2",
4
+ "description": "Foundation module for Bunary - config, environment, and app helpers",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun && bunx tsc -p tsconfig.build.json",
20
+ "typecheck": "bunx tsc --noEmit",
21
+ "test": "bun test",
22
+ "lint": "bunx biome check ./src"
23
+ },
24
+ "keywords": [
25
+ "bunary",
26
+ "bun",
27
+ "backend",
28
+ "framework",
29
+ "config"
30
+ ],
31
+ "author": "Paul Radford",
8
32
  "license": "MIT",
9
- "type": "commonjs"
33
+ "engines": {
34
+ "bun": ">=1.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@biomejs/biome": "^1.9.4",
38
+ "bun-types": "latest"
39
+ }
10
40
  }