UNPKG

rajt

Version:

A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.

17 lines (14 loc) 511 B
import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' export default function jsonImport<T = any>(filePath: string, defaultValue: T = {} as T): T { const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) try { const fullPath = join(__dirname, filePath) const fileContent = readFileSync(fullPath, 'utf-8') return JSON.parse(fileContent) as T } catch (error) { return defaultValue } }