Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/playgrounds/bun-react/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type } from "arkenv";

export default type({
BUN_PUBLIC_API_URL: "string",
BUN_PUBLIC_API_URL: "string.url",
BUN_PUBLIC_DEBUG: "boolean",
});
6 changes: 1 addition & 5 deletions apps/playgrounds/bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const env = arkenv({

// Automatically validate and parse process.env
// TypeScript knows the ✨exact✨ types!
const host = env.HOST;
const port = env.PORT;
const nodeEnv = env.NODE_ENV;

console.log({ host, port, nodeEnv });
console.log({ host: env.HOST, port: env.PORT, nodeEnv: env.NODE_ENV });

export default env;
4 changes: 2 additions & 2 deletions apps/playgrounds/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import arkenv from "arkenv";

const env = arkenv({
HOST: "string.host",
PORT: "number.port",
HOST: "string.ip | 'localhost'",
PORT: "0 <= number.integer <= 65535",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
DEBUG: "boolean = true",
});
Expand Down
35 changes: 12 additions & 23 deletions apps/playgrounds/standard-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const env = arkenv({
DEBUG: "boolean = false",

// Zod validators (great for complex validation and transformations)
DATABASE_URL: z.string().url(),
DATABASE_URL: z.url(),
API_KEY: z
.string()
.min(32)
Expand All @@ -23,35 +23,24 @@ const env = arkenv({
ALLOWED_ORIGINS: z
.string()
.transform((str: string) => str.split(","))
.pipe(z.array(z.string().url())),
.pipe(z.array(z.url())),

// Array defaults with ArkType
FEATURE_FLAGS: type("string[]").default(() => []),
});

// All validators work together seamlessly with full type inference
const host: string = env.HOST;
const port: number = env.PORT;
const nodeEnv: "development" | "production" | "test" = env.NODE_ENV;
const debug: boolean = env.DEBUG;
const databaseUrl: string = env.DATABASE_URL;
const apiKey: string = env.API_KEY;
const maxRetries: number = env.MAX_RETRIES;
const timeoutMs: number = env.TIMEOUT_MS;
const allowedOrigins: string[] = env.ALLOWED_ORIGINS;
const featureFlags: string[] = env.FEATURE_FLAGS;

console.log({
host,
port,
nodeEnv,
debug,
databaseUrl,
apiKey: `${apiKey.substring(0, 8)}...`, // Don't log full API key
maxRetries,
timeoutMs,
allowedOrigins,
featureFlags,
host: env.HOST,
port: env.PORT,
nodeEnv: env.NODE_ENV,
debug: env.DEBUG,
databaseUrl: env.DATABASE_URL,
apiKey: `${env.API_KEY.substring(0, 8)}...`, // Don't log full API key
maxRetries: env.MAX_RETRIES,
timeoutMs: env.TIMEOUT_MS,
allowedOrigins: env.ALLOWED_ORIGINS,
featureFlags: env.FEATURE_FLAGS,
});

export default env;
6 changes: 3 additions & 3 deletions apps/playgrounds/vite-legacy/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import tsconfigPaths from "vite-tsconfig-paths";
// 2. Validating VITE_* variables via the plugin
export const Env = type({
PORT: "number.port",
VITE_MY_VAR: "string",
VITE_MY_NUMBER: type("string").pipe((str) => Number.parseInt(str, 10)),
VITE_MY_BOOLEAN: type("string").pipe((str) => str === "true"),
VITE_MY_VAR: "unknown",
VITE_MY_NUMBER: "number",
VITE_MY_BOOLEAN: "boolean",
});

// https://vite.dev/config/
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import arkenv from "arkenv";

const env = arkenv({
HOST: "string.host",
PORT: "number.port",
HOST: "string.ip | 'localhost'",
PORT: "0 <= number.integer <= 65535",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
DEBUG: "boolean = true",
});
Expand Down
2 changes: 1 addition & 1 deletion examples/with-bun-react/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type } from "arkenv";

export default type({
BUN_PUBLIC_API_URL: "string",
BUN_PUBLIC_API_URL: "string.url",
BUN_PUBLIC_DEBUG: "boolean",
});
6 changes: 1 addition & 5 deletions examples/with-bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const env = arkenv({

// Automatically validate and parse process.env
// TypeScript knows the ✨exact✨ types!
const host = env.HOST;
const port = env.PORT;
const nodeEnv = env.NODE_ENV;

console.log({ host, port, nodeEnv });
console.log({ host: env.HOST, port: env.PORT, nodeEnv: env.NODE_ENV });

export default env;
35 changes: 12 additions & 23 deletions examples/with-standard-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const env = arkenv({
DEBUG: "boolean = false",

// Zod validators (great for complex validation and transformations)
DATABASE_URL: z.string().url(),
DATABASE_URL: z.url(),
API_KEY: z
.string()
.min(32)
Expand All @@ -23,35 +23,24 @@ const env = arkenv({
ALLOWED_ORIGINS: z
.string()
.transform((str: string) => str.split(","))
.pipe(z.array(z.string().url())),
.pipe(z.array(z.url())),

// Array defaults with ArkType
FEATURE_FLAGS: type("string[]").default(() => []),
});

// All validators work together seamlessly with full type inference
const host: string = env.HOST;
const port: number = env.PORT;
const nodeEnv: "development" | "production" | "test" = env.NODE_ENV;
const debug: boolean = env.DEBUG;
const databaseUrl: string = env.DATABASE_URL;
const apiKey: string = env.API_KEY;
const maxRetries: number = env.MAX_RETRIES;
const timeoutMs: number = env.TIMEOUT_MS;
const allowedOrigins: string[] = env.ALLOWED_ORIGINS;
const featureFlags: string[] = env.FEATURE_FLAGS;

console.log({
host,
port,
nodeEnv,
debug,
databaseUrl,
apiKey: `${apiKey.substring(0, 8)}...`, // Don't log full API key
maxRetries,
timeoutMs,
allowedOrigins,
featureFlags,
host: env.HOST,
port: env.PORT,
nodeEnv: env.NODE_ENV,
debug: env.DEBUG,
databaseUrl: env.DATABASE_URL,
apiKey: `${env.API_KEY.substring(0, 8)}...`, // Don't log full API key
maxRetries: env.MAX_RETRIES,
timeoutMs: env.TIMEOUT_MS,
allowedOrigins: env.ALLOWED_ORIGINS,
featureFlags: env.FEATURE_FLAGS,
});

export default env;