feat(utils): add

This commit is contained in:
Pihkaal
2025-12-03 15:34:20 +01:00
parent fd2e2ebd4b
commit ebb157991e
6 changed files with 90 additions and 0 deletions

1
packages/utils/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
dist

View File

@@ -0,0 +1,29 @@
{
"name": "@lbf-bot/utils",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
},
"files": [
"dist"
],
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
},
"dependencies": {
"dotenv": "17.2.3",
"zod": "4.1.11"
},
"devDependencies": {
"@types/node": "22.19.1",
"tsc-alias": "1.8.16",
"typescript": "5.9.3"
}
}

17
packages/utils/src/env.ts Normal file
View File

@@ -0,0 +1,17 @@
import "dotenv/config";
import { z } from "zod";
export const parseEnv = <T extends z.ZodRawShape>(vars: T) => {
const schema = z.object(vars);
const result = schema.safeParse(process.env);
if (!result.success) {
console.error("ERROR: Environment variable validation failed:");
for (const issue of result.error.issues) {
console.error(`- ${issue.path.join(".")}: ${issue.message}`);
}
process.exit(1);
}
return result.data;
};

View File

@@ -0,0 +1 @@
export * from "./env";

View File

@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"removeComments": false
},
"tsc-alias": {
"resolveFullPaths": true
},
"include": ["src"]
}

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"moduleResolution": "bundler",
"allowImportingTsExtensions": false,
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"],
"~": ["./src/index"]
},
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}