Initial commit
This commit is contained in:
23
packages/core-shared/src/lib/date.test.ts
Normal file
23
packages/core-shared/src/lib/date.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { toIsoString } from "./date";
|
||||
|
||||
describe("toIsoString", () => {
|
||||
it("converts a Date to ISO string", () => {
|
||||
const d = new Date("2026-05-04T12:00:00.000Z");
|
||||
expect(toIsoString(d)).toBe("2026-05-04T12:00:00.000Z");
|
||||
});
|
||||
|
||||
it("passes through an existing ISO string", () => {
|
||||
expect(toIsoString("2026-05-04T12:00:00.000Z")).toBe(
|
||||
"2026-05-04T12:00:00.000Z",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns null for null input", () => {
|
||||
expect(toIsoString(null)).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for undefined input", () => {
|
||||
expect(toIsoString(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
5
packages/core-shared/src/lib/date.ts
Normal file
5
packages/core-shared/src/lib/date.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function toIsoString(input: Date | string | null | undefined): string | null {
|
||||
if (input === null || input === undefined) return null;
|
||||
if (input instanceof Date) return input.toISOString();
|
||||
return input;
|
||||
}
|
||||
28
packages/core-shared/src/lib/env.test.ts
Normal file
28
packages/core-shared/src/lib/env.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it, afterEach } from "vitest";
|
||||
import { requireEnv } from "./env";
|
||||
|
||||
describe("requireEnv", () => {
|
||||
const originalEnv = process.env.SOME_KEY;
|
||||
|
||||
afterEach(() => {
|
||||
if (originalEnv === undefined) delete process.env.SOME_KEY;
|
||||
else process.env.SOME_KEY = originalEnv;
|
||||
});
|
||||
|
||||
it("returns the value when set", () => {
|
||||
process.env.SOME_KEY = "value";
|
||||
expect(requireEnv("SOME_KEY")).toBe("value");
|
||||
});
|
||||
|
||||
it("throws when missing", () => {
|
||||
delete process.env.SOME_KEY;
|
||||
expect(() => requireEnv("SOME_KEY")).toThrow(
|
||||
/Missing required env var: SOME_KEY/,
|
||||
);
|
||||
});
|
||||
|
||||
it("throws when empty string", () => {
|
||||
process.env.SOME_KEY = "";
|
||||
expect(() => requireEnv("SOME_KEY")).toThrow();
|
||||
});
|
||||
});
|
||||
7
packages/core-shared/src/lib/env.ts
Normal file
7
packages/core-shared/src/lib/env.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function requireEnv(name: string): string {
|
||||
const value = process.env[name];
|
||||
if (!value) {
|
||||
throw new Error(`Missing required env var: ${name}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user